Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations MikeeOK on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Retrieve the MenuItem ID of any Menu in any application

Status
Not open for further replies.

boemboem

Programmer
Dec 8, 2005
1
BE
//Hey all,
//-->I want to trap the MenuItem ID of any Menu in any application.
//--> this is done with subclassing.

Code:
unit jmHookApp;

interface

uses
  SysUtils,
  Windows,
  Messages;


var
  intPrevProc : integer;
  m_ApphWnd  : HWND;

 function Hook(hookAppWindowHwnd : HWND): boolean;

 function WindowProc(WindowHwnd : HWND;
                        uMsg : cardinal;
                        wParam : integer;
                        lParam : integer): integer;StdCall;

 function UnHook(): boolean;

implementation

function Hook(hookAppWindowHwnd : HWND): boolean;
begin
 try
    intPrevProc := SetWindowLong(hookAppWindowHwnd, GWL_WNDPROC, integer(@WindowProc));
    Result := True;
 Except
    on E:Exception do Result := False;
 end;
end;

function UnHook(): boolean;
begin
 try
    SetWindowLong(m_ApphWnd, GWL_WNDPROC, intPrevProc);
    Result := True;
 Except
    on E:Exception do Result := False;
 end;
end;

function WindowProc(WindowHwnd : HWND;
                       uMsg : cardinal;
                       wParam : integer;
                       lParam : integer): integer;StdCall;

Begin
 WindowProc := CallWindowProc(PInteger(intPrevProc),
                                        WindowHwnd,
                                        uMsg,
                                        wParam,
                                        lParam);

 case uMsg of
  WM_MENUSELECT:
    begin
     if ReleaseCapture() > Bool(0) then
      begin

[COLOR=red]//------------
      // here I want to trap or return the ID of the MenuItem selected
      // like the 'IDItem' of 'TWMMenuSelect'
//------------[/color]
      end;
    end;
 end;
 m_ApphWnd := WindowHwnd;
end;

end.

//Thanks for any suggestions,

//Jan

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top