掲示板システム
ホーム
アクセス解析
カテゴリ
ログアウト
自作アプリのラベルのCaption等を取得するには? (ID:33661)
名前
ホームページ(ブログ、Twitterなど)のURL (省略可)
本文
メッセージを使った例 ------------------------------ 【共有ユニット】 unit ShareUnit; interface uses Windows, Messages; const //マウスカーソル位置のラベルキャプションを //送信するよう依頼するメッセージ WM_GET_LABEL_CAPTION=WM_APP + 1; //WM_COPYDATA の識別用 GET_LABEL_CAPTION_DATA= 20090315; //適当な値 //Captionの最大サイズ MAX_CAPTION_SIZE=128; type TLabelCaptionRec= packed record dsCaption: array[0..MAX_CAPTION_SIZE-1] of Char; end; TMyData= packed Record Msg: Cardinal; SenderHandle: HWND; Reserved: LongInt; Result: Longint; end; ------------------------------ 【監視側】 TFormA = class(TForm) procedure Timer1Timer(Sender: TObject); private //WM_COPYDATA procedure WMCopyData(var aMessage:TWMCopyData);message WM_COPYDATA; public end; implementation uses ShareUnit; procedure TFormA.Timer1Timer(Sender: TObject); var activeHandle: HWND; begin activeHandle := GetForegroundWindow; if (activeHandle > 0) and (activeHandle <> Handle) then begin SendMessage(activeHandle, WM_GET_LABEL_CAPTION, Self.Handle, 0); end; end; //WM_COPYDATA procedure TFormA.WMCopyData(var aMessage:TWMCopyData); var pLabelCaptionRec:^TLabelCaptionRec; pCaption: PChar; begin if aMessage.CopyDataStruct^.dwData = GET_LABEL_CAPTION_DATA then begin pLabelCaptionRec := aMessage.CopyDataStruct^.lpData; pCaption := @pLabelCaptionRec^.dsCaption; Label1.Caption := pCaption; end; end; ------------------------------ 【別アプリ側】 TFormB = class(TForm) private //WM_COPYDATA procedure GetLabelCaptionData(var aMyData: TMyData); message WM_GET_LABEL_CAPTION; end; implementation procedure TFormB.GetLabelCaptionData(var aMyData: TMyData); var mp: TPoint; ctrl: TControl; copyDataStruct: TCopyDataStruct; labelCaptionRec: TLabelCaptionRec; begin //マウスカーソルの座標 GetCursorPos(mp); //フォーム上のカーソル位置 mp := ScreenToClient(mp); //Control取得 ctrl := ControlAtPos(mp, False); //送信準備 copyDataStruct.dwData := GET_LABEL_CAPTION_DATA; copyDataStruct.cbData := SizeOf(TLabelCaptionRec); copyDataStruct.lpData := @labelCaptionRec; //Caption編集 if (ctrl <> nil) and (ctrl is TLabel) then StrPLCopy(labelCaptionRec.dsCaption, TLabel(ctrl).Caption, MAX_CAPTION_SIZE) else StrPLCopy(labelCaptionRec.dsCaption, '×', MAX_CAPTION_SIZE); //送信 SendMessage(aMyData.SenderHandle, WM_COPYDATA, Handle, Integer(@copyDataStruct)); end;
←解決時は質問者本人がここをチェックしてください。
更新する
戻る
掲示板システム
Copyright 2021 Takeshi Okamoto All Rights Reserved.