以QQ登录窗口为例<br><br><br><br>implementation<br>var<br> OldBtnProc: Pointer;<br> QQWindow,BtnExit: HWND;<br>{$R *.dfm}<br> function ButtonProc(hwnd: HWND; Msg: UINT;wparam: WPARAM;lparam: LPARAM):LRESULT;Stdcall;<br> begin<br> if Msg = WM_LBUTTONDOWN then<br> begin<br> SendMessage(QQWindow,WM_SYSCOMMAND,SC_CLOSE,0);<br> Result:= 0;<br> end<br> else<br> Result:= CallWindowProc(OldBtnProc,hwnd,Msg,wparam,lparam);<br> end;<br>procedure TForm1.Button1Click(Sender: TObject);<br><br>begin<br> QQWindow:= FindWindow(nil,'QQ用户登录');<br> if QQWindow = 0 then exit;<br> BtnExit:= CreateWindow('Button','退出',WS_VISIBLE or WS_CHILD or BS_PUSHBUTTON,10,10,80,50,<br> QQWindow,1,GetWindowLong(QQWindow,GWL_HINSTANCE),nil);<br> Windows.SetParent(BtnExit,QQWindow);<br> OldBtnProc:= Pointer(SetWindowLong(BtnExit,GWL_WNDPROC,Longint(@ButtonProc)));<br>end;