在qq的聊天窗口,当按下"发送"按钮之前,执行一段我的代码
希望能用全局消息钩子加子类化函数实现
WH_CALLWNDPROC setwindowslong
因为,用全局钩子消息,我已会 我在学子类化函数的用法?library TmHook; uses
SysUtils,
Classes,
Windows,
Messages,
CommCtrl;
var
hhook: Windows.HHOOK;
hwndListView: HWND;
na:array[0..300] of char;
oldWndProc: Integer;
{$R *.res}
function WindowProc(hwnd: HWND; msg: UINT; wp: WPARAM; lp: LPARAM): LRESULT; stdcall;
begin
case Msg of
WM_LBUTTONDOWN:
MessageBox(hwndListView,'你好!','提示',MB_OK);
end;
Result := CallWindowProc(TFNWndProc(oldWndProc), hwnd, msg, wp, lp);
end;
function TmHookProc(nCode: Integer; wParam: WPARAM; lParam: LPARAM): Integer; stdcall;
var
cwp: PCwpStruct;
m:TPoint;
begin
Result := 0;
if (nCode < 0) then
begin
Result := CallNextHookEx(hhook, nCode, wParam, lParam);
exit;
end;
cwp := PCwpStruct(lParam);
if cwp^.message <> WM_COMMAND then
begin
Result := CallNextHookEx(hhook, nCode, wParam, lParam);
exit;
end;
GetCursorPos(m);
GetWindowText(WindowFromPoint(m),na,299);
if lstrcmpi('发送(S)',na) <>0 then
begin
Result := CallNextHookEx(hhook, nCode, wParam, lParam);
exit;
end;
hwndListView:=WindowFromPoint(m);
oldWndProc := SetWindowLong(hwndListView, GWL_WNDPROC, Integer(@WindowProc));
end;
procedure Hook(bEnable: Boolean); stdcall; export;
begin
if bEnable then
begin
if hhook = 0 then
begin
hhook := SetWindowsHookEx(WH_CALLWNDPROC, TmHookProc, HInstance, 0);
end;
end
else
begin
if hhook <> 0 then
begin
UnhookWindowsHookEx(hhook);
hhook := 0;
end;
end;
end;
exports
Hook;
begin
hhook := 0;
hwndListView := 0;
oldWndProc:=0;
end.
到底哪里错了,一运行,qq就自动关闭??
希望能用全局消息钩子加子类化函数实现
WH_CALLWNDPROC setwindowslong
因为,用全局钩子消息,我已会 我在学子类化函数的用法?library TmHook; uses
SysUtils,
Classes,
Windows,
Messages,
CommCtrl;
var
hhook: Windows.HHOOK;
hwndListView: HWND;
na:array[0..300] of char;
oldWndProc: Integer;
{$R *.res}
function WindowProc(hwnd: HWND; msg: UINT; wp: WPARAM; lp: LPARAM): LRESULT; stdcall;
begin
case Msg of
WM_LBUTTONDOWN:
MessageBox(hwndListView,'你好!','提示',MB_OK);
end;
Result := CallWindowProc(TFNWndProc(oldWndProc), hwnd, msg, wp, lp);
end;
function TmHookProc(nCode: Integer; wParam: WPARAM; lParam: LPARAM): Integer; stdcall;
var
cwp: PCwpStruct;
m:TPoint;
begin
Result := 0;
if (nCode < 0) then
begin
Result := CallNextHookEx(hhook, nCode, wParam, lParam);
exit;
end;
cwp := PCwpStruct(lParam);
if cwp^.message <> WM_COMMAND then
begin
Result := CallNextHookEx(hhook, nCode, wParam, lParam);
exit;
end;
GetCursorPos(m);
GetWindowText(WindowFromPoint(m),na,299);
if lstrcmpi('发送(S)',na) <>0 then
begin
Result := CallNextHookEx(hhook, nCode, wParam, lParam);
exit;
end;
hwndListView:=WindowFromPoint(m);
oldWndProc := SetWindowLong(hwndListView, GWL_WNDPROC, Integer(@WindowProc));
end;
procedure Hook(bEnable: Boolean); stdcall; export;
begin
if bEnable then
begin
if hhook = 0 then
begin
hhook := SetWindowsHookEx(WH_CALLWNDPROC, TmHookProc, HInstance, 0);
end;
end
else
begin
if hhook <> 0 then
begin
UnhookWindowsHookEx(hhook);
hhook := 0;
end;
end;
end;
exports
Hook;
begin
hhook := 0;
hwndListView := 0;
oldWndProc:=0;
end.
到底哪里错了,一运行,qq就自动关闭??
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货