chpicker
Programmer
- Apr 10, 2001
- 1,316
For some reason I can't get this function to work.
I'm following a tutorial in a book I bought from Sam's Publishing. I created an MDI application using the MFC AppWizard. In the Main Frame class I am supposed to put in a message handler for a toolbar action. The handler needs to call a function in my document class. To do this, I need to obtain a pointer to the document. The GetActiveDocument() function is supposed to do this. However, when I run my program it always returns NULL. Here's the code snippet:
[tt]
CDocument* pDoc=GetActiveDocument();
if (pDoc)
MessageBox("Obtained pointer"
else
MessageBox("Failed to obtain pointer"
[/tt]
I've tried opening several windows so there are plenty of documents to choose from. I switch between all the windows and try the toolbar action from each in turn. Every time, I get my failure message box on the screen.
Any suggestions?
I'm following a tutorial in a book I bought from Sam's Publishing. I created an MDI application using the MFC AppWizard. In the Main Frame class I am supposed to put in a message handler for a toolbar action. The handler needs to call a function in my document class. To do this, I need to obtain a pointer to the document. The GetActiveDocument() function is supposed to do this. However, when I run my program it always returns NULL. Here's the code snippet:
[tt]
CDocument* pDoc=GetActiveDocument();
if (pDoc)
MessageBox("Obtained pointer"
else
MessageBox("Failed to obtain pointer"
[/tt]
I've tried opening several windows so there are plenty of documents to choose from. I switch between all the windows and try the toolbar action from each in turn. Every time, I get my failure message box on the screen.
Any suggestions?