Reputation: 20360
I have a dialog box based application (MFC - VS 2008). I have a list control on it. I pop up other dialog boxes, but I also want to be able to get back to the parent app dialog. I can get back to the parent app dilaog box, but the problem is that even if I click on it with the mouse it remains hidden behind the "child" windows.
I want it to come to the front.
There is probably something obvious I am doing wrong. What do I need to do to make the parent window come to the front when it has focus? I assume there is some property on the child dlg that should not be there, or something missing
I can post the rc code if that helps.
EDIT:
here is the .rc code for the two dialog boxes. The first is the mainframe window.
The second is launched with the following code:
HistogramWindow *histwind;
histwind = new HistogramWindow(this);
histwind->Create(IDD_DIALOG_HISTOGRAM);
histwind->ShowWindow(SW_SHOW);
IDD_DTHISTOGRAMDLG_DIALOG DIALOGEX 0, 0, 320, 200
STYLE DS_SETFONT | DS_FIXEDSYS | WS_MINIMIZEBOX | WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME
EXSTYLE WS_EX_APPWINDOW
CAPTION "dtHistogramDlg"
FONT 8, "MS Shell Dlg", 0, 0, 0x1
BEGIN
DEFPUSHBUTTON "OK",IDOK,209,179,50,14,NOT WS_VISIBLE
PUSHBUTTON "Cancel",IDCANCEL,263,179,50,14,NOT WS_VISIBLE
CONTROL "",IDC_LIST_SYMBOL_SETS,"SysListView32",LVS_ALIGNLEFT | WS_BORDER | WS_TABSTOP,7,7,60,50
END
IDD_DIALOG_HISTOGRAM DIALOGEX 0, 0, 317, 184
STYLE DS_SETFONT | DS_FIXEDSYS | WS_VISIBLE | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME
EXSTYLE WS_EX_APPWINDOW
CAPTION "Histogram"
FONT 8, "MS Shell Dlg", 400, 0, 0x1
BEGIN
DEFPUSHBUTTON "OK",IDOK,205,163,50,14,NOT WS_VISIBLE
PUSHBUTTON "Cancel",IDCANCEL,260,163,50,14,NOT WS_VISIBLE
CONTROL "",IDC_STATIC,"Static",SS_BLACKFRAME,7,7,20,20
END
Upvotes: 3
Views: 3713
Reputation: 11
I had the same problem, but the second Dialog was running inside a CWinThread.
My Solution was:
m_pDlg->Create(IDD_DIALOG, CWnd::FromHandle(GetDesktopWindow()));
I Found further help hrer: http://www.codeproject.com/Articles/1651/Tutorial-Modeless-Dialogs-with-MFC
Upvotes: 1
Reputation: 20360
A friend of mine suggested the following (and it work)
This works, however thereis a strange behavior when i move the parent window from behind a child. While moving the window is hidden until I release the mouse.
This will work for now.
thanks to all who helped.
Upvotes: 1
Reputation: 347196
You are probably using a modal dialog box via calling DoModal
.
Instead, you need to create a modeless dialog box.
To do this, use CWnd::Create and CWnd::ShowWindow.
Example:
CMyDialog *m_pMyDialog = new CMyDialog(this);
m_pMyDialog->Create(CMyDialog::IDD);
m_pMyDialog->ShowWindow(SW_SHOW);
Upvotes: 4