Q: In my application's main dialog, I've created a top-level modeless dialog as follows:
Code:// MainDialog.h #include "FloatingDialog.h" // ... class CMainDialog : public CDialog { CFloatingDialog m_dlg; // ... };Although SetWindowPos has been called in order to place the new dialog behind the main dialog, it's still shown on top.Code:// MainDialog.cpp // ... void CMainDialog::OnButtonShowDialog() { // create modeless dialog if not already created if(NULL == m_dlg.m_hWnd) m_dlg.Create(IDD_FLOATING_DIALOG); // asure it's top-level (WS_CHILD style is not set) ASSERT(!(m_dlg.GetStyle() & WS_CHILD)); // place it behind this window m_dlg.SetWindowPos(this, 0, 0, 0, 0, SWP_NOMOVE|SWP_NOSIZE); // make it visible m_dlg.ShowWindow(SW_SHOW); }
Also, a user action like clicking in the main dialog does not change this.
What can be done to overcome this issue?
A: If call CDialog::Create ignoring the second parameter, which is default NULL, the main application's window becomes its owner. Every ovned window stays always on top of its owner and there is no chance to move it behind.
To create a top-level modeless dialog that can stay behind application main window, pass a pointer to desktop window in second parameter of CDialog::Create:
Resources [MSDN]Code:void CMainDialog::OnButtonShowDialog() { // create modeless dialog if not already created if(NULL == m_dlg.m_hWnd) m_dlg.Create(IDD_FLOATING_DIALOG, CWnd::GetDesktopWindow()); //...
See also [Codeguru FAQ]


Ovidiu Cucu
Reply With Quote

Bookmarks