Solved

Get the CChildFrame from CDocument or CView

Posted on 2002-04-15
7
1,170 Views
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
0
Comment
Question by:ahTri
  • 4
  • 2
7 Comments
 
LVL 2

Expert Comment

by:manojbkumar
ID: 6943833
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
 

Author Comment

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

Expert Comment

by:Roshan Davis
ID: 6943900
For getting main window

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

GOOD LUCK

0
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 

Author Comment

by:ahTri
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));
}
0
 

Author Comment

by:ahTri
ID: 6943918
I know this is strange, I had another MDI window which work happily with this command
0
 
LVL 2

Accepted Solution

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

pView->GetTopLevelFrame();
0
 

Author Comment

by:ahTri
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
0

Featured Post

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Get filename and folder into excel 7 74
has77  challenge 9 83
zeroFront challenge 7 98
withoutTen challenge 14 121
Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
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.

770 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