# CodeGuru Technical FAQs > CodeGuru Individual FAQs >  MFC: How to show modeless dialogs behind the main window?

## ovidiucucu

*Q*: In my application's main dialog, I've created a top-level modeless dialog as follows:


```
// MainDialog.h
#include "FloatingDialog.h"
// ...
class CMainDialog : public CDialog
{
   CFloatingDialog m_dlg;
   // ...
};
```



```
// 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);
}
```

Although _SetWindowPos_ has been called in order to place the new dialog behind the main dialog, it's still shown on top.
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_:


```
void CMainDialog::OnButtonShowDialog() 
{
   // create modeless dialog if not already created
   if(NULL == m_dlg.m_hWnd)
      m_dlg.Create(IDD_FLOATING_DIALOG, CWnd::GetDesktopWindow());
   //...
```

Resources [MSDN]
CDialog::CreateCWnd::SetWindowPosCWnd::GetDesktopWindow

See also [Codeguru FAQ]
What is an owned window?What is a top-level window?

----------

