[求教]知道某个进程的ID,该进程弹出了一个MessageBox,我怎么取得这个MessageBox的句柄呢?(20分)

  • 主题发起人 主题发起人 cornermoss
  • 开始时间 开始时间
C

cornermoss

Unregistered / Unconfirmed
GUEST, unregistred user!
var &nbsp;<br> &nbsp; PI:TProcessInformation; &nbsp;<br> &nbsp; SI:TStartUpInfo; &nbsp;<br> &nbsp; hRegExe:THandle; &nbsp;//Regedit.exe进程句柄 &nbsp;<br>begin &nbsp;<br> &nbsp; FillChar(SI,SizeOf(SI),#0); &nbsp;<br> &nbsp; &nbsp; &nbsp; with &nbsp;SI &nbsp;do &nbsp;begin &nbsp;<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; cb:=SizeOf(SI); &nbsp;<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; dwFlags:=StartF_UsesTDHandles &nbsp;or &nbsp;STARTF_USESHOWWINDOW; &nbsp;<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; lpTitle:=nil; &nbsp;<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; wShowWindow:=SW_Show; &nbsp;<br> &nbsp; &nbsp; &nbsp; end; &nbsp;<br> &nbsp; &nbsp; &nbsp; CreateProcess('C:/Windows/regedit.exe', &nbsp;PChar(' &nbsp;'+sRegFile), &nbsp;nil,nil,True,DETACHED_PROCESS,nil,nil,SI,PI); &nbsp;<br> &nbsp; &nbsp; &nbsp; hRegExe &nbsp;:= &nbsp;OpenProcess(PROCESS_ALL_ACCESS, &nbsp;FALSE,PI.dwProcessId); &nbsp;<br> &nbsp; &nbsp; &nbsp; if &nbsp;hRegExe=0 &nbsp;then &nbsp;begin &nbsp;<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ShowMessage('Regedit &nbsp;tool &nbsp;can''t &nbsp;run!'); &nbsp;<br> &nbsp; &nbsp; &nbsp; end &nbsp;else &nbsp;begin &nbsp;<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; hRegEdit &nbsp;:= &nbsp;FindWindowEx(hRegExe, &nbsp;0, &nbsp;'#32770', &nbsp;NIL); &nbsp;//为什么这样取不到MessageBox的句柄呢? &nbsp;'#32770'是我用其它工具查到的MessageBox的类名,已证实该类名是正确的 &nbsp;<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ShowMessage(IntToStr(hRegEdit)); &nbsp; &nbsp;<br> &nbsp; &nbsp; &nbsp; end; &nbsp;<br> &nbsp; &nbsp; &nbsp; CloseHandle(hRegExe); &nbsp;<br> <br> &nbsp; end;
 
to cornermoss:<br>根据你的程序来看,用getactivewindow()就可以了;<br>注意:<br>若出现了MessageBox,则进程处于挂起状态(自我理解的,不一定确切),直到你按下确定按钮,进程继续运行,也就是说,getactivewindow()放在哪里比较合适,个人认为用一个定时器TTimer比较简单,把getactivewindow()放在Ontimer事件里。
 
后退
顶部