[MFC MDI] How to activate a view programmatically and safely ?
I've developing MFC-MDI applications and this application has tabbed document style.
I want to activate each view programmatically and using CMainFrame::SetActiveView method like below.
void CMyView::OnShowWindow( BOOL bShow ... )
{
CView::OnShowWindow( bShow, ... );
CMainFrame *mf = (CMainFrame*)AfxGetMainWnd();
mf->SetActiveView(this);
}
This code makes a view active programatically but has a critical problem that the application pops up the error about the activation of the context when I close a document.
How can I solve this problem?
Re: [MFC MDI] How to activate a view programmatically and safely ?
Maybe you need to do this only when bShow=TRUE.
Re: [MFC MDI] How to activate a view programmatically and safely ?
Sorry I did it, but I'd forgot to write in the avobe code.
Re: [MFC MDI] How to activate a view programmatically and safely ?
Quote:
Originally Posted by
lightshield
I've developing MFC-MDI applications and this application has tabbed document style.
I want to activate each view programmatically and using CMainFrame::SetActiveView method like below.
I don't understand. When do you want to activate a view?
What kind of behavior are you trying to implement?
Re: [MFC MDI] How to activate a view programmatically and safely ?
Quote:
Originally Posted by
lightshield
This code makes a view active programatically but has a critical problem that the application pops up the error about the activation of the context when I close a document.
How can I solve this problem?
Have you tried stepping into the mfc source code and finding out where the error has occurred? Often times, the MFC source code will have comments where the assertion occurs that helps you track down the problem.
Re: [MFC MDI] How to activate a view programmatically and safely ?
Re: [MFC MDI] How to activate a view programmatically and safely ?
You didn't tell us the error and you didn't show all your code. Not much we can do at this point. I'm not really sure why you're doing it from OnShowWindow either.
Re: [MFC MDI] How to activate a view programmatically and safely ?
This tab's problem can be discussed abstractly.
MDI style application has the tabbed document style.
If one tab clicked then associated view will be activated and other views will be deactivated.
I want to implement this behavior programmatically but I've not found solutions yet.
Please give me gurus power.
Re: [MFC MDI] How to activate a view programmatically and safely ?
I think that the MFC has not had obvious method to implement this behavior programmatically because of nothing of requirements for this purpose.
I'd implemented desired behavior by an other agenda. But if programmatic methods for this purpose exists, I want to know these.
So please try to answer this problem. Thanks all.
Re: [MFC MDI] How to activate a view programmatically and safely ?
Did you even look at MSDN? If you had, you probably would have found
CMDIFrameWnd::MDIActivate
Re: [MFC MDI] How to activate a view programmatically and safely ?
Yes, I had
But MDIActivate didn't work with tabbed document style. I had used CMDIFrameWnd::SetActiveView alternatively and this makes the objective view active but an exception occurs when I close arbitrary documents.
Re: [MFC MDI] How to activate a view programmatically and safely ?
I say this situation other words, MDIActivate and SetActiveView functions didn't emulate 'click on a tab' behavior.
Re: [MFC MDI] How to activate a view programmatically and safely ?
Quote:
Originally Posted by
lightshield
I say this situation other words, MDIActivate and SetActiveView functions didn't emulate 'click on a tab' behavior.
Did you pass a view pointer or a MDI child pointer. I believe it wants a CChildFrame pointer rather than a view.
Re: [MFC MDI] How to activate a view programmatically and safely ?
Yes, I did.
I'd tried some way using CView* or CChildFrame* with CMDIFrameWnd::SetActiveView, but I can't solve an exception. But, therefor, this method can activate the desired view.
Re: [MFC MDI] How to activate a view programmatically and safely ?
Quote:
Originally Posted by
lightshield
Yes, I did.
I'd tried some way using CView* or CChildFrame* with CMDIFrameWnd::SetActiveView, but I can't solve an exception. But, therefor, this method can activate the desired view.
I'm having trouble following what you're saying here. What exception?
Can you show the code you tried.