如何得到当前桌面打开的窗口标题! (50分)

  • 主题发起人 主题发起人 afasl
  • 开始时间 开始时间
A

afasl

Unregistered / Unconfirmed
GUEST, unregistred user!
我想做一个带老板键的程序,实现热键隐藏所有打开窗口的功能。:)<br>我用GetWindow得到的是系统中所有运行程序的Handle,请问各位大虾如何依次得到当前桌面上打开的窗口的Handle?不是所有的运行程序的。<br>对不起,我刚才的问题没描述清楚,让大家误会了,谢谢大家的回答。
 
GetForegroundWindow<br>ShowWindow
 
使用GetWindowText函数。
 
unit Unit1;<br><br>interface<br><br>uses<br>&nbsp; Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,<br>&nbsp; Dialogs, 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>var<br>&nbsp; Form1: TForm1;<br><br>implementation<br><br>{$R *.dfm}<br><br>procedure TForm1.Button1Click(Sender: TObject);<br>var<br>&nbsp; hCurrentWindow: HWnd;<br>&nbsp; szText: array[0..254] of char;<br>begin<br>&nbsp; hCurrentWindow := GetWindow(Handle, GW_HWNDFIRST);<br>&nbsp; while hCurrentWindow &lt;&gt; 0 do<br>&nbsp; begin<br>&nbsp; &nbsp; if GetWindowText(hCurrentWindow, @szText, 255)&gt;0 then<br>&nbsp; &nbsp; &nbsp; ListBox1.Items.Add(StrPas(@szText));<br>&nbsp; &nbsp; hCurrentWindow:=GetWindow(hCurrentWindow, GW_HWNDNEXT);<br>&nbsp; end;<br>end;<br><br>end.<br>
 
用GetActiveWindow可以取得前桌面上打开窗体的handle,取其标题如下:<br>var<br>&nbsp; wtext:pchar;<br>begin<br>&nbsp; getmem(wtext,255);<br>&nbsp; getwindowtext(GetActiveWindow,wtext,255);<br>&nbsp; showmessage(strpas(wtext));<br>&nbsp; freemem(wtext);<br>end;
 
我搞定了。用IsWindowVisible来判断过滤一下就可以了。
 
后退
顶部