CDockablePane in CMDIChildWndEx
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6

Thread: CDockablePane in CMDIChildWndEx

  1. #1
    Join Date
    Jan 2009
    Posts
    192

    CDockablePane in CMDIChildWndEx

    I have an MDI app, built in VS2008. On some childframes, I have inserted some CDockablePane. But I have a probem: <b>They don't know to save their state and position</b>. The CDockablePane's ones that is part of CMainFrame know how to save their state and position without any written code, through CDockingManager class ...

    But this is not the case, when CDockablePane is part of CChildFrame ...

    I have tried this: https://stackoverflow.com/questions/...49341#39449341

    not worked.

    I have tried this:
    Code:
    int CChildFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
    {
    ..........
    	CDockState state;
    	state.LoadState(_T("MyDockPane"));
    	SetDockState(state);
    
    	return 0;
    }
    and
    Code:
    void CChildFrame::OnDestroy()
    {
    	CDockState state;
    	GetDockState(state);
    	state.SaveState(_T("MyDockPane"));
    
    	CMDIChildWndEx::OnDestroy();
    }
    I also tried this:
    Code:
    int CChildFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
    {
    	if (CMDIChildWndEx::OnCreate(lpCreateStruct) == -1)
    		return -1;
    
    	// enable Visual Studio 2005 style docking window behavior
    	CDockingManager::SetDockingMode(DT_SMART);
    	// enable Visual Studio 2005 style docking window auto-hide behavior
    	EnableAutoHidePanes(CBRS_ALIGN_ANY);
    
    	CMDIChildWndEx::m_bEnableFloatingBars = TRUE;
    
    	// Create properties window
    	CString strPropertiesWnd;
    	BOOL bNameValid = strPropertiesWnd.LoadString(IDS_PROPERTIES_WND);
    	ASSERT(bNameValid);
    	if(! m_wndProperties.Create(strPropertiesWnd, this, CRect(0, 0, 200, 200), TRUE, ID_VIEW_PROPERTIESWND, WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS | WS_CLIPCHILDREN | CBRS_LEFT | CBRS_FLOAT_MULTI))
    	{
    		TRACE(_T("Failed to create Properties window\n"));
    		return FALSE; // failed to create
    	}
    	if(! m_wndFilter.Create(_T("Filter"), this, CRect(0, 0, 200, 200), TRUE, 0, WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS | WS_CLIPCHILDREN | CBRS_LEFT | CBRS_FLOAT_MULTI))
    	{
    		TRACE(_T("Failed to create Properties window\n"));
    		return FALSE; // failed to create
    	}
    
    	SetDockingWindowIcons(theApp.m_bHiColorIcons);
    
    	AddPane(&m_wndFilter);
    	AddPane(&m_wndProperties);
    	m_wndFilter.EnableDocking(CBRS_ALIGN_ANY);
    	m_wndProperties.EnableDocking(CBRS_ALIGN_ANY);
    	DockPane(&m_wndFilter);
    	CDockablePane* pTabbedBar = NULL;
    	m_wndProperties.AttachToTabWnd(&m_wndFilter, DM_SHOW, TRUE, &pTabbedBar);
    	EnableAutoHidePanes(CBRS_ALIGN_ANY);
    
    	m_dockManager.LoadState(theApp.GetRegSectionPath(_T("ChildFrame")));
    	m_dockManager.SetDockState();
    
    	return 0;
    }
    and
    Code:
    void CChildFrame::OnDestroy()
    {
    	if(! m_wndProperties.IsFloating() && 
    		! m_wndFilter.IsFloating())
    	m_dockManager.SaveState(theApp.GetRegSectionPath(_T("ChildFrame")));
    
    	CMDIChildWndEx::OnDestroy();
    }
    but sometimes I get memory leaks:
    Code:
    Detected memory leaks!
    Dumping objects ->
    f:\dd\vctools\vc7libs\ship\atlmfc\src\mfc\afxpanecontainer.cpp(2382) : {27179} client block at 0x0267BEC8, subtype c0, 156 bytes long.
    a CPaneContainer object at $0267BEC8, 156 bytes long
    Object dump complete.
    The program '[8876] Model.exe: Native' has exited with code 0 (0x0).
    and
    Code:
    DestroyWindow in CWnd::~CWnd; OnDestroy or PostNcDestroy in derived class will not be called.
    is there any solution to save/restore the pane's from child frame ?

    I attach here a sample code that illustrate the problem ...
    Attached Files Attached Files
    Last edited by mesajflaviu; May 30th, 2017 at 01:39 AM.

  2. #2
    Join Date
    Jun 2003
    Location
    Armenia, Yerevan
    Posts
    696

    Re: CDockablePane in CMDIChildWndEx

    It passed a long time since I am not engaged in MFC-related development. However, as from what, I remember, during that timescale, you need to release any resource you have created in your application. For example, if it would the drawing facility like device context, there's a necessity to release it after acquiring its handle. The same technique is applicable here.
    Popular opinion is the greatest lie in the world.

  3. #3
    Join Date
    Jan 2009
    Posts
    192

    Re: CDockablePane in CMDIChildWndEx

    Thank you for your interest. Yes, I would clean any resources, if I would allocate it ... but in this case, I allocate no resources ...
    Last edited by mesajflaviu; May 30th, 2017 at 01:39 AM.

  4. #4
    Join Date
    Jan 2009
    Posts
    192

    Re: CDockablePane in CMDIChildWndEx

    I think I have found the problem: in the creation of m_wndFilter, I didn't put an distinct ID, but 0. Soon as I identified with ID, everything work ok, with the solution:
    Code:
    	m_dockManager.LoadState(theApp.GetRegSectionPath(_T("ChildFrame")));
    	m_dockManager.SetDockState();
    and
    Code:
    m_dockManager.SaveState(theApp.GetRegSectionPath(_T("ChildFrame")));

  5. #5
    Join Date
    Feb 2003
    Location
    Iasi - Romania
    Posts
    8,184

    Re: CDockablePane in CMDIChildWndEx

    Two related remarks:

    1. To easily find the source of memory leaks in MFC, put this code on top of each implementation (.cpp) file:
    Code:
    #ifdef _DEBUG
    #define new DEBUG_NEW
    #endif
    See also: How to detect memory leaks in MFC?

    2. If you find in the output window
    Code:
    Warning: calling DestroyWindow in CWnd::~CWnd; OnDestroy or PostNcDestroy in derived class will not be called.
    or
    Code:
    Warning: calling DestroyWindow in CDialog::~CDialog -- OnDestroy or PostNcDestroy in derived class will not be called.
    means that an object of CWnd-derived or CDialog-derived class, is being destroyed without previously destroy the window. As a consequence if you handled WM_DESTROY message or overrode PostNcDestroy, they will never called.
    One solution to get rid this issue by calling DestroyWindow in the derived class destructor (of course if the window is not yet destroyed).
    Ovidiu
    "When in Rome, do as Romans do."
    My latest articles: http://codexpert.ro/blog/author/ovidiu-cucu/

  6. #6
    Join Date
    Jan 2009
    Posts
    192

    Re: CDockablePane in CMDIChildWndEx

    Ovidiu, thank you for your observations.

    The funny thing here is that I get rid of these ML and warnings, solving the problem: when I create the pane, I give him a real ID, not 0 ... I am thinking that inside of MFC code is searching for the pane ID, and as long as it didn't found this ID, the resources were not freed ... I guess.
    Last edited by mesajflaviu; June 2nd, 2017 at 07:09 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This a Codeguru.com survey!


On-Demand Webinars (sponsored)