線上訂房服務-台灣趴趴狗聯合訂房中心
發文 回覆 瀏覽次數:2646
推到 Plurk!
推到 Facebook!

如何得知視窗工作列上所有正在運轉程式的名稱

答題得分者是:Zard
sam_000
一般會員


發表:27
回覆:47
積分:14
註冊:2003-09-15

發送簡訊給我
#1 引用回覆 回覆 發表時間:2004-11-16 08:41:11 IP:211.22.xxx.xxx 未訂閱
前輩好 windows允許許多程式同時執行,如何得知視窗工作列上所有正在運轉程式的名稱,請前輩幫忙 謝謝. sam上
aquarius
資深會員


發表:3
回覆:347
積分:330
註冊:2003-05-21

發送簡訊給我
#2 引用回覆 回覆 發表時間:2004-11-16 09:27:49 IP:210.243.xxx.xxx 未訂閱
給你一個範例看看...   相關函數的說明自己看 class="code"> unit Unit1; interface uses Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, tlhelp32, StdCtrls ; type TForm1 = class(TForm) Button1: TButton; Memo1: TMemo; procedure Button1Click(Sender: TObject); private { Private declarations } function ShowAllRunning:integer ; public { Public declarations } end; var Form1: TForm1; implementation {$R *.DFM} function TForm1.ShowAllRunning:integer ; var hSS : THandle ; ppp : TProcessEntry32 ; dwPID : DWORD ; begin Result:=0 ; memo1.Clear ; GetWindowThreadProcessID(0,@dwPID) ; hSS:=CreateToolhelp32Snapshot(TH32CS_SNAPProcess,dwPID) ; if Process32First(hSS,ppp) then begin Memo1.Lines.Add(strpas(ppp.szExeFile)) ; while Process32Next(hSS,ppp) do Memo1.Lines.Add(strpas(ppp.szExeFile)) ; end ; closeHandle(hSS) ; end ; procedure TForm1.Button1Click(Sender: TObject); begin ShowAllRunning ; end; end. ...Aquarius
------
水瓶男的blog: http://791909.blogspot.com
sam_000
一般會員


發表:27
回覆:47
積分:14
註冊:2003-09-15

發送簡訊給我
#3 引用回覆 回覆 發表時間:2004-11-16 13:30:26 IP:220.130.xxx.xxx 未訂閱
前輩好 測試您的例題,可以把目前全部的執行檔(包括隱藏或沒有form)顯示出來, 我只想要列出在視窗工作列上者有出現的程式名稱,不知是否可以達成? sam
Zard
尊榮會員


發表:24
回覆:396
積分:539
註冊:2003-11-26

發送簡訊給我
#4 引用回覆 回覆 發表時間:2004-11-16 13:37:49 IP:210.243.xxx.xxx 未訂閱
給你一範例, 這個範例可列出視窗工作列上所有視窗名稱
unit Unit1;    interface    uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls;    type
  TForm1 = class(TForm)
    Memo1: TMemo;
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }        Procedure ListAllActiveWnd();      end;    var
  Form1: TForm1;
  
  
implementation    {$R *.DFM}    Procedure TForm1.ListAllActiveWnd();      type
    PStringList = ^TStringList;      Function EnumWndProc(hWin: HWND; Param: LPARAM): BOOL; stdcall;
  var
    szBuf: array[0..100] of Char;
    
  begin
    // 取得所有可見的視窗
    if (IsWindow(hWin) and IsWindowVisible(hWin)) then
    begin
      // 只取最上層可見視窗
      if (Windows.GetParent(hWin) = 0) then
      begin
        FillChar(szBuf, SizeOf(szBuf), 0);
        GetWindowText(hWin, szBuf, SizeOf(szBuf));
        if (szBuf <> '') then
          PStringList(Param)^.AddObject(szBuf, TObject(hWin));
      end;
    end;        Result := TRUE;
  end;    var
  i: Integer;
  slWnd: TStringList;
  dwProcess1, dwProcess2: DWORD;
  
begin
  slWnd := TStringList.Create;
  // 用 EnumWindows 列舉出所有可能的視窗, 並記在TStringList中
  EnumWindows(@EnumWndProc, LPARAM(@slWnd));      Memo1.Lines.Clear;
  
  // 比對所有可能的視窗, 去掉屬於同一個Process的視窗
  // 最後一個一定是Program Manager, 所以loop只到slWnd.Count - 2, 直接去掉
  // Program Manager
  for i := 0 to slWnd.Count - 2 do
  begin
    GetWindowThreadProcessId(HWND(slWnd.Objects[i]), @dwProcess1);
    GetWindowThreadProcessId(HWND(slWnd.Objects[i   1]), @dwProcess2);
    if dwProcess1 <> dwProcess2 then
      Memo1.Lines.Add(slWnd.Strings[i]);
  end;      slWnd.Free;
end;    procedure TForm1.Button1Click(Sender: TObject);
begin
  ListAllActiveWnd;
end;    end.    
sam_000
一般會員


發表:27
回覆:47
積分:14
註冊:2003-09-15

發送簡訊給我
#5 引用回覆 回覆 發表時間:2004-11-16 17:48:21 IP:219.80.xxx.xxx 未訂閱
前輩太厲害了,可以了,謝謝兩位前輩,謝謝 sam
gaui
一般會員


發表:25
回覆:36
積分:12
註冊:2004-06-11

發送簡訊給我
#6 引用回覆 回覆 發表時間:2005-01-13 13:10:50 IP:61.59.xxx.xxx 未訂閱
不好意思! 不知道可不可以請問一下, 上面兩位先進提供的例子, 不知道有什麼不同, 請撥空指教。
系統時間:2024-05-02 9:40:35
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!