//Hey all,
//-->I want to trap the MenuItem ID of any Menu in any application.
//--> this is done with subclassing.
//Thanks for any suggestions,
//Jan
//-->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