how to get the message of the messsagebox?

hi members of the forum , i have a question about messageboxes , this is:
How to get the "string" message of a messagebox from window handle?, i mean not the title of the the messagebox, just the message that show the messagebox

thank you

[245 byte] By [xavierkdna] at [2007-12-16]
# 1
I'm not really sure what you mean, but if you need to show a string with a messagebox, just type: MessageBox("Youe text here");
ProgramWizard at 2007-9-9 > top of Msdn Tech,Visual C++,Visual C++ General...
# 2
I think you're asking how to extract the string printed by a Message Box. This type of query is best handled in one of the Win32 forums or newsgroups. I will see if I can dig up the information in the meantime.
BorisJabes at 2007-9-9 > top of Msdn Tech,Visual C++,Visual C++ General...
# 3
Well, if you already have the HWND of the Message Box then you can do:


char text[256];
GetWindowText(FindWindowEx(hwnd_msgbox, 0, "Static", 0), text, 256);


1) MessageBox() pauses the thread it is called in so you have to get the text from another thread.
2) I don't know what you are doing so I can't say how you should get the message box's HWND to begin with but depending on your circumstances FindWindow(Ex)(), GetForegroundWindow(), GetAncestor(), and friends might help your cause.
RITZ at 2007-9-9 > top of Msdn Tech,Visual C++,Visual C++ General...
# 4
thanks RITZ, i could get the text of the message , with your help, about the FindwindowsEx function, but i just could get the text of the message only for a messagebox with the button OK, but in the messageboxes that have more buttons, like "yes", "no" and "cancel", i couldn′t get the text of the messagebox, should I change the parameter of FindwindowEx?
thanks again for your help
xavierkdna at 2007-9-9 > top of Msdn Tech,Visual C++,Visual C++ General...
# 5
I see, I'm sure that is because of the icon wich is also a static control.


void GetMessageBoxText(HWND hw_msgbox, char *text, int max)
{
HWND hw_static = 0;
do
{
hw_static = FindWindowEx(hw_msgbox, hw_static, "Static", 0); // find first/next static control in message box
}
while(GetWindowLong(hw_static, GWL_STYLE) & SS_ICON); // reiterate if this static control is an icon
GetWindowText(hw_static, text, max); // grab text
}


That should do it.. (untested).
RITZ at 2007-9-9 > top of Msdn Tech,Visual C++,Visual C++ General...
# 6
thanks a lot RITZ it work very well, by the way i got the window handle with hook functions, thanks again
xavierkdna at 2007-9-9 > top of Msdn Tech,Visual C++,Visual C++ General...