930317 - 如何避免闪烁mdi父背景? [英] 930317 - How to avoid flashing mdi parent background?

查看:123
本文介绍了930317 - 如何避免闪烁mdi父背景?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

hi
在用C ++编写的MDI程序中,我遇到了这个问题。创建新文档时,它的视图会以不同的大小重复显示,直到达到最终大小。我将TRACE放在相应子框架的OnSize中并得到以下值:



300x525

300x525

316x563

0x0

560x788

561x789

560x788



这是一种奇怪的行为!我希望在最终根据工具控件,工具栏等确定和计算大小时,只调用一个OnSize。对我来说不合理的其他行为是,当创建新的选项卡式文档时,OnMDIActivate被调用两次以上。 MSDN说它被调用了两次,一次是针对正在失去激活的文档,一次是针对正在获得激活的文档。但是我看到,一旦新文档被激活,它就会失去激活,并且再次激活旧文档并再次激活新文档并且旧文档失去激活!为什么这样,我怎么能避免呢?

thx



PS。我将要包含子框架代码:

  //   ChildFrm.cpp:CChildFrame类的实现 
//

#include < span class =code-string> 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构建/销毁

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

CChildFrame :: ~CChildFrame()
{
}

// CChildFrame诊断

#ifdef _DEBUG
< span class =code-keyword> void CChildFrame :: AssertValid() const
{
CMDIChildWndEx :: AssertValid() ;
}

void CChildFrame ::转储(CDumpContext& dc) const
{
CMDIChildWndEx :: Dump(dc);
}
#endif // _ DEBUG

// CChildFrame消息处理程序

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也是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();
}
}

解决方案

这是一个想法:谁需要MDI?为什么要折磨自己并吓跑你的用户?

帮自己一个大忙:根本不要使用MDI。没有它,您可以更轻松地实现设计,质量更好。 MDI甚至被微软高度劝阻,事实上,微软将其从WPF中删除并且很难支持它。更重要的是,如果您使用MDI,您将吓跑所有用户。只是不要。请参阅:

http://en.wikipedia.org/wiki/Multiple_document_interface#Disadvantages [ ^ ],

如何在WPF中创建MDI父窗口? [ ^ ]。



我可以解释做什么。请看我过去的答案:

如何在WPF中创建MDI父窗口? [解决方案2 ],

关于在WPF中使用MDI窗口的问题 [ ^ ],

麦当劳给出错误 [ ^ ],

如何设置子窗体最大化,最后一个子窗体最小化 [ ^ ]。



-SA

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:

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

解决方案

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


这篇关于930317 - 如何避免闪烁mdi父背景?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆