我如何使用WinAPI的阅读文本的MessageBox如何使用、文本、WinAPI、MessageBox

2023-09-04 11:50:20 作者:心如初

我如何读准赢消息框(信息)的消息?

How do I read a message of standard Win message box (Info)?

使用

SendMessage(this.HandleControl, WM_GETTEXT, builder.Capacity, builder);

我只能读消息框或标题按钮的文字,而不是信息本身。

I can only read the header of the message box or the text of the button, but not the message itself.

感谢。

this.HandleControl 是一个处理消息框窗口

this.HandleControl is a handler to the message box window

间谍++显示无子控件栏上的按钮。这就是它让我想,消息框有自己的保留文本瓦特/出使用标签

Spy++ shows no child controls bar the button. That's what it made me thinking that Message Boxes have their own way of keeping text w/out using labels

这是一个传统的应用程序写入德尔福,按钮的类是TButton的按间谍++,但仍然有对话窗口内的按钮,但没有任何控制。

It's a legacy app written with delp the button's class is TButton as per Spy++, but still there's no controls except of button inside the dialog window.

检查一个记事本窗口,无论是形象和功放后,文字是'选择',我想我的应用程序不使用一个std消息框。不过,我怎么去提取文本出来的东西吗?我可以看到,在我的德尔福的应用程序没有标签可以通过间谍++搜索工具进行选择。

After checking a notepad window, both Image & Text are 'selectable', I guess my app doesn't use a std MessageBox. still, how do I go about extracting the text out of the thing? I can see that no labels in my delphi app can be selected by Spy++ Finder tool.

推荐答案

消息文本是在模态消息框对话窗口上的标签控制。你必须得到的窗口句柄到MessageBox对话框(WIN32 API的FindWindow),然后检索窗口句柄来控制(WIN32 API函数GetDlgItem),然后检索该窗口的Win32 API GetWindowText函数)。

The message text is in a label control on the modal MessageBox dialog window. You have to get the window handle to the MessageBox dialog (win32 API FindWindow) then retrieve the window handle to the control (win32 API GetDlgItem) and then retrieve the text from that window win32 API GetWindowText).

编辑 -

TCHAR text[51] = {0};
HWND msgBox = ::FindWindow(NULL, TEXT("MessageBoxCaption"));
HWND label = ::GetDlgItem(msgBox, 0xFFFF);
::GetWindowText(label, text, sizeof(text)-1);