LoginSignup
1
1

More than 5 years have passed since last update.

C++ Builder XE4, 10.2 Tokyo > notepad > 他のソフトの座標を取得する > GetWindowRect()使用

Last updated at Posted at 2017-01-24
動作環境
C++ Builder XE4
   Windnows 7 pro (32bit)

RAD Studio 10.2 Tokyo Update 2 (追記: 2017/12/28)

他のソフトの座標を取得する。

メモ帳を対象ソフトとして実装した。

参考 C#での実装例 @ stackoverflow
参考 GetWindowRect @ MSDN
参考 Delphiでの実装例 @ stackoverflow

Unit1.cpp
//---------------------------------------------------------------------------

#include <vcl.h>
#pragma hdrstop

#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
    : TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
    String fullCaption = L"無題 - メモ帳";

    HWND appHwnd;

    appHwnd = FindWindowEx(NULL, NULL, NULL, fullCaption.c_str());
    if (appHwnd == NULL) {
        return;
    }

    SetForegroundWindow(appHwnd); // 前面に映す


    TRect lpRect;
    GetWindowRect(appHwnd, &lpRect);

    int nop=1;

}
//---------------------------------------------------------------------------
  1. メモ帳を起動する
    • キャプションは「無題 - メモ帳」であること
  2. 上記のソフトをデバッグモードで実行し
    • int nop=1;にてブレークポイントで止める

以下のように、lpRectにleft, top, right, bottomが得られた。

qiita.png

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1