|
-
August 15th, 2011, 03:49 PM
#16
Re: [MFC MDI] How to activate a view programmatically and safely ?
Sorry, now I can't show you the entire of my code.
But I'll prepare test code as possible.
An exception that occurs when I close documents arbitrary after activate one view. Exception messages are like below
'A deactivating object is not a recently activated object'
-
August 15th, 2011, 03:54 PM
#17
Re: [MFC MDI] How to activate a view programmatically and safely ?
 Originally Posted by lightshield
Sorry, now I can't show you the entire of my code.
But I'll prepare test code as possible.
An exception that occurs when I close documents arbitrary after activate one view. Exception messages are like below
'A deactivating object is not a recently activated object'
Did the call work otherwise?
-
August 15th, 2011, 03:54 PM
#18
Re: [MFC MDI] How to activate a view programmatically and safely ?
An exception message is like below
'A deactivating object is not a recently activated object.'
GCDEF, please show the tail of my first post. thanks
-
August 15th, 2011, 03:58 PM
#19
Re: [MFC MDI] How to activate a view programmatically and safely ?
Sorry for my duplicated post.
What about 'the call' and what means 'work' ?
-
August 15th, 2011, 05:26 PM
#20
Re: [MFC MDI] How to activate a view programmatically and safely ?
I've made the VC solution to repro this problem.
I'll upload files to some server soon.
And I fix my words that the exception occurs when I close 'the application', not a document.
-
August 15th, 2011, 05:55 PM
#21
Re: [MFC MDI] How to activate a view programmatically and safely ?
https://skydrive.live.com/?cid=578e0...8337%21103
An above link is for the repro program and download 'mditest.zip'.
1. build the solution
2. run the mditest.exe and create at least 2 documents.
3. close the application from 'X' button -> exception will be invoked.
Please try it.
-
August 15th, 2011, 09:09 PM
#22
Re: [MFC MDI] How to activate a view programmatically and safely ?
At a quick glance you're switching the view in the child frame instead of activating the correct frame. I'm not sure why you're even doing that. If you comment out the call to ForceActivate the program behaves the same way. Use the MDIActivate function and pass in a pointer to a child frame as I said instead of switching the view in the active frame.
-
August 15th, 2011, 10:56 PM
#23
Re: [MFC MDI] How to activate a view programmatically and safely ?
I'd already tried ways that you said but I couldn't emulate 'click on a tab' behavior.
I've known that above code is incorrect. I just want to know ways for 'click on a tab' behavior.
MDIActivate method does not work this purpose by calling this method simply.
In other words, make the procedure of OnActivateView same as tab-click.
But I found a strange thing that existing documents will be deactivated when the new document created. This may be same behavior as tab-click.
Therefor, I couldn't get same result. fmmm
I got the another way to avoid this problem now. But It's difficult problem to emulate the tab-click behavior.
Last edited by lightshield; August 15th, 2011 at 11:08 PM.
-
August 15th, 2011, 11:15 PM
#24
Re: [MFC MDI] How to activate a view programmatically and safely ?
I've solved this problem by enumerating documents from document templates and proceed desired behavior.
It's a safe way to synchronize between each view.
GCDEF, thank you for this log conversation.
Last edited by lightshield; August 16th, 2011 at 04:21 PM.
-
January 14th, 2015, 11:49 PM
#25
Re: [MFC MDI] How to activate a view programmatically and safely ?
try this code:
POSITION pos = GetMDITabGroups().GetHeadPosition();
while(pos){
const CObject* obj = GetMDITabGroups().GetNext(pos);
CMFCTabCtrl* tab = (CMFCTabCtrl*)obj;
int count = tab->GetWindowedChildCount();
for(int i=0; i<count; i++){
tab->ActivateMDITab(i);
if(openedScenario==GetActiveView()){
break;
}
}
}
-
January 14th, 2015, 11:55 PM
#26
Re: [MFC MDI] How to activate a view programmatically and safely ?
 Originally Posted by wootra
try this code:
POSITION pos = GetMDITabGroups().GetHeadPosition();
while(pos){
const CObject* obj = GetMDITabGroups().GetNext(pos);
CMFCTabCtrl* tab = (CMFCTabCtrl*)obj;
int count = tab->GetWindowedChildCount();
for(int i=0; i<count; i++){
tab->ActivateMDITab(i);
if(openedScenario==GetActiveView()){
break;
}
}
}
the openedScenario is the View you wanted to activate.
you can know what view you want to active in the other way.
I had same problem, but I couldn't find the way to solve this problem. So I leave my solution here.
-
January 15th, 2015, 08:53 AM
#27
Re: [MFC MDI] How to activate a view programmatically and safely ?
An MDI application with "tabbed views" can have zero, one or more tab groups.
Here is an example of one having two tab groups.
Tabed-view MDI application having two tab groups.jpg
If you want to programmatically activate a tab item (and its associated view) from a given tab group you have to do the following:
- call CMDIFrameWndEx::GetMDITabGroups to get a list of tab groups (this is a list of CMFCTabCtrl pointers, one for each tab group);
- get the desired tab group from the list;
- call CMFCTabCtrl::ActivateMDITab to activate the desired tab item (and the associated view).
And here is a sample code:
Code:
BOOL CMainFrame::_ActivateTab(INT_PTR nTabGroupIndex, int nTabItemIndex /*= -1*/)
{
BOOL bRet = FALSE;
const CObList& list = GetMDITabGroups();
POSITION pos = list.FindIndex(nTabGroupIndex);
if(NULL != pos)
{
const CObject* pTabGroup = list.GetAt(pos);
VERIFY(pTabGroup->IsKindOf(RUNTIME_CLASS(CMFCTabCtrl)));
if(NULL != pTabGroup)
{
CMFCTabCtrl* pTabCtrl = (CMFCTabCtrl*)pTabGroup;
if(pTabCtrl->GetTabsNum() > nTabItemIndex)
{
pTabCtrl->ActivateMDITab(nTabItemIndex);
bRet = TRUE;
}
}
}
return bRet;
}
Code:
void CMainFrame::OnSomeCommand()
{
// just for demo purpose
// activate the third tabbed view from the first tab group
VERIFY(_ActivateTab(0, 2));
}
Last edited by ovidiucucu; January 15th, 2015 at 08:57 AM.
Reason: typo
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
|