高手快来救我!!!!如何根据某窗口句柄得到产生其的执行文件名。(100分)

  • 主题发起人 主题发起人 quaver
  • 开始时间 开始时间
Q

quaver

Unregistered / Unconfirmed
GUEST, unregistred user!
我在窗口枚举函数中是这样写的:<br>&nbsp;if getTopWindow(wHandle)&gt;0 then<br>&nbsp; &nbsp;if GetWindowText(wHandle,winName,SizeOf(winName)) &gt; 0 then<br>&nbsp; &nbsp;begin<br>&nbsp; &nbsp; &nbsp; &nbsp;if IsIconic(wHandle) then ShowWindow(wHandle, SW_RESTORE)<br>&nbsp; &nbsp; &nbsp; &nbsp;else BringWindowToTop(wHandle); &nbsp; &nbsp; &nbsp; <br>&nbsp; &nbsp; &nbsp; &nbsp;setForegroundWindow(wHandle);<br>&nbsp; &nbsp; &nbsp; &nbsp;winInstance:=getWindowLong(wHandle,GWL_HINSTANCE);//GWL_WNDPROC也试过;<br>&nbsp; &nbsp; &nbsp; &nbsp;setLength(winModuleName,200);<br>&nbsp; &nbsp; &nbsp; &nbsp;getModuleFileName(WinInstance,pChar(winModuleName),length(winModuleName));<br>&nbsp; &nbsp; &nbsp; &nbsp;winModuleName:=pchar(winModuleName);<br>&nbsp; &nbsp; &nbsp; &nbsp;listbox1.items.Add('文件名:'+winModuleName+'窗口名:'+StrPas(@winName));<br>&nbsp; &nbsp;end;<br>&nbsp;<br>结果winModuleName取值错误(取不到值或为本程序名),请高手赐教。<br>
 
application.exename可得到可执行文件名
 
application.exename得到的是自己的文件名
 
据说 FindExecutable 可以实现。
 
winInstance,不是Module handle,它只是process的 base of virtual address.<br>用GetWindowThreadProcessId获得windows所在process的ID<br>用Toolhelp枚举当前processes,找出文件名。<br>似乎比较麻烦,有更好的解决办法,可告我一声。<br><br>uses windows,tlhelp32;<br><br>function getexefilename(wh:Thandle):string;<br>var<br>&nbsp;p:Dword;<br>&nbsp;thh:Thandle;<br>&nbsp;lppe:tagProcessentry32;<br>&nbsp;buf:array[0..200] of char;<br>begin<br>&nbsp; GetWindowThreadProcessId(handle,@p);<br>&nbsp; thh:=CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS,0);<br>&nbsp; lppe.dwSize:=sizeof(lppe);<br>&nbsp; Process32First(thh,lppe);<br>&nbsp; if lppe.th32ProcessID=p then<br>&nbsp; &nbsp;begin<br>&nbsp; &nbsp; result:=lppe.szExeFile;<br>&nbsp; &nbsp; exit;<br>&nbsp; &nbsp;end;<br>&nbsp; while Process32Next(thh,lppe) do<br>&nbsp; &nbsp;if lppe.th32ProcessID=p then<br>&nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; result:=lppe.szExeFile;<br>&nbsp; &nbsp; &nbsp; break;<br>&nbsp; &nbsp; end;<br>end;
 
接受答案了.
 
在结束讨论后,我还想知道怎么样得到当前所有打开的窗口的句柄
 
后退
顶部