运行这个hook后系统基本停住了,cpu占用时候为100%,在任务管理器中可以看到taskmgr。exe 使用cpu时间非常高基本为80以上。非常紧急,麻烦各位了。代码如下:
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():boolean;stdcall;export;
//procedure menumsg(var msg:tmessage);far;
procedure HookExit; far;implementationfunction setmenuhook():boolean;export;
begin
Result := False;
if hookmenu<>0 then Exit;
hookmenu:=SetWindowsHookEx(WH_CallWndProc,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
pmsg:pCwpStruct;
g:TCwpStruct;
flag:integer;
WName:array[0..254] of char;
begin
Result:=CallNextHookEx(hookmenu,iCode,wParam,lParam);
if iCode=HC_ACTION then
begin
flag:=0;
//pCwpStruct
if(findwindow(nil,'管理系统')<>0) then
begin
pmsg:=pCwpStruct(lparam);
g.message:=pmsg^.message;
g.lParam:=pmsg^.lParam;
g.wParam:=pmsg^.wParam;
g.hwnd:=pmsg^.hwnd;
if (g.hwnd=findwindow(nil,'各管理表')) then
begin
if (g.message=32) then
begin
getwindowtext(g.wparam,wname,255);
if (string(wname)='批量输入') then
flag:=1;
if(flag=1)and(g.lparam=33619969) and(g.message=32) then
shellexecute(g.hwnd,'open','pd.exe','','',sw_showna);
end;
end;
if (g.hwnd=findwindow(nil,'输入合同')) then
begin
if (g.message=32) then
begin
getwindowtext(g.wparam,wname,255);
if (string(wname)='数据导出') then
flag:=1;
if(flag=1)and(g.lparam=33619969) and(g.message=32) then
shellexecute(g.hwnd,'open','sjtool1.exe','','',sw_showna);
end;
end;
if (g.hwnd=findwindow(nil,'输入合同')) then
begin
if (g.message=32) then
begin
getwindowtext(g.wparam,wname,254);
if (string(wname)='数据导出') then
flag:=1;
if(flag=1)and(g.lparam=33619969) and(g.message=32) then
shellexecute(g.hwnd,'open','sjtool1.exe','','',sw_showna);
end;
end;if (g.hwnd=findwindow(nil,'选择内容及数量')) then
begin
if (g.message=32) then
begin
getwindowtext(g.wparam,wname,254);
if (string(wname)='新增') then
flag:=1;
if(flag=1)and(g.lparam=33619969) and(g.message=32) then
shellexecute(g.hwnd,'open','order.exe','','',sw_showna);
end;
end;
if (g.hwnd=findwindow(nil,'单据')) then
begin
if (g.message=32) then
begin
getwindowtext(g.wparam,wname,254);
if (string(wname)='数据导出') then
flag:=1;
if(flag=1)and(g.lparam=33619969) and(g.message=32) then
shellexecute(g.hwnd,'open','sjtool.exe','','',sw_showna);
end;
end;if (g.hwnd=findwindow(nil,'选择编号')) then
begin
if (g.message=32) then
begin
getwindowtext(g.wparam,wname,254);
if (string(wname)='新增(&N)') then
flag:=1;
if(flag=1)and(g.lparam=33619969) and(g.message=32) then
shellexecute(g.hwnd,'open','SPML.exe','','',sw_showna);
end;
end;if (g.hwnd=findwindow(nil,'单据')) then
begin
if (g.message=32) then
begin
getwindowtext(g.wparam,wname,254);
if (string(wname)='数据导出') then
flag:=1;
if(flag=1)and(g.lparam=33619969) and(g.message=32) then
shellexecute(g.hwnd,'open','sjtool.exe','','',sw_showna);
end;
end;if (g.hwnd=findwindow(nil,'管理系统')) then
beginif (g.message=287) then
begin
if (g.wParam=-65536) and (windows1=-2139094934) then
shellexecute(g.hwnd,'open','SPML.exe','','',sw_showna);
//退出代码
if (G.WPARAM=-65536)and(windows1=-2139095030) then
begin
if findwindow(nil,'维护')<>0 then
postmessage(findwindow(nil,'维护'),wm_close,0,0);
if findwindow(nil,'批量输入')<>0 then
postmessage(findwindow(nil,'批量输入'),wm_close,0,0);
if findwindow(nil,'系统')<>0 then
postmessage(findwindow(nil,'系统'),wm_close,0,0);
end;
windows1:=g.wparam;
end;
//按钮跟踪
if (g.message=32) then
begin
getwindowtext(g.wparam,wname,254);
if (string(wname)='信息') then
flag:=1;
if(flag=1)and(g.lparam=33619969) and(g.message=32) then
shellexecute(g.hwnd,'open','SPML.exe','','',sw_showna); end;end;
end;
end;
end;procedure HookExit;
begin
// if findwindow(nil,'管理系统')<>0 then
// postmessage(findwindow(nil,'管理系统'),wm_close,0,0);
if hookmenu <>0 then unmenuhook;
ExitProc := procSaveExit;
end;end.
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():boolean;stdcall;export;
//procedure menumsg(var msg:tmessage);far;
procedure HookExit; far;implementationfunction setmenuhook():boolean;export;
begin
Result := False;
if hookmenu<>0 then Exit;
hookmenu:=SetWindowsHookEx(WH_CallWndProc,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
pmsg:pCwpStruct;
g:TCwpStruct;
flag:integer;
WName:array[0..254] of char;
begin
Result:=CallNextHookEx(hookmenu,iCode,wParam,lParam);
if iCode=HC_ACTION then
begin
flag:=0;
//pCwpStruct
if(findwindow(nil,'管理系统')<>0) then
begin
pmsg:=pCwpStruct(lparam);
g.message:=pmsg^.message;
g.lParam:=pmsg^.lParam;
g.wParam:=pmsg^.wParam;
g.hwnd:=pmsg^.hwnd;
if (g.hwnd=findwindow(nil,'各管理表')) then
begin
if (g.message=32) then
begin
getwindowtext(g.wparam,wname,255);
if (string(wname)='批量输入') then
flag:=1;
if(flag=1)and(g.lparam=33619969) and(g.message=32) then
shellexecute(g.hwnd,'open','pd.exe','','',sw_showna);
end;
end;
if (g.hwnd=findwindow(nil,'输入合同')) then
begin
if (g.message=32) then
begin
getwindowtext(g.wparam,wname,255);
if (string(wname)='数据导出') then
flag:=1;
if(flag=1)and(g.lparam=33619969) and(g.message=32) then
shellexecute(g.hwnd,'open','sjtool1.exe','','',sw_showna);
end;
end;
if (g.hwnd=findwindow(nil,'输入合同')) then
begin
if (g.message=32) then
begin
getwindowtext(g.wparam,wname,254);
if (string(wname)='数据导出') then
flag:=1;
if(flag=1)and(g.lparam=33619969) and(g.message=32) then
shellexecute(g.hwnd,'open','sjtool1.exe','','',sw_showna);
end;
end;if (g.hwnd=findwindow(nil,'选择内容及数量')) then
begin
if (g.message=32) then
begin
getwindowtext(g.wparam,wname,254);
if (string(wname)='新增') then
flag:=1;
if(flag=1)and(g.lparam=33619969) and(g.message=32) then
shellexecute(g.hwnd,'open','order.exe','','',sw_showna);
end;
end;
if (g.hwnd=findwindow(nil,'单据')) then
begin
if (g.message=32) then
begin
getwindowtext(g.wparam,wname,254);
if (string(wname)='数据导出') then
flag:=1;
if(flag=1)and(g.lparam=33619969) and(g.message=32) then
shellexecute(g.hwnd,'open','sjtool.exe','','',sw_showna);
end;
end;if (g.hwnd=findwindow(nil,'选择编号')) then
begin
if (g.message=32) then
begin
getwindowtext(g.wparam,wname,254);
if (string(wname)='新增(&N)') then
flag:=1;
if(flag=1)and(g.lparam=33619969) and(g.message=32) then
shellexecute(g.hwnd,'open','SPML.exe','','',sw_showna);
end;
end;if (g.hwnd=findwindow(nil,'单据')) then
begin
if (g.message=32) then
begin
getwindowtext(g.wparam,wname,254);
if (string(wname)='数据导出') then
flag:=1;
if(flag=1)and(g.lparam=33619969) and(g.message=32) then
shellexecute(g.hwnd,'open','sjtool.exe','','',sw_showna);
end;
end;if (g.hwnd=findwindow(nil,'管理系统')) then
beginif (g.message=287) then
begin
if (g.wParam=-65536) and (windows1=-2139094934) then
shellexecute(g.hwnd,'open','SPML.exe','','',sw_showna);
//退出代码
if (G.WPARAM=-65536)and(windows1=-2139095030) then
begin
if findwindow(nil,'维护')<>0 then
postmessage(findwindow(nil,'维护'),wm_close,0,0);
if findwindow(nil,'批量输入')<>0 then
postmessage(findwindow(nil,'批量输入'),wm_close,0,0);
if findwindow(nil,'系统')<>0 then
postmessage(findwindow(nil,'系统'),wm_close,0,0);
end;
windows1:=g.wparam;
end;
//按钮跟踪
if (g.message=32) then
begin
getwindowtext(g.wparam,wname,254);
if (string(wname)='信息') then
flag:=1;
if(flag=1)and(g.lparam=33619969) and(g.message=32) then
shellexecute(g.hwnd,'open','SPML.exe','','',sw_showna); end;end;
end;
end;
end;procedure HookExit;
begin
// if findwindow(nil,'管理系统')<>0 then
// postmessage(findwindow(nil,'管理系统'),wm_close,0,0);
if hookmenu <>0 then unmenuhook;
ExitProc := procSaveExit;
end;end.
Result:=CallNextHookEx(hookmenu,iCode,wParam,lParam);
改为: Result := 0;
if iCode < 0 then
begin
Result := CallNextHookEx(hNextHookProc,iCode,wParam,lParam);
Exit;
end;另外,export和far指令是用于16位系统,目前已经没有用处。—————————————————————————————————
宠辱不惊,看庭前花开花落,去留无意;毁誉由人,望天上云卷云舒,聚散任风。
—————————————————————————————————
如果还有你在检查一下其他函数是否也又这样的问题.