デスクトップのウィンドウのタイトルとハンドルを取得する
|
稼働中のウィンドウのタイトルとハンドルを取得するには、
APIのENumWindows関数を使います。
第一パラメータのコールバック関数は、タイトルとハンドル
をどのように処理するかを工夫します。
次の例はListBoxに列挙し、Labelにその数を示します。
function CallBackTest(WH: HWND; LP: LParam): BOOL stdcall;
var
Buf: array [0..255] of Char;
begin
// スタイル ビットがセットされているもののみ
if IsWindowVisible(hwnd) then
// タイトル バーのテキストをBufにコピー
if GetWindowText(WH, Buf, 255) <> 0 then
TListBox(LP).Items.AddObject(Buff, Pointer(hwnd));
Result := True;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
ListBox1.Clear;
EnumWindows(@CallBackTest, Longint(ListBox1));
Label1.Caption := IntToStr(ListBox1.Items.Count);
end;
|
|