How to read MessageBox text using WinAPI

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

Using

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

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

thanks.

Notes (from Q & A):

this.HandleControl is a message box window handler

Spy ++ does not show any child controls. This is what made me think Message Boxes have their own way of storing text without labels

This is an obsolete application written using delphi, the TButton button class according to Spy ++, but still there are no controls except the button inside the dialog box.

After checking the notepad window, both images and text are โ€œselectedโ€, I think my application does not use std MessageBox. yet how can i extract text from this thing? I see that no shortcuts in my delphi application can be selected with the Spy ++ Finder tool.

+4
source share
2 answers

The message text is in the label control in the MessageBox modal dialog box. You should get the window handle in the MessageBox dialog box (win32 API FindWindow), and then return the window handle to the control (win32 API GetDlgItem), and then extract the text from this window win32 API GetWindowText).

EDIT -

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

Try to simulate a copy operation (Ctrl-C), then extract the text from the clipboard: messages allow you to copy all content in this way (if they are executed correctly).

The OP commented on this: it worked, thanks. I could do so. Ideally, we wanted our implementation to focus independently, but by choosing between a dedicated computer and OCR, I would probably go the first way.

Personally, I tested this in Delphi 6, and it looks like this:

 --------------------------- Confirm --------------------------- You are about to close the program WARNING: Are you sure? --------------------------- Yes No --------------------------- 

Note. . This is based on the answer suggested by "Stefan" in the comments on the original Question

+1
source

All Articles