0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

C++ Builder XE4 > 起動している多数のソフトのキャプションを取得 v0.1 (+ 別の方法に関する追記)

Last updated at Posted at 2018-10-23
動作環境
C++ Builder XE4

起動している多数のソフトウェアのキャプションを取得してみる。

参考

情報感謝です。

実装

  • 一つ目のサンプルコードをXE4で動くようにコードを修正
    • TMemoへ出力
    • UnicodeStringに対応
  • 階層を定義し、1階層下までを表示
Unit1.cpp
//---------------------------------------------------------------------------

# include <vcl.h>
# pragma hdrstop

# include "Unit1.h"
# include <Windows.h>
//---------------------------------------------------------------------------
# pragma package(smart_init)
# pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
	: TForm(Owner)
{
}
//---------------------------------------------------------------------------

static const int kMaxDepth = 1; // チェックする階層数

void TForm1::EnumetareWindows(HWND hWndParent, int depth)
{
	wchar_t szBuff[512] = {0};
	GetWindowText(hWndParent, szBuff, 512);

	if (szBuff[0] != 0x00) {
		if (depth <= kMaxDepth) {
			String msg = IntToStr(depth) + L":" + String(szBuff);
			Memo1->Lines->Add(msg);
		}
	}

	HWND hWndChild = FindWindowEx(hWndParent, NULL, NULL, NULL);
	if (hWndChild == NULL) {
		return;
	}

	do {
		EnumetareWindows(hWndChild, (depth+1));
	} while ( (hWndChild = FindWindowEx(hWndParent, hWndChild, NULL, NULL)) != NULL );
}

void __fastcall TForm1::Button1Click(TObject *Sender)
{
	Memo1->Lines->Clear();

	HWND hWndParent = GetDesktopWindow();
	EnumetareWindows(hWndParent, /*depth=*/0);
}
//---------------------------------------------------------------------------

実行

  • C++ Builder XE4起動状態
  • ビルドしたソフト起動状態
    • Project1.exe
  • Tera Term起動状態
  • メモ帳起動状態

2018-10-23_09h03_12.png

備考

余分なウィンドウも捉えられるが、フィルタ条件を考慮すれば、希望のソフトのキャプションを取得できるだろう。

別の方法 > EnumWindows()

(追記 2018/10/24)

下記の記事を作る中、EnumWindows()を使う方法があると知りました。

0
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
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?