L
lfpsoft
Unregistered / Unconfirmed
GUEST, unregistred user!
想到用MOUSEHOOK做,但对于HOOK研究不深,找了些例子看了。
现在用HOOK已载到按下右键的消息。但由于水平问题,
全部的按右键的消息都“吃”掉了。哪位高手帮在忙看看,应该如何得出是在
任务栏上的自己程序上按了右键,然后又如何弹出自己的菜单呢?
我想到用屏幕取词,如果取得窗口标题为程序标题,则就弹出自己的菜单。
但屏幕取词好像很复杂呀。
大家想想办法吧!
下面给出我的HOOK,用的是DLL HOOK;请大家指教指教!
//DLL 工程代码
library HKTest;
uses
HKProc in 'HKProc.pas';
exports
EnableMouseHook,
DisableMouseHook;
begin
hNextHookProc := 0;
procSaveExit := ExitProc;
ExitProc := @MouseHookExit;
end.
//HKProc.pas
unit HKProc;
interface
uses
Windows, Messages;
var
hNextHookProc: HHook;
procSaveExit: Pointer;
function MouseHookHandler(iCode: Integer;
wParam: WPARAM;
lParam: LPARAM): LRESULT; stdcall; export;
function EnableMouseHook: BOOL; export;
function DisableMouseHook: BOOL; export;
procedure MouseHookExit; far;
implementation
function MouseHookHandler(iCode: Integer;
wParam: WPARAM;
lParam: LPARAM): LRESULT; stdcall; export;
begin
Result := 0;
If iCode < 0 Then
begin
Result := CallNextHookEx(hNextHookProc, iCode, wParam, lParam);
Exit;
end;
if (wParam = WM_RBUTTONUP) then
begin
Result := 1;
MessageBeep(0);
// DoMenu;//如何在这里加入判断以弹出自己的菜单呢?
end;
end;
function EnableMouseHook: BOOL; export;
begin
Result := False;
if hNextHookProc <> 0 then Exit;
hNextHookProc := SetWindowsHookEx(WH_MOUSE,
MouseHookHandler,
HInstance,
0);
Result := hNextHookProc <> 0;
end;
function DisableMouseHook: BOOL; export;
begin
if hNextHookProc <> 0 then
begin
UnhookWindowsHookEx(hNextHookProc);
hNextHookProc := 0;
MessageBeep(0);
end;
Result := hNextHookProc = 0;
end;
procedure MouseHookExit;
begin
if hNextHookProc <> 0 then DisableMouseHook;
ExitProc := procSaveExit;
end;
end.
//调用
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs;
type
TForm1 = class(TForm)
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
function EnableMouseHook:BOOL;stdcall;external 'HKTest.dll';
function DisableMouseHook:BOOL;stdcall;external 'HKTest.dll';
var
Form1: TForm1;
hook,mm:integer;
implementation
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
begin
EnableMouseHook;
end;
procedure TForm1.FormDestroy(Sender: TObject);
begin
DisableMouseHook;
end;
end.
现在用HOOK已载到按下右键的消息。但由于水平问题,
全部的按右键的消息都“吃”掉了。哪位高手帮在忙看看,应该如何得出是在
任务栏上的自己程序上按了右键,然后又如何弹出自己的菜单呢?
我想到用屏幕取词,如果取得窗口标题为程序标题,则就弹出自己的菜单。
但屏幕取词好像很复杂呀。
大家想想办法吧!
下面给出我的HOOK,用的是DLL HOOK;请大家指教指教!
//DLL 工程代码
library HKTest;
uses
HKProc in 'HKProc.pas';
exports
EnableMouseHook,
DisableMouseHook;
begin
hNextHookProc := 0;
procSaveExit := ExitProc;
ExitProc := @MouseHookExit;
end.
//HKProc.pas
unit HKProc;
interface
uses
Windows, Messages;
var
hNextHookProc: HHook;
procSaveExit: Pointer;
function MouseHookHandler(iCode: Integer;
wParam: WPARAM;
lParam: LPARAM): LRESULT; stdcall; export;
function EnableMouseHook: BOOL; export;
function DisableMouseHook: BOOL; export;
procedure MouseHookExit; far;
implementation
function MouseHookHandler(iCode: Integer;
wParam: WPARAM;
lParam: LPARAM): LRESULT; stdcall; export;
begin
Result := 0;
If iCode < 0 Then
begin
Result := CallNextHookEx(hNextHookProc, iCode, wParam, lParam);
Exit;
end;
if (wParam = WM_RBUTTONUP) then
begin
Result := 1;
MessageBeep(0);
// DoMenu;//如何在这里加入判断以弹出自己的菜单呢?
end;
end;
function EnableMouseHook: BOOL; export;
begin
Result := False;
if hNextHookProc <> 0 then Exit;
hNextHookProc := SetWindowsHookEx(WH_MOUSE,
MouseHookHandler,
HInstance,
0);
Result := hNextHookProc <> 0;
end;
function DisableMouseHook: BOOL; export;
begin
if hNextHookProc <> 0 then
begin
UnhookWindowsHookEx(hNextHookProc);
hNextHookProc := 0;
MessageBeep(0);
end;
Result := hNextHookProc = 0;
end;
procedure MouseHookExit;
begin
if hNextHookProc <> 0 then DisableMouseHook;
ExitProc := procSaveExit;
end;
end.
//调用
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs;
type
TForm1 = class(TForm)
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
function EnableMouseHook:BOOL;stdcall;external 'HKTest.dll';
function DisableMouseHook:BOOL;stdcall;external 'HKTest.dll';
var
Form1: TForm1;
hook,mm:integer;
implementation
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
begin
EnableMouseHook;
end;
procedure TForm1.FormDestroy(Sender: TObject);
begin
DisableMouseHook;
end;
end.