level 7
function GetMsgPro(code:Integer;wPar:Integer;lPar:Integer):Integer;stdcall;
var
HHookInf:PCWPStruct;
//Buffer,
MyCaption:array[0..127] of Char;
LogInfo:string;
begin
if (Code = HC_ACTION) then
begin
HHookInf := PCWPStruct(lPar);
if HHookInf.message = WM_CREATE then
begin
GetWindowText(HHookInf.hwnd,MyCaption,SizeOf(MyCaption));
LogInfo := '程序创建,名称为:'+GetProcessExePath(HHookInf.hwnd);
Writlog(LogInfo);
Writlog('标题为:'+MyCaption);
end else if HHookInf.message = WM_DESTROY then
begin
GetWindowText(HHookInf.hwnd,MyCaption,SizeOf(MyCaption));
LogInfo := '窗口销毁,名称为:'+GetProcessExePath(HHookInf.hwnd);
Writlog(LogInfo);
end;
end;
Result := CallNextHookEx(DMessageHook,code,wPar,lPar);
end;
我将创建窗体的消息钩住,然后根据句柄获得文件名,为什么它会重复得到这个新建窗体的消息。应该怎么做?难道建立以个全局变量,保存前面的结果,如果当前值和保存的值相同,则我们舍弃结果?
2014年04月17日 07点04分