Why does dialog box for calling program turn white?

I have an MFC program that calls another program with ShellExecuteEx() and I notice that the outline of the dialog box for the calling program turns white while waiting for the called program to exit.  The call code is

               ZeroMemory(&ShellExecuteInfo, sizeof(ShellExecuteInfo));

            str.Format("%d", daysLeft);      // parameter to pass
            ShellExecuteInfo.cbSize = sizeof(ShellExecuteInfo);
            ShellExecuteInfo.fMask = SEE_MASK_NOCLOSEPROCESS;
            ShellExecuteInfo.hwnd = NULL;            // NULL for local window
            ShellExecuteInfo.lpVerb = "open";
            ShellExecuteInfo.lpFile = lpFile;      // file to call: Buy.exe            
            ShellExecuteInfo.lpParameters = str;            // daysLeft parameter
            ShellExecuteInfo.nShow = SW_SHOWNORMAL;


            /*      
                  Wait       at 0% CPU utilization.
            */

            WaitForSingleObject(ShellExecuteInfo.hProcess, INFINITE);      // infinite timeout

//////////////////////////////////

Does anyone know what's going on here.  I would like the calling program dialog box to remain visible while the called program executes.

Thanks,
steva
stevaAsked:
Who is Participating?
 
mahesh1402Commented:
What if you use CreateProcess instead of ShellExecuteEx something like following :

   STARTUPINFO         si;
   PROCESS_INFORMATION pi;
   BOOL                bRes;
   DWORD               dwCode  =   0;
   MSG                           msg;
   ZeroMemory  (   &si,    sizeof  (   STARTUPINFO));
   si.cb           =   sizeof  (   STARTUPINFO);
   si.dwFlags      =   STARTF_USESHOWWINDOW;
   si.wShowWindow  =   SW_SHOWNORMAL;
 
  bRes    =   CreateProcess   (   NULL,
                                   pszCmd,  // execute string
                                   NULL,
                                   NULL,
                                   TRUE,
                                   NORMAL_PRIORITY_CLASS,
                                   NULL,
                                   NULL,
                                   &si,
                                   &pi
                               );

   while   (   WAIT_OBJECT_0   !=  MsgWaitForMultipleObjects   (   1,
                                                                   &pi.hProcess,
                                                                   FALSE,
                                                                   INFINITE,
                                                                   QS_ALLINPUT
                                                               )
           )
           {
               while   (   PeekMessage (   &msg,   NULL,   0,  0,  PM_REMOVE))
                       {
                           DispatchMessage     (   &msg);
                       }
           }

   GetExitCodeProcess  (   pi.hProcess,    &dwCode);
   CloseHandle (   pi.hProcess);
   CloseHandle (   pi.hThread);

-MAHESH
0
 
AndyAinscowFreelance programmer / ConsultantCommented:
Is this the normal appearance of a dialog when the focus switches to another app?

Try starting eg. notepad whilst your dialog is visible normally (not in this function call)
0
 
jkrCommented:
0
Cloud Class® Course: Microsoft Office 2010

This course will introduce you to the interfaces and features of Microsoft Office 2010 Word, Excel, PowerPoint, Outlook, and Access. You will learn about the features that are shared between all products in the Office suite, as well as the new features that are product specific.

 
AndyAinscowFreelance programmer / ConsultantCommented:
jkr - Is that the correct link?
0
 
jkrCommented:
Takes me to the "Search Results" page.
0
 
AndyAinscowFreelance programmer / ConsultantCommented:
me as well.
0
 
stevaAuthor Commented:
The CreateProcess code works ok.  The problem seems to be with my

                      WaitForSingleObject(ShellExecuteInfo.hProcess, INFINITE);      // infinite timeout

If I have CreateProcess wait this way, I see the white dialog box again. And if I change my ShellExecute to wait with
0
 
stevaAuthor Commented:
I hit a tab by mistake and posted a partial comment above.  Here's what I meant to say:

The CreateProcess code works ok.  The problem of my calling dialog going white  seems to be with my

                      WaitForSingleObject(ShellExecuteInfo.hProcess, INFINITE);    

after the calling code.   If I have your  CreateProcess wait this way, I see the white dialog box again until the called process exits.   And if I change my ShellExecute to wait with

            do {
                   GetExitCodeProcess(si.hProcess, &ExitCode);
             }
             while(ExitCode == STILL_ACTIVE);

instead of WaitForSingleObject it works: I see the normal dialog box again while the called program runs.  

Does that give us any clues about what's going on?

By the way, Andy, white is not the normal state of calling dialog when I switch focus by starting something like notepad.  The dialog box stays colored and completely drawn.

Thanks for your help.
steva

0
 
AndyAinscowFreelance programmer / ConsultantCommented:
Are you performing some drawing of the non-client (border) yourself in the dialog?
Have you customised the message routing in the dialog ?
0
 
stevaAuthor Commented:
No to both questions.  

It seems that what's  happening is that the dialog can't redraw itself when the application is in a WaitForSingleObject or WaitForMultipleObjects sleep.  Let me provide a little more detail.

The calling dialog box gets overlaid by the window of the called program, which is a browser displaying an order form.  When the form is submitted and accepted, a smaller "accepted" window replaces it which contains a license value.  This smaller windows has xy coordinates and a size that allows it and the original calling dialog to be seen simultaneously on the screen.  The user is then supposed to copy the license value in the accepted window and paste it into a field of the calling program's dialog in order to license the application permanently.  My problem is that the calling dialog is white when the maxed order form windows closes so the user can't paste the license value into it.  

As I was saying at the top of this, it seems that when the calling dialog is in a simple
WaitForSingleObject or WaitForMultipleObjects sleep it doesn't receive the messages to repaint itself when the maxed order form window closes and reveals the area where the calling dialog sits.  

If I omit the

 while   (   PeekMessage (   &msg,   NULL,   0,  0,  PM_REMOVE))
                       {
                           DispatchMessage     (   &msg);
                       }
           }
from the CreateProcess code above I get the same white hole where my dialog should be when the orderform window closes.  

So maybe we've solved it. I'll just add the Peek/Dispatch code.   If you guys don't have anything more to add I'll wrap this up and split the points with you for having this conversation with me that led to a solution.
0
 
stevaAuthor Commented:
Ah!  I see the CreateProcess code above uses MsgWaitForMultipleObjects, not WaitForMultipleObjects, and that's the key.  MsgWaitForMultipleObjects will return when "a system event requires the thread's action, such as foreground activation."  That's what I need.
0
 
stevaAuthor Commented:
Oh oh!  While MsgWaitForMultipleObjects let's the user see the calling dialog now, he still can't paste into it until the called program exits.  Is there something to pass along "write" requests while the dialog is waiting?
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.