掲示板システム
ホーム
アクセス解析
カテゴリ
ログアウト
自作アプリのラベルのCaption等を取得するには? (ID:33659)
名前
ホームページ(ブログ、Twitterなど)のURL (省略可)
本文
自作アプリの上にマウスカーソルを重ねると、 その場所のLabel等のコンポーネントのCaptionを 取得できるような、別のアプリを作成したいのです。 その別のアプリのソースが以下ですが、 "X"のコメントの所で、AccessViolationエラーが 発生してしまいます。HWND型の変数:actHndlを TForm型で扱う方法がわかりません。教えて下さい。 unit Unit1; interface uses Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, ExtCtrls; type TForm1 = class(TForm) Timer1: TTimer; Label1: TLabel; procedure FormShow(Sender: TObject); procedure FormClose(Sender: TObject; var Action: TCloseAction); procedure Timer1Timer(Sender: TObject); private { Private 宣言 } public { Public 宣言 } end; var Form1: TForm1; implementation {$R *.DFM} procedure TForm1.FormShow(Sender: TObject); begin Timer1.Interval:=200; end; procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction); begin Timer1.Interval:=0; end; procedure TForm1.Timer1Timer(Sender: TObject); var actHndl : HWND; actR : TRect; cp : TPoint; i : integer; c : array[0..255] of char; x1,y1 : integer; x2,y2 : integer; begin actHndl:=GetForeGroundWindow; if actHndl <> 0 then begin if actHndl <> Self.Handle then begin Timer1.Interval:=0; GetClassName(actHndl,c,SizeOf(c)); if c = 'TFormMain' then begin GetCursorPos(cp); GetWindowRect(actHndl,actR); for i:=0 to TForm(actHndl).ComponentCount-1 do begin//X if TForm(actHndl).Components[i] is TLabel then begin with TForm(actHndl).Components[i] as TLabel do begin x1:=actR.Left+Left;//x1,y1,x2,y2=TLabelの範囲 y1:=actR.Top+Top; x2:=x1+Width; y2:=y1+Height; if (y1 <= cp.Y) and (cp.Y <=y2) then begin//カーソルがTLabel範囲内 if (x1 <= cp.X) and (cp.X <= x2) then begin Label1.Caption:=Caption; break; end; end; end; end; end; end; Timer1.Interval:=200; end; end; end; end.
←解決時は質問者本人がここをチェックしてください。
更新する
戻る
掲示板システム
Copyright 2021 Takeshi Okamoto All Rights Reserved.