Get the CChildFrame from CDocument or CView

Posted on 2002-04-15
Last Modified: 2013-11-20
For example my classes are CDifarDocument/CDifarView subclass of CDocument/CView . How to get the CChildFrame from CDifarDocument or CDifarView ?

My purpose is to get the system menu of the child window to enable/disable buttons, I can get the system menu from CChildFrame, but cannot get from other objects.

From CDifarDocument I get the CDifarView, and from CDifarView get the system menu:

CMenu *pSysMenu = pView->GetSystemMenu(FALSE);
ASSERT(pSysMenu != NULL);

but it fail at the ASSERT
Question by:ahTri
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2

Expert Comment

ID: 6943833
Call the GetParent() function of the view and cast it to CCHildFrame.For your purpose replace the line
CMenu *pSysMenu = pView->GetSystemMenu(FALSE);
CMenu *pSysMenu = GetParent()->GetSystemMenu(FALSE);


Author Comment

ID: 6943896
Cool it's work, how about the main window ? what function to get the main window ?
LVL 23

Expert Comment

by:Roshan Davis
ID: 6943900
For getting main window

CMainFrame *pFrame = (CMainFrame *)AfxGetMainWnd();


Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!


Author Comment

ID: 6943913
I already try this before it bring up the exception in afxwin2.inl line 62

_AFXWIN_INLINE CMenu* CWnd::GetSystemMenu(BOOL bRevert) const
  ASSERT(::IsWindow(m_hWnd)); return
  CMenu::FromHandle(::GetSystemMenu(m_hWnd, bRevert));

Author Comment

ID: 6943918
I know this is strange, I had another MDI window which work happily with this command

Accepted Solution

manojbkumar earned 50 total points
ID: 6943984
>>what function to get the main window ?


Author Comment

ID: 6944102
Geeze actually I have this in my code
     CFrameWnd *pFrame = pView->GetTopLevelFrame();
     MainSysMenu = pFrame->GetSystemMenu(FALSE);

and it ok the first run to disable the menu, after done and ready to enable menu it bring up the assert error again:

_AFXWIN_INLINE CMenu* CWnd::GetSystemMenu(BOOL bRevert) const
     { ASSERT(::IsWindow(m_hWnd)); return CMenu::FromHandle(::GetSystemMenu(m_hWnd, bRevert)); }

still line 62 of afxwin2.inl

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
repeatEnd java challenge 42 85
Expand macro to ask for filename column 8 37
Window placement 17 95
fix34  challenge 9 165
In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
In an interesting question ( here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

756 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question