0

I've got a situation. There is a huge app (C++ MFC). I write a .dll module with a dockable pane.

Pane interface structure:

 Pane -> CMFCToolBar  
      -> CSplitterWndEx -> CListCtrl 
                        -> CDialogEx

That's how i create my DialogEx:

int CMyPane::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
    ///////////////////////////////////////////
    ////////// TAB CTRL ///////////////////////
    ///////////////////////////////////////////

    const int dwResTabCtrlStyle = WS_CHILD | WS_VISIBLE | TCS_VERTICAL;// | LVS_SINGLESEL;  
    
    if(!m_SptitterWndEx.AddTabCtrl(0, 1, &m_tabCtrl, CMFCTabCtrl::STYLE_3D, CMFCBaseTabCtrl::LOCATION_TOP, CSize(10,10)))
        return -1;

    {
        AFX_MANAGE_STATE(AfxGetStaticModuleState());
        
        m_DialogEx.Create(CAccuracyResultPage::IDD, NULL);
    }

    m_DialogEx.SetParent(&m_tabCtrl);
    if(!m_DialogEx.GetParent())
        return -1;

    str.LoadString( AfxGetStaticModuleState()->m_hCurrentResourceHandle, IDS_RESULT_TAB);
    m_tabCtrl.AddTab(&m_DialogEx, str, 0);  

    AdjustLayout();

    return 0;
}

I getting assert on CDialogEx::PreTranslateMessage. The reason is the when it gets it's parents

_AFXWIN_INLINE CWnd* CWnd::GetParent() const
    { ASSERT(::IsWindow(m_hWnd)); return CWnd::FromHandle(::GetParent(m_hWnd)); }

m_hWnd is not a Wnd. But the CDialog looks perfectly OK, it has m_pParentWnd, but it's not m_tabCtrl.

So my questions are: Why doesn't CDialogEx set its parent?! And how it can be dealed with?!

Community
  • 1
  • 1
Alexandr Crit
  • 111
  • 1
  • 14
  • Are you asking about the parent (unlikely), or the owner? Those are different relationships. See [Child Windows](https://msdn.microsoft.com/en-us/library/windows/desktop/ms632599.aspx#child) and [Owned Windows](https://msdn.microsoft.com/en-us/library/windows/desktop/ms632599.aspx#owned_windows). – IInspectable Sep 14 '15 at 16:08
  • I want to "divide the client area of a parent window into functional areas". In fact, into one funcional area. Dialog as a TabPage. – Alexandr Crit Sep 16 '15 at 15:01

1 Answers1

0

Where is your dialog template residing? Is it in the same dll? If not, then i think that's your problem.

My guess is, if your dialog template resides in a different dll then windows might search in the HWND=>CWnd map of the module state of that dll. If that happens then it wont be able to find the CWnd in the map and will create a temporary CWnd object and set it as the parent of the dialog.

Rasheduzzaman Sourov
  • 1,375
  • 2
  • 15
  • 36