SetActiveView
William F. Cook -- wfcook@ix.netcom.com
Tuesday, September 17, 1996
Environment: VC++4.1, Win95
I've got a situation where I need to be able to activate a particular view
in an MDI application, just as if the user had done it himself from the
window menu. This seems pretty simple - this is what I did:
AfxGetMainWnd()->SetActiveView(pView);
That didn't work (nothing happened), and the app crashed when it was closed
in a state where there's no source code and where the call stack leads to
no place I can recognized. I'm positive that pView points to the view in
question and not into outer space somewhere. Looking through MSDN and the
MFC source code I can see nothing wrong with what I've done. I'm sure it's
something simple but I've now spent an entire day on this little problem
and need help.
Any ideas out there?
Thanx,
Bill Cook
Guy -- GUY@sparky.kyle.cri.nz
Friday, September 20, 1996
[Mini-digest: 9 responses]
Bill,
I've just done the same. First I had to activate the frame that
contains the view
In the App after I opened the Doc I "saved" pChildFlow to be used in the View
CMDIFrameWnd *pFrame3 = (CMDIFrameWnd *)AfxGetApp()->m_pMainWnd;
// Get the active MDI child window.
pChildFlow = (CMDIChildWnd *) pFrame3->GetActiveFrame();
then in the View I activate that Frame
// Switch to view containing plot so that the menu is alive
pChildFlow->ActivateFrame();
at which point you can activate a particular View in that Frame (I
only have one view/ document so I don't need to).
// OnActivateView(TRUE,pVw,pView);
Guy
------------------------------------
Guy Halliburton
National Institute of Water & Atmospheric Research
PO Box 8602
Christchurch,New Zealand
ph: 64 3 3437896 fax: 64 3 3437899
email: guy@sparky.kyle.cri.nz
------------------------------------
-----From: Dean Henkel
Try
pview->GetParentFrame()->ActivateFrame();
Dean
-----From: Mike Morel
SetActiveView must be called for the parent frame of the view, not the main frame. Try:
pView->GetParentFrame()->SetActiveView(pView);
Mike Morel
Mushroom Software
Home of MFC For Yourself
http://www.mushroomsoft.com/mushroom
-----From: Roger Onslow/Newcastle/Computer Systems Australia/AU
MDI frame does not have any child views .. it has child frames instead.
You should therefore activate the appropriate chid frame rather than a view
so you cannot use SetActiveView
Roger Onslow
-----From: David.Lowndes@bj.co.uk
Bill,
I think you should be using MDIActivate instead of SetActiveView.
Dave Lowndes
-----From: Joyce Carley
I had the same problem. Once I determine which view I want to activate
I do the following:
pView->GetParentFrame()->ActivateFrame( SW_RESTORE );
-----From: "Dean Wiles"
In an MDI app you need to call MDIActivate() instead of SetActiveView().
There are two versions:
void CMDIChildWnd::MDIActivate();
void CMDIFrameWnd::MDIActivate(CWnd* pWndActivate);
In your case call one of the following, either should work:
pView->GetParentFrame()->MDIActivate();
AfxGetMainWnd()->MDIActivate(pView->GetParentFrame());
--------------------------------------------------------------------------
Dean Wiles (deanw@mail.isc-br.com) Olivetti North America
Phone: (509)927-7037 22425 East Appleway Ave
Fax: (509)927-2499 Liberty Lake, WA 99019-9534
If the Son sets you free, you will be free indeed. (John 8:36)
-----From: Rohit Namjoshi
Try
CFrameWnd* pFrame = pView->GetParentFrame();
if (pFrame)
pFrame->ActivateFrame();
Cheers... Rohit
--
Rohit Namjoshi namjoshi@austin.asc.slb.com
Schlumberger Austin Product Center Vox: +1 512 331 3353
Austin, TX 78726, USA Fax: +1 512 331 3320
-----From: Dave_Rabbers@Quinton-Eng.CCMAIL.CompuServe.COM
You say you are using MDI. But
AfxGetMainWnd()->SetActiveView(pView);
attempts to SetActiveView in the main frame, not the MDI child frame.
Try:
((CMDIFrame*)AfxGetMainWnd())->MDIGetActive()->SetActiveView(pView);
Add appropriate error checking, of course.
| Вернуться в корень Архива
|