Click here to Skip to main content
15,881,516 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi In an MDI program written in C++, I've this problem. When a new document is creating, it's view is shown repeatedly with different sized until it gets its final size. I put TRACE in OnSize of the corresponding child frame and got the following values:

300x525
300x525
316x563
0x0
560x788
561x789
560x788

This is a weird behavior! I expect only one OnSize be called when the size finally determined and calculated based on tools controls, toolbars, etc. The other behavior which is not justifiable for me is that when a new tabbed document is created, OnMDIActivate is called more than two times. MSDN says that it's called twice, once for the document which is losing activation and once for the document which is gaining activation. But I see that once the new document is activated, then it loses activation and again the older document is activated and again the new one is activated and the old one loses activation! Why is that and how can i avoid it?
thx

PS. I'm going to include the child frame code:
C++
// ChildFrm.cpp : implementation of the CChildFrame class
//

#include "stdafx.h"

#define Uses_CChildFrame
#define Uses_Ct2View
#define Uses_AcItemPropertyPane
#include "hdrs.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#endif

// CChildFrame

IMPLEMENT_DYNCREATE(CChildFrame, CMDIChildWndEx)

BEGIN_MESSAGE_MAP(CChildFrame, CMDIChildWndEx)
	ON_WM_MDIACTIVATE()
	ON_WM_CHILDACTIVATE()
END_MESSAGE_MAP()

// CChildFrame construction/destruction

CChildFrame::CChildFrame()
{
	d_ActivateFrameWasCalled = false;
}

CChildFrame::~CChildFrame()
{
}

// CChildFrame diagnostics

#ifdef _DEBUG
void CChildFrame::AssertValid() const
{
	CMDIChildWndEx::AssertValid();
}

void CChildFrame::Dump(CDumpContext& dc) const
{
	CMDIChildWndEx::Dump(dc);
}
#endif //_DEBUG

// CChildFrame message handlers

void CChildFrame::OnMDIActivate(BOOL bActivate, CWnd* pActivateWnd, CWnd* pDeactivateWnd)
{
	//TRACE("%d\t%p\t%s\n", ++_counter, this, __FUNCTION__);
	CMDIChildWndEx::OnMDIActivate(bActivate, pActivateWnd, pDeactivateWnd);
	if (!pActivateWnd)  // bActivate is also FALSE
		AcGlobals::wndItemPropertyPane->load(NULL);
}

void CChildFrame::ActivateFrame(int nCmdShow)
{
	//TRACE("%d\t%p\t%s\n", ++_counter, this, __FUNCTION__);
	__super::ActivateFrame(nCmdShow);
	d_ActivateFrameWasCalled = true;
}

void CChildFrame::OnChildActivate()
{
	CMDIChildWndEx::OnChildActivate();
	if (d_ActivateFrameWasCalled)
	{
		CView *pView = GetActiveView();
		ASSERT_KINDOF(Ct2View, pView);
		Ct2View *pt2View = (Ct2View *)pView;
		pt2View->updateItemProperty();
	}
}
Posted
Updated 6-Jun-14 12:36pm
v2
Comments
phil.o 6-Jun-14 16:39pm    
Please show the code that is leading to the behaviour you are describing. Use the "Improve Question" button to post the code in your question itself, not in reply to my comment, please :)
ilostmyid2 6-Jun-14 18:37pm    
ok. thank you for your reply.
although it's not a special code and indeed my code didn't cause the problem and the MFC itself seems to cause the flicker, i updated the question to include to code too.
Sergey Alexandrovich Kryukov 6-Jun-14 18:44pm    
By not using MDI... not only you are torturing yourself, but giving horrific user experience. Who needs this trash, ever?
—SA
ilostmyid2 6-Jun-14 19:41pm    
so you suggest to remove the question itself instead of finding a good answer to it?!
Sergey Alexandrovich Kryukov 6-Jun-14 21:51pm    
Not "instead". It makes no sense to find a better answer. Remove the question or not — does not matter. Not using MDI is really already the best answer. It will save you from a lot of wasted time and frustration.
—SA

1 solution

Here is the idea: who needs MDI, ever? Why torturing yourself and scaring off your users?
Do yourself a great favor: do not use MDI at all. You can do much easier to implement design without it, with much better quality. MDI is highly discouraged even by Microsoft, in fact, Microsoft dropped it out of WPF and will hardly support it. More importantly, you will scare off all your users if you use MDI. Just don't. Please see:
http://en.wikipedia.org/wiki/Multiple_document_interface#Disadvantages[^],
How to Create MDI Parent Window in WPF?[^].

I can explain what to do instead. Please see my past answers:
How to Create MDI Parent Window in WPF? [Solution 2],
Question on using MDI windows in WPF[^],
MDIContainer giving error[^],
How to set child forms maximized, last childform minimized[^].

—SA
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900