Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

controls not displayed in dialog

Status
Not open for further replies.

cisotta

Programmer
Apr 23, 2004
9
0
0
IT
I have included in my application a dialog class that displays a window with a CProgressCtrl control and a Cancel button during a heavy process.

The problem is that the button and any CStatic objects (text...) put on the dialog are not displayed during the data processing, but are displayed only when all processing ends and the parent program returns in idle mode. The only object always visible is the progress control, that is updated regularly with the SetPos() during processing.

I create this window with

prgDialog.Create(IDD_PROGRESS, NULL);
prgDialog.ShowWindow(SW_SHOW);

and destroy it with
prgDialog.DestroyWindow();

Thanks to everybody,
francesco
 
Most likely you are doing the processing in the same thread as your message pump (i.e. a message handler, like the handler for a button press notification). All messages are serialized. So until you return from the message handler, any other messages waiting in the queue will be blocked, including messages crucial to drawing the dialog's controls, such as WM_PAINT.

The reason why the progress control does update is that the SetPos() call actually ends up calling SendMessage() to the progress control's window, sending a message directly to the window without going through the (blocked) message queue.

To solve the problem, do the processing in a worker thread. Have the message handler start a second thread rather than doing the processing directly. When the worker thread is done, have it post another message back to the application. In this second message handler, you can get back the results of the processing, tear down the progress control/dialog, etc.

Even if you are calling another program to do the processing, if you end up waiting for that other program from inside a message handler, it will definitely block any window painting or other messages that go through the message queue.
 
I think I'm already doing the processing in a separate process. Please look at this case: I show a splash screen with an AVI animation, and then create the process that will run an executable. The splash will be destroyed when the separate process is done. -->Anyway the splash dialog is never drawn, just the grey background will be visible.

CSplashDlg splash;
splash.Create(IDD_SPLASH_DIALOG, this);
splash.ShowWindow(SW_SHOW);

PROCESS_INFORMATION ProcessInfo;
STARTUPINFO StartupInfo;
ZeroMemory(&StartupInfo, sizeof(StartupInfo));
StartupInfo.cb = sizeof StartupInfo ;
StartupInfo.dwFlags = STARTF_USESHOWWINDOW;
StartupInfo.wShowWindow = SW_HIDE;
CreateProcess("myheavyprocess.exe", 0, NULL,NULL,FALSE,
0,NULL,NULL,&StartupInfo,&ProcessInfo))

WaitForSingleObject(ProcessInfo.hProcess,INFINITE);
CloseHandle(ProcessInfo.hThread);
CloseHandle(ProcessInfo.hProcess);

Thanks to everybody who can help me.
francesco
 
I believe if you call splash.UpdateWindow() immediately after ShowWindow it will fix the problem.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top