Showing a message box in a child process.

Status
Not open for further replies.

ever_thus

Baseband Member
Messages
94
I created a child process in a Windows program with the following code:

PROCESS_INFORMATION info;
memset (&info, 0 , sizeof (info));
STARTUPINFO start;
memset (&start, 0 , sizeof (start));
start.lpReserved = NULL;
start.lpDesktop = "E:\desktop";
start.lpTitle = NULL;
start.dwX = 0;
start.dwY = 0;
start.dwXSize = 0;
start.dwYSize = 0;
start.dwXCountChars = 0;
start.dwYCountChars = 0;
start.dwFillAttribute = 0;
start.dwFlags = 0;
start.wShowWindow = 0;
start.cbReserved2 = 0;
start.lpReserved2 = NULL;
start.hStdInput = NULL;
start.hStdOutput = NULL;
start.hStdError = NULL;
start.cb = sizeof (start);
CreateProcess (NULL, Child_exe, NULL, NULL, FALSE, 0, NULL, NULL, &start, &info);

The child process then calls the message box function several times. When it does I hear the characteristic sound of a message box, Task Manager displays it in the open windows tab, but the box is nowhere to be seen on the screen. I tried fiddling around with the various x and y and wShowWindow members in the STRARTUPINFO struct, but nothing seems to help.
 
NULL. When calling MessageBox from a top-level process (or DLL in its address space) this is not a problem.
 
Well, NULL is the right HWND, dunno why it isn't working.

Maybe try passing down a HWND pointer from the parent process somehow?

Alternatively, you can Enum the Windows, find your parent Process, and use that HWND.
 
The entire process tree is not a GUI, so there are no HWNDs; the only windows I show are error messages for which I use MessageBox ()
 
Well you can always still call EnumWindows and find any window and try using that. You can even grab the HWND of explorer itself, if I remember correctly.
 
Still the same result. Here's the code I used.

In WinMain ():

HWND hWnd;
EnumWindows (GetNonChildWindow, (LPARAM) &hWnd);

and passed hWnd as the HWND to MessageBox ()

and getNonChildWindow ():

BOOL CALLBACK GetNonChildWindow (HWND hwnd, LPARAM lparam){
if (GetWindowLong (hwnd, GWL_STYLE) & WS_CHILD){
lparam = (LPARAM) &hwnd;
return false;
}
return true;
}
 
Status
Not open for further replies.
Back
Top Bottom