怎么样编程实现获得任务栏上所有窗口句柄?(100分)

N

nfy

Unregistered / Unconfirmed
GUEST, unregistred user!
怎么样编程实现获得任务栏上所有窗口句柄?最好有代码,我是新手
 
procedure Tform1.getname;<br>var<br>hCurrentWindow: HWnd;<br>szText: array[0..254] of char;<br>sef:string;<br>begin<br>hCurrentWindow := GetWindow(Handle, GW_HWNDFIRST);<br>while hCurrentWindow &lt;&gt; 0 do<br>begin<br>if GetWindowText(hCurrentWindow, @szText, 255)&gt;0 then<br>&nbsp;Memo1.Lines.Add(StrPas(@szText));<br>&nbsp;hCurrentWindow:=GetWindow(hCurrentWindow, GW_HWNDNEXT);<br>end;<br>
 
把分給了吧![:D]
 
能说说你的用处么<br>如果只是列出在上面运行的程序名<br>上面的已达到要求了<br>还有其它方法
 
jeary 真快啊!!!!
 
int CALLBACK EnumExe(HWND hwnd, LPARAM lParam)<br>{<br> WINDOWINFO windowinfo;<br> if(GetWindowInfo(hwnd, &amp;windowinfo))<br> {<br> if ((windowinfo.dwStyle &amp; 0x14CF0000) == 0x14CF0000)<br> {<br> char lpString[255];<br> // n++;<br> GetWindowText(hwnd, &nbsp;lpString, 255);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; sprintf(g_lpAppInfo + strlen(g_lpAppInfo), "%s,", lpString);<br> }<br> }<br><br> return true;<br>}<br><br>EnumWindows((WNDENUMPROC)EnumExe,0);
 
unit Unit1;<br><br>interface<br><br>uses<br>&nbsp; Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,<br>&nbsp; Dialogs, StdCtrls, Buttons;<br><br>type<br>&nbsp; TForm1 = class(TForm)<br>&nbsp; &nbsp; BitBtn1: TBitBtn;<br>&nbsp; &nbsp; ComboBox1: TComboBox;<br>&nbsp; &nbsp; procedure BitBtn1Click(Sender: TObject);<br>&nbsp; private<br>&nbsp; &nbsp; { Private declarations }<br>&nbsp; public<br>&nbsp; &nbsp; { Public declarations }<br>&nbsp; end;<br><br>var<br>&nbsp; Form1: TForm1;<br><br>implementation<br><br>{$R *.dfm}<br>function GetText(Wnd : HWND) : string;<br>var<br>&nbsp; &nbsp; textlength : integer;<br>&nbsp; &nbsp; text : PChar;<br>begin<br>&nbsp; &nbsp; textlength:=SendMessage(Wnd,WM_GETTEXTLENGTH,0,0);<br>&nbsp; &nbsp; if textlength=0 then<br> &nbsp; &nbsp;Result := ''<br>&nbsp; &nbsp; else begin<br>&nbsp; &nbsp; &nbsp; &nbsp; getmem(text,textlength+1);<br>&nbsp; &nbsp; &nbsp; &nbsp; SendMessage(Wnd,WM_GETTEXT,textlength+1,Integer(text));<br>&nbsp; &nbsp; &nbsp; &nbsp; Result:=text;<br>&nbsp; &nbsp; &nbsp; &nbsp; freemem(text);<br>&nbsp; &nbsp; end;<br>end;<br><br>function EnumWindowsProc (Wnd: HWND; LParam: LPARAM): BOOL; stdcall;<br>var<br>&nbsp; &nbsp; s : String ;<br>begin<br>&nbsp; &nbsp; Result := True;<br>&nbsp; &nbsp; if (IsWindowVisible(Wnd)) and (GetWindowLong(Wnd, GWL_HWNDPARENT) = 0) and (GetWindowLong(Wnd, GWL_EXSTYLE) and WS_EX_TOOLWINDOW = 0) then begin<br>// &nbsp; &nbsp; &nbsp; &nbsp;s := ''+Inttostr(Wnd)+', '+ GetText(Wnd) ;<br>&nbsp; &nbsp; &nbsp; &nbsp; s := GetText(Wnd) ;<br>&nbsp; &nbsp; &nbsp; &nbsp; Form1.Combobox1.items.add(s);<br>&nbsp; &nbsp; end;<br>end;<br><br>procedure TForm1.BitBtn1Click(Sender: TObject);<br>var<br>&nbsp; &nbsp; Param : Longint;<br>begin<br>&nbsp; &nbsp; Combobox1.Items.Clear;<br>&nbsp; &nbsp; Param := 0 ;<br>&nbsp; &nbsp; EnumWindows(@EnumWindowsProc , Param);<br>end;<br>这才是解决之道,可惜没发给自己加分阿,我以解决了
 
多人接受答案了。
 
顶部