掲示板システム
ホーム
アクセス解析
カテゴリ
ログアウト
EnumChildWindowsでTLabelを取得するには? (ID:45387)
名前
ホームページ(ブログ、Twitterなど)のURL (省略可)
本文
EnumChildWindowsでTLabelが取得できません。 http://mrxray.on.coocan.jp/Halbow/VCL06.html#VChap6-5 のList19でやっている「子ウィンドウの探索」がまさにやりたいことなのですが、 TLabelが列挙されません。 冒頭で >TLabel や TImage 、TPaintBox 、 TSpeedButton などの TGraphicControl の派生クラスは、 >ウィンドウの特定のクライアント領域の描画機能をカプセル化したものであり、 >ウィンドウではないのでOSからは見えない。 と記載されており、 TLabelはEnumChildWindowsで取得できないのかもしれませんが、 どうにか取得する方法がありませんか? よろしくお願いします。 //以下サンプル //フォームにはTButtonとTListBoxとTLabelを最低1個置き、そのほかは適当に配置している状態 unit Unit1; interface uses Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, ComCtrls, ExtCtrls, StdCtrls; type TForm1 = class(TForm) Button1: TButton; Label1: TLabel; Button2: TButton; ComboBox1: TComboBox; Panel1: TPanel; Label2: TLabel; Button3: TButton; ComboBox2: TComboBox; ListBox1: TListBox; procedure Button1Click(Sender: TObject); private { Private 宣言 } public { Public 宣言 } end; var Form1: TForm1; implementation {$R *.DFM} type PHWndArray = ^THWndArray; THWndArray = array[0..500] of HWND; function EnumChildWndProc(hWindow:HWND;lData:LPARAM):BOOL;stdcall; var pWA:PHWndArray; begin pWA := PHWndArray(lData); pWA^[0] := pWA^[0]+1; pWA^[pWA^[0]] := hWindow; result := true; end; function AEnumChildWindows(var WA:THWndArray; hParent:HWND):integer; begin WA[0] := 0; EnumChildWindows(hParent,@EnumChildWndProc,LPARAM(@WA)); result := WA[0]; end; function GetClassNameStr(hWindow:HWND):string; var p:PChar; ret:integer; begin GetMem(p,100); ret := GetClassName(hWindow,p,100); SetString(result,p,ret); FreeMem(p); end; function GetWindowTextStr(hWindow:HWND):string; var p:PChar; ret:integer; begin ret := GetWindowTextLength(hWindow); GetMem(p,ret+1); ret := GetWindowText(hWindow,p,ret+1); SetString(result,p,ret); FreeMem(p); end; procedure TForm1.Button1Click(Sender: TObject); var SL:TStringList; WA:THWndArray; i,Num:integer; begin ListBox1.clear; SL := TStringList.Create; try Num := AEnumChildWindows(WA,Handle); Label1.Caption := IntToStr(Num); if Num > 0 then for i := 1 to Num do begin ListBox1.Items.Add(GetClassNameStr(WA[i])+'/'+GetWindowTextStr(WA[i])); end; finally SL.Free; end; end; end.
←解決時は質問者本人がここをチェックしてください。
更新する
戻る
掲示板システム
Copyright 2021 Takeshi Okamoto All Rights Reserved.