• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1199
  • Last Modified:

Get the CChildFrame from CDocument or CView

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
0
ahTri
Asked:
ahTri
  • 4
  • 2
1 Solution
 
manojbkumarCommented:
ahTri
Call the GetParent() function of the view and cast it to CCHildFrame.For your purpose replace the line
CMenu *pSysMenu = pView->GetSystemMenu(FALSE);
with
CMenu *pSysMenu = GetParent()->GetSystemMenu(FALSE);

GoodLuck
0
 
ahTriAuthor Commented:
Cool it's work, how about the main window ? what function to get the main window ?
0
 
Roshan DavisCommented:
For getting main window

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

GOOD LUCK

0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
ahTriAuthor Commented:
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));
}
0
 
ahTriAuthor Commented:
I know this is strange, I had another MDI window which work happily with this command
0
 
manojbkumarCommented:
>>what function to get the main window ?

pView->GetTopLevelFrame();
0
 
ahTriAuthor Commented:
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
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 4
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now