LRESULT CALLBACK GetMsgProc( int code, // hook code WPARAM wParam, // removal flag LPARAM lParam // address of structure with message ); ParameterscodeSpecifies whether the hook procedure must process the message. If code is HC_ACTION, the hook procedure must process the message. If code is less than zero, the hook procedure must pass the message to the CallNextHookEx function without further processing and should return the value returned by CallNextHookEx. wParamSpecifies whether the message has been removed from the queue. This parameter can be one of the following values: Value Meaning PM_NOREMOVE Specifies that the message has not been removed from the queue. (An application called the PeekMessage function, specifying the PM_NOREMOVE flag.) PM_REMOVE Specifies that the message has been removed from the queue. (An application called GetMessage, or it called the PeekMessage function, specifying the PM_REMOVE flag.) lParamPoints to an MSG structure that contains details about the message. Return ValuesThe return value should be zero.
var I:Thandle; //句柄变量 Str:string; begin Str:='Test'; I:=FindWindow(nil,'计算器'); if I<>0 then SendMessage(I,WM_SETTEXT,10,Integer(Str)) end;
function Proc(Code: Integer; WParam: Longint;Msg:Longint): LRESULT;stdcall; begin if (Code = HC_ACTION) then if PMsg(Msg)^.Message = WM_MOUSEWHEEL then //鼠标滚动 begin if HIWORD(PMsg(Msg)^.wParam)=120 then // 上滚 begin //做你想做的。 ShowWindow (pmsg(msg)^.hwnd,SW_MAXIMIZE ); end; if HIWORD(PMsg(Msg)^.wParam)<>120 then // 下滚 begin //做你想做的。 ShowWindow (pmsg(msg)^.hwnd,SW_RESTORE ); end; PMsg(Msg)^.Message := 0; end; Result :=CallNextHookEx(HookHandle, Code, WParam, Longint(@Msg)); end;
WPARAM wParam, // removal flag
LPARAM lParam // address of structure with message
);
ParameterscodeSpecifies whether the hook procedure must process the message. If code is HC_ACTION, the hook procedure must process the message. If code is less than zero, the hook procedure must pass the message to the CallNextHookEx function without further processing and should return the value returned by
CallNextHookEx. wParamSpecifies whether the message has been removed from the queue. This parameter can be one of the following values: Value Meaning
PM_NOREMOVE Specifies that the message has not been removed from the queue. (An application called the PeekMessage function, specifying the PM_NOREMOVE flag.)
PM_REMOVE Specifies that the message has been removed from the queue. (An application called GetMessage, or it called the PeekMessage function, specifying the PM_REMOVE flag.)
lParamPoints to an MSG structure that contains details about the message. Return ValuesThe return value should be zero.
var
I:Thandle; //句柄变量
Str:string;
begin
Str:='Test';
I:=FindWindow(nil,'计算器');
if I<>0 then
SendMessage(I,WM_SETTEXT,10,Integer(Str))
end;
function Proc(Code: Integer; WParam: Longint;Msg:Longint): LRESULT;stdcall;
begin
if (Code = HC_ACTION) then
if PMsg(Msg)^.Message = WM_MOUSEWHEEL then //鼠标滚动
begin
if HIWORD(PMsg(Msg)^.wParam)=120 then // 上滚
begin
//做你想做的。
ShowWindow (pmsg(msg)^.hwnd,SW_MAXIMIZE );
end; if HIWORD(PMsg(Msg)^.wParam)<>120 then // 下滚
begin
//做你想做的。
ShowWindow (pmsg(msg)^.hwnd,SW_RESTORE );
end;
PMsg(Msg)^.Message := 0;
end;
Result :=CallNextHookEx(HookHandle, Code, WParam, Longint(@Msg));
end;
当计算器程序运行了,showmessage('ok')就可以了。
我觉得用WH_GETMESSAGE 类型可以实现这个功能。
如果设置个全局变量作为标志进行判断不知道行不行?
还请大家指点一下。
不过监视explorer.exe的CreateProcess可能会容易点
用WH_SHELL 钩子测试成功 结帖