views:

561

answers:

1

I am using MFC to write a GUI application. I chose dialog-based application, and put picture control, edit box and buttons on it. When the picture control is mapped to the class derived from CWnd using DDX_Control, all the message boxes (including default system message box pop up when you enter invalid input in the edit box) are hidden behind main dialog until you use "alt + tab" to bring them to front. If I map the picture control to the default CStatic class, the above problem disappeared. Do anyone has some hints to solve this problem? Thank you in advance for any help.

A: 

Try calling

SetWindowPos( &CWnd::wndNoTopMost, 0, 0, 0, 0 SWP_NOMOVE | SWP_NOSIZE );

on the dialog window. MessageBox's will be created as a "top most" window and that should move the dialog window to behind any of these "top most" windows.

Goz
Thanks for your reply. Here is the code in the dialog class by following you instructions:CWnd* pWnd = CWnd::FromHandle(HWND_NOTOPMOST); SetWindowPos( pWnd, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE );AfxMessageBox(msg, MB_OK | MB_ICONEXCLAMATION | MB_SETFOREGROUND | MB_TOPMOST | MB_TASKMODAL);The message box is still hidden before the dialog windows. Did I do something wrong here? Any help is appreciated.
Cougar_usa
Im not sure if what you are doing, ebcause of my error, will work in. I have edited my original post. It still may not work but worth a shot :)
Goz
unfortunately, it is still not working:)
Cougar_usa
So what happens if you just call MessaageBox instead of AfxMessageBox? (ie CWnd::MessageBox). That way it should be a child of your dialog ...
Goz
the problem still existed if I used ::MessageBox(this->GetSafeHwnd(), msg, "Application", MB_OK | MB_ICONEXCLAMATION | MB_SETFOREGROUND | MB_TOPMOST | MB_TASKMODAL);
Cougar_usa
Then im sorry but im at a loss. Im off to bed so if i think of anything tomorrow morning ill suggest it :)
Goz
I think the key is what happen when the control in the dialog is mapped to the class deriving from CWnd. I searched in the google, but didn't find any helpful info:( Anyway, thank you very much for your help.
Cougar_usa
The problem is solved. I forget to invoke CWnd:OnPaint() in the OnPaint() of the CWnd derived class.
Cougar_usa