紧急救助,hook程序在98上面报错!!!!! (100分)

  • 主题发起人 guyigood
  • 开始时间
G

guyigood

Unregistered / Unconfirmed
GUEST, unregistred user!
目的,监控一个程序的一个窗口上面的按钮按下事件。
代码如下,在w2k上可以运行,但时间不能太长,否则报错,在98下面运行提示系统
资源不足,随后死机。
请各位高手指点一下。非常感谢。
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;



implementation



function 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
//f1:textfile;
pmsg:pCwpStruct;
g:TCwpStruct;
g1,g2:hwnd;
//spcx:Tspfl;
i:integer;
WName:array[0..254] of char;
//wname:pchar;
begin
//pCwpStruct
pmsg:=pCwpStruct(lparam);
g.message:=pmsg^.message;
g.lParam:=pmsg^.lParam;
g.wParam:=pmsg^.wParam;
g.hwnd:=pmsg^.hwnd;
if (g.hwnd=findwindow(nil,'选择一个))and(g.message=273) then
begin
g1:=getwindow(g.hwnd,gw_child);
for i:=1 to 1000 do
begin
g2:=GetWindow(g1,GW_HWNDNEXT);
getwindowtext(g2,wname,254);
if (string(wname)='分类查询') then
break;
g1:=g2;
end;
if g.lParam=g2 then
begin
// spcxnew;
shellexecute(g.hwnd,'open','spflcx.exe','','',sw_showna);
end;
// messagebox(g.hwnd,'fkdsj','dfaldja',sw_show);
end;
//wm_command
if (g.message=287)and(g.hwnd=findwindow(nil,'xxx')) then
begin
//查询菜单id
if (g.wparam=-65536)and(windows1=-2139095014)then
begin
// zk:=tspzkwh.Create(application);
// zk.showmodal;
// zk.free;
shellexecute(g.hwnd,'open','zk.exe','','',sw_showna);
end;
if findwindow(nil,'xxxx')<>0 then
postmessage(findwindow(nil,'xxxx'),wm_close,0,0);
end;
windows1:=g.wparam;
Result:= 1;
end
else
begin
CallNextHookEx(hookmenu,icode,WParam,LParam);
Result := 0;
end;
end;

procedure HookExit;
begin
if findwindow(nil,'xxxx')<>0 then
postmessage(findwindow(nil,'xxxx'),wm_close,0,0);
if hookmenu <>0 then unmenuhook;
ExitProc := procSaveExit;
end;

end.


发现去掉这段代码,可以正常运行,那位大哥给点意见吧,拜托了!
if (g.hwnd=findwindow(nil,'选择一个))and(g.message=273) then
begin
g1:=getwindow(g.hwnd,gw_child);
for i:=1 to 1000 do
begin
g2:=GetWindow(g1,GW_HWNDNEXT);
getwindowtext(g2,wname,254);
if (string(wname)='分类查询') then
break;
g1:=g2;
end;
 
真的没有人知道吗,要分数可以加的哦。就算要现金也可以,请懂得大虾跟我联系,
help@cnguyi.com
 
没分配内存!傻瓜!
 
请问一下如何具体的实现方法。谢谢
 
怎么没有知道吗,高手在那里,呼唤高手。
 
难道这个论坛真的没有人能够回答吗,拜托大家知道的快告诉我吧,先谢谢了。
 
这个论坛上看来没有高手,幸亏自己已经解决,分数谁也不给了。省了。
 

Similar threads

I
回复
0
查看
635
import
I
I
回复
0
查看
701
import
I
I
回复
0
查看
493
import
I
顶部