1 2 下一页
此文将讲述如何捕获自己发送出去的消息:
// hottey 于2004-6-2号
QQ从本机发出消息无非就是两种方式.(1)按发送按钮,(2)按Ctrl+Enter组合键.当然自定义键除外.也不在本文考虑范围之内:
基于这两种发送的方式我选用:WH_CALLWNDPROC 和 WH_KEYBOARD两种钩子.Sorry,今天心情太烂(学校里的一些琐事,郁闷).实在无心继续.只能贴上源码了.大家有兴趣自己看看...有什么问题可以和我联系.delphi21@163.com
| //监控Ctrl+Enter组合键 function KeyboardProc(iCode: Integer; wParam: WPARAM; lParam: LPARAM): LRESULT; stdcall; begin if (wParam = VK_RETURN) and (GetKeyState(VK_CONTROL) < 0) and (lParam >= 0) then begin SendMessage(Shared^.MainWnd,WM_USERCMD, UC_WINDESTROY, GetForegroundWindow); end; Result := CallNextHookEx(Shared^.KeyHook,iCode,wParam,lParam); end; //监控"发送"按钮 function CallWndProc(iCode: Integer; wParam: WPARAM; lParam: LPARAM): LRESULT; stdcall; type Msg = ^CWPSTRUCT; var p : Msg; begin p := Msg(lParam); //只对前台窗口进行处理 if (p^.message = WM_COMMAND) and (LOWORD(p^.wParam) = 1) then begin SendMessage(Shared^.MainWnd,WM_USERCMD, UC_WINDESTROY, GetForegroundWindow); end; Result := CallNextHookEx(Shared^.CallHook,iCode,wParam,lParam); end; |
演示程序相关代码:
| procedure TForm1.WndProc(var Msg: TMessage); begin with Msg do begin if Msg = WM_USERCMD then begin case wParam of UC_WINDESTROY: begin GetText(Findhwd(HWND(lParam))); end; end; end; end; inherited; end; |
上一篇: Delphi单元文件详解
下一篇: Delphi设计简易对象垃圾回收框架
1 2 下一页