PRB: GetActiveView Returns NULL for an MDI Frame Window (129649)
The information in this article applies to:
- The Microsoft Foundation Classes (MFC), when used with:
- Microsoft Visual C++ 1.51
- Microsoft Visual C++ 1.52
- Microsoft Visual C++, 32-bit Learning Edition 4.0
- Microsoft Visual C++, 32-bit Professional Edition 2.0
- Microsoft Visual C++, 32-bit Professional Edition 2.1
- Microsoft Visual C++, 32-bit Professional Edition 4.0
This article was previously published under Q129649 SYMPTOMS
The GetActiveView() function returns the active view (if any) attached
to a frame window (CFrameWnd). This function returns NULL when called
for an MDI main frame window (CMDIFrameWnd).
CAUSE
In an MDI application, the MDI main frame window (CMDIFrameWnd) does not
have a view associated with it. Instead, each individual child window
(CMDIChildWnd) has one or more views associated with it. Therefore, a call
to the GetActiveView() function for an MDI main frame window returns NULL.
The "More Information" section of this article gives the layout of the
different windows in an MDI application.
RESOLUTION
To resolve the problem, find the active MDI child window (if any), and then
call the GetActiveView() function for that child window. The active MDI
child window can be found by calling the MDIGetActive() or GetActiveFrame()
function, as demonstrated in this code:
CMDIFrameWnd *pFrame = (CMDIFrameWnd *)AfxGetApp()->m_pMainWnd;
// Get the active MDI child window.
CMDIChildWnd *pChild =
(CMDIChildWnd *) pFrame->GetActiveFrame();
/* or CMDIChildWnd *pChild =
pFrame->MDIGetActive();
*/
// Get the active view attached to the active MDI child window.
CMyView *pView = (CMyView *) pChild->GetActiveView();
REFERENCES
"Programming Windows 3.1," Charles Petzold, Microsoft Press, 1992.
Modification Type: | Major | Last Reviewed: | 12/9/2003 |
---|
Keywords: | kbcode kbDocView kbMDI kbprb KbUIDesign KB129649 |
---|
|