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