来源: http://www.delphitop.com/html/jiqiao/567.html
delphi代码 procedure TForm1.Button1Click(Sender: TObject); var hParent,hButton,hMemo: HWND; begin Memo1.CopyToClipboard;//把Memo中选中的语句拷贝到剪贴板中 try //找发送消息的QQ窗口 hParent := FindWindow(nil, '发送消息'); //然后找回话时用的编辑窗口,Point函数用于返回一个TPoint类型变量 hMemo := ChildWindowFromPointEx(hParent, Point(50, 100),CWP_ALL); //找到“送讯息”按钮的句柄 hButton :=FindWindowEx(hParent,0,nil,'送讯息(&S)'); if (hParent = 0) or (hMemo = 0) or (hButton = 0)then MessageBox(Handle,'没有找到发送窗口,请重试!','错误',MB_ICONWARNING) else begin //向发送消息中的回话编辑框发送粘贴消息 SendMessage(hMemo,WM_PASTE,0,0); //向“送讯息”按钮送单击消息以模仿按键发送回话 SendMessage(hButton,BM_CLICK,0,0); end; except //如果发生以外错误给出提示 MessageBox(Handle,'发送消息出错,请重试!','错误',MB_ICONWARNING); end; end; |