|
-
August 13th, 2011, 08:49 PM
#1
[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?
-
August 14th, 2011, 03:00 AM
#2
Re: [MFC MDI] How to activate a view programmatically and safely ?
Maybe you need to do this only when bShow=TRUE.
-
August 14th, 2011, 07:46 AM
#3
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.
-
August 14th, 2011, 07:35 PM
#4
Re: [MFC MDI] How to activate a view programmatically and safely ?
 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?
Cheers, D Drmmr
Please put [code][/code] tags around your code to preserve indentation and make it more readable.
As long as man ascribes to himself what is merely a posibility, he will not work for the attainment of it. - P. D. Ouspensky
-
August 14th, 2011, 08:36 PM
#5
Re: [MFC MDI] How to activate a view programmatically and safely ?
 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.
-
August 15th, 2011, 02:24 AM
#6
Re: [MFC MDI] How to activate a view programmatically and safely ?
-
August 15th, 2011, 07:10 AM
#7
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.
-
August 15th, 2011, 09:50 AM
#8
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.
-
August 15th, 2011, 10:52 AM
#9
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.
-
August 15th, 2011, 11:09 AM
#10
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
-
August 15th, 2011, 11:13 AM
#11
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.
-
August 15th, 2011, 11:16 AM
#12
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.
-
August 15th, 2011, 12:38 PM
#13
Re: [MFC MDI] How to activate a view programmatically and safely ?
 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.
-
August 15th, 2011, 02:18 PM
#14
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.
-
August 15th, 2011, 03:33 PM
#15
Re: [MFC MDI] How to activate a view programmatically and safely ?
 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.
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|