LoginSignup
0
1

More than 5 years have passed since last update.

C++ Builder XE4, 10.2 Tokyo > エラーメッセージウィンドウ > エラーメッセージを別ソフトから取得する

Last updated at Posted at 2017-12-21
動作環境
C++ Builder XE4
RAD Studio 10.2 Tokyo Update 2 (追記: 2018/01/05)

関連

C++ Builder > メモリが足りません (Abnormal Program Termination) > 再現方法

処理

エラーメッセージが表示されている状態で、そのエラーメッセージを別ソフトから取得する。

参考: https://stackoverflow.com/questions/27260843/get-textbox-value-and-show-it-as-messagebox-winapi

answered Dec 2 '14 at 23:52
FelipeDurar

該当のHWND値をどう取得するか。

Microsoft Spy++で確認したところ、エラーメッセージは下記のようになる。

  • 'OK' Button
  • '' Static
  • 'メモリが足りません.' Static

方針としては、「Staticの次のStatic」を取得する。

参考: Zオーダーのウインドウを取得

code

Unit2.cpp
//---------------------------------------------------------------------------

#include <vcl.h>
#pragma hdrstop

#include "Unit2.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm2 *Form2;
//---------------------------------------------------------------------------
__fastcall TForm2::TForm2(TComponent* Owner)
    : TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm2::Button1Click(TObject *Sender)
{
    HWND winhwnd;

    winhwnd = FindWindow(NULL, L"Project1");
    if (winhwnd == NULL) {
        return;
    }

    HWND msghwnd = FindWindowEx(winhwnd, NULL, L"Static", NULL);
    HWND nexthwnd = GetWindow(msghwnd, GW_HWNDNEXT);

    HWND target = nexthwnd;

    int len = GetWindowTextLength(target) + 1;
    wchar_t text[100]; // 100: 任意の長さ
    GetWindowText(target, text, len);
    ShowMessage(text);
}
//---------------------------------------------------------------------------

実行例

qiita.png

qiita.png

10.2 Tokyo

10.2 Tokyoでも動作した。
エラーメッセージは異なる。

参考: C++ Builder 10.2 Tokyo > Error: OleStr型からDate型へのバリアント型変換はできません。

qiita.png

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