小弟现用一鼠标hook监控了鼠标点击事件,可以取得任何窗口的句柄和显示名称,但后来发现,对菜单没有用,根本取不到菜单的文字内容麻烦各位帮帮忙。
代码如下:
unit Unit1;
interface
uses
    windows,Messages,shellapi;
var
hookmenu:thandle;
windows1:wparam;
//a:integer;
procSaveExit: Pointer;
function menumsg(iCode: Integer;wParam: WPARAM;lParam: LPARAM): LRESULT; stdcall; export;
function unmenuhook():boolean;stdcall;export;
function setmenuhook(WndHandle:hwnd):boolean;stdcall;export;
//procedure menumsg(var msg:tmessage);far;
procedure HookExit; far;implementationfunction setmenuhook(WndHandle:hwnd):boolean;export;
begin
Result := False;
if hookmenu<>0 then Exit;
hookmenu:=SetWindowsHookEx(WH_MOUSE,menumsg,hinstance,0);
//hookmenu:=SetWindowsHookEx(WH_getmessage,menumsg,hinstance,0);
Result := hookmenu<>0;
end;function unmenuhook:boolean;export;
begin
if hookmenu<>0 then
begin
UnhookWindowshookEx(hookmenu);
hookmenu:= 0;
end;
Result := hookmenu = 0;
end;function menumsg(iCode: Integer;wParam: WPARAM;lParam: LPARAM): LRESULT; stdcall; export;
var
wnd,hd:hwnd;
WName:array[0..254] of char;
winPos:TPoint;
begin
result:=0;
if icode<0 then
  begin
   Result:=CallNextHookEx(hookmenu,iCode,wParam,lParam);
   exit;
  end;
if iCode=HC_ACTION then
beginif wParam=WM_LBUTTONDOWN then
begin
 GetCursorPos(winpos);
 Wnd:=WindowFromPoint(WinPos);if(findwindow(nil,'系统')<>0) then
 begin
  hd:=GetActiveWindow();
  getwindowtext(hd,wname,255); getwindowtext(wnd,wname,255);
if hd=findwindow(nil,'系统') then
 begin//目录菜单
  { if (string(wname)='目录') then
       shellexecute(hd,'open','SPML.exe','','',sw_showna);}
   if (string(wname)='目录信息') then
      shellexecute(hd,'open','SPML.exe','','',sw_showna);
   end;
end;
end;
end;
   Result:=CallNextHookEx(hookmenu,iCode,wParam,lParam);
end;procedure HookExit;
beginif hookmenu <>0 then unmenuhook;
 ExitProc := procSaveExit;
end;end.

解决方案 »

  1.   

    呵呵...我有一源码可以实现你想要的...   不过有几个pas文件不好贴..想要的话给你的e-mail出来..
      

  2.   

    也给我一分吧。
    [email protected]
    谢谢
      

  3.   

    取得菜单的显示字串药用GetMenuString。如:var
      P: PChar;
    begin
      GetMem(P, MAXBYTE);
      GetMenuString(PopupMenu1.Handle, 0{第1个菜单项}, P, MAXBYTE-1, MF_BYPOSITION);
      ShowMessage(P);
      FreeMem(P);
    end;—————————————————————————————————
    宠辱不惊,看庭前花开花落,去留无意;毁誉由人,望天上云卷云舒,聚散任风。
    —————————————————————————————————