如何得到正在运行的程序名字?(38分)

  • 主题发起人 主题发起人 wwshuo
  • 开始时间 开始时间
W

wwshuo

Unregistered / Unconfirmed
GUEST, unregistred user!
就是windows任务管理器应用程序页中看到的程序名称,不是进程。
 
看看合适否。<br><br>unit Unit1;<br><br>interface<br><br>uses<br>&nbsp;Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,<br>&nbsp;StdCtrls;<br><br>type<br>&nbsp;TForm1 = class(TForm)<br>&nbsp; &nbsp;ListBox1: TListBox;<br>&nbsp; &nbsp;Button1: TButton;<br>&nbsp; &nbsp;procedure Button1Click(Sender: TObject);<br>&nbsp;private<br>&nbsp; &nbsp;{ Private declarations }<br>&nbsp;public<br>&nbsp; &nbsp;{ Public declarations }<br>&nbsp;end;<br><br>&nbsp;function EnumWndProc(AWnd:HWND;AlParam:LPARAM):Boolean;stdcall;<br>var<br>&nbsp;Form1: TForm1;<br><br>implementation<br><br>{$R *.DFM}<br><br>function EnumWndProc(AWnd: HWND; AlParam: LPARAM):Boolean;stdcall;<br>var<br>&nbsp;WndCaption: array[0..254] of Char;<br>begin<br>&nbsp;if IsWindowVisible(AWnd) then<br>&nbsp;begin<br>&nbsp; &nbsp;GetWindowText(AWnd, @WndCaption, 254);<br><br>&nbsp; &nbsp;if WndCaption[0]&lt;&gt;chr(0) then<br>&nbsp; &nbsp; &nbsp;Form1.ListBox1.Items.Add(Format('%d &nbsp;= &nbsp;%s',[AWnd,StrPas(WndCaption)]));<br>&nbsp;end;<br><br>&nbsp;Result := True;<br>end;<br><br>procedure TForm1.Button1Click(Sender: TObject);<br>begin<br>&nbsp;EnumWindows(@EnumWndProc,0);<br>end;<br><br>end. &nbsp;
 
得到的结果和windows任务管理器的信息还是有一些不一致。
 
以下转载:<br>================================================================================<br><br>bubble(2002-04-10 16:56) <br>这个是应用程序列表。<br>var<br>&nbsp;Form1: TForm1;<br>&nbsp; Wnd: HWND;<br>implementation<br><br>{$R *.DFM}<br><br>Function EnumWindowsProc (Wnd: HWND; lb: TListbox): BOOL; stdcall;<br>var<br>&nbsp;caption: Array [0..128] of Char;<br>begin<br>&nbsp;Result := True;<br>&nbsp;if { skip invisible windows }<br>&nbsp; &nbsp; IsWindowVisible(Wnd) and<br>&nbsp; &nbsp; { only process truly top-level windows. GetWindowLong must be used, not<br>GetParent }<br>&nbsp; &nbsp; ((GetWindowLong(Wnd, GWL_HWNDPARENT) = 0) or<br>&nbsp; &nbsp; &nbsp;(HWND(GetWindowLong(Wnd, GWL_HWNDPARENT)) = GetDesktopWindow)) and<br>&nbsp; &nbsp; { skip WS_EX_TOOLWINDOW windows }<br>&nbsp; &nbsp; ((GetWindowLong(Wnd, GWL_EXSTYLE) and WS_EX_TOOLWINDOW) = 0)<br>&nbsp;then begin<br>&nbsp; &nbsp;SendMessage( Wnd, WM_GETTEXT, Sizeof( caption ), integer(@caption));<br>&nbsp; &nbsp;lb.Items.AddObject( caption, TObject( Wnd ));<br>&nbsp;end;<br>end;<br><br>procedure TForm1.Button1Click(Sender: TObject);<br>begin<br>&nbsp;listbox1.clear;<br>&nbsp;EnumWindows( @EnumWindowsProc, integer( listbox1 ));<br>end;<br><br>procedure TForm1.ListBox1Click(Sender: TObject);<br>var<br>&nbsp;theClassname: Array [0..128] of Char;<br><br>&nbsp;tid, pid: DWORD;<br>&nbsp;intExitCode:DWORD;<br>begin &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br>&nbsp;With Sender As TListbox Do Begin<br>&nbsp; &nbsp;If ItemIndex &gt;= 0 Then Begin<br>&nbsp; &nbsp; &nbsp;Wnd:= HWND(Items.Objects[ itemindex ]);<br>&nbsp; &nbsp; &nbsp;If Wnd &lt;&gt; 0 Then Begin<br>&nbsp; &nbsp; &nbsp; &nbsp;Windows.GetClassname( Wnd, theClassname, Sizeof( classname ));<br>&nbsp; &nbsp; &nbsp; &nbsp;tid := GetWindowThreadProcessID( Wnd, @pid );<br>&nbsp; &nbsp; &nbsp; &nbsp;label1.caption :=<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Format(<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;'HWND: %8.8x'#13#10+<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;'Class: %s'#13#10+<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;'Process ID: %8.8x'#13#10+<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;'Thread ID: %8.8x',<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;[Wnd, theClassname, pid, tid] );<br>&nbsp; &nbsp; &nbsp;End;<br>&nbsp; &nbsp;End;<br>&nbsp;End;<br>end;<br>&nbsp;<br>教父(2002-04-11 11:00) <br>Del_Sun的方法并不能在NT下使用。<br>bubble的方法基本上没有问题了,但是加了<br>&nbsp; &nbsp; { skip WS_EX_TOOLWINDOW windows }<br>&nbsp; &nbsp; ((GetWindowLong(Wnd, GWL_EXSTYLE) and WS_EX_TOOLWINDOW) = 0)<br>之后,QQ不会显示出来,去掉这一句又会出现一些其它不想要的东西,有没有办法去掉<br>一些不想要的窗体?如果实在没有办法就算了。 :)<br>&nbsp;<br>bubble(2002-04-11 11:15) <br>sorry 我用的win2000,开了foxmail和金山此吧及毒吧<br>(它们都在进程里面而不是应用程序里面),<br>只要在托盘区的你看看应用程序里面都没有,只有在进程里面有。<br>&nbsp;<br>教父(2002-04-11 11:57) <br>我用的是XP,在托盘区的程序不在应用程序里我想是因为 <br>if { skip invisible windows }<br>&nbsp; &nbsp; IsWindowVisible(Wnd)<br>这段代码起了作用,是任务管理器里头也可以看到QQ的,去掉<br>&nbsp; &nbsp; { skip WS_EX_TOOLWINDOW windows }<br>&nbsp; &nbsp; ((GetWindowLong(Wnd, GWL_EXSTYLE) and WS_EX_TOOLWINDOW) = 0)<br>这一段会把系统的两个程序也给包含进来,你试试看看。<br>&nbsp;<br>bubble(2002-05-11 12:44) <br>[:(]<br>是的,我试验过了,最多也就能找到这些窗口了,<br>这个程序是遍历可以找到的顶级窗口的。<br>[:)]
 
getmodulefilename
 
applicaton.exename
 
接受答案了.
 
后退
顶部