Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

CDocument Pointers

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
Hello

I have created an application using the doc/view architecture in vc++ 5. The problem I have is that I need to access attributes in the DOC class from a dialog. I have no problems creating a pointer to the doc class from view classes, but I cannot get it to work with dialog classes. Can someone please shed some light on this?

Thank you
 
> but I cannot get it to work with dialog classes

That should work. If you show some of the code that is not working for you we might be able to help.

-pete
 
Here's how I do it:

CIPDebugTestDoc* CIPDebugTestApp::GetActiveDoc(){
CIPDebugTestDoc *pDocCMDIChildWnd
*pMDIChildWnd = pMainFrame->MDIGetActive(NULL);

if(pMDIChildWnd != NULL){
pDoc = (CIPDebugTestDoc*)pMDIChildWnd->GetActiveDocument();
}
TRACE0("Got MDI\n");
if(pDoc != NULL)
return pDoc;
return NULL;
}

This goes in my MFC generated "NameOfProject.cpp" file. Says "Defines the class behaviors for the application" at the top.

In this case CIPDebugTestApp is the main app class, CIPDebugTestDoc is the doc class, pMainFrame is used in the InitInstance()function. You'll need to make pMainFrame global.

This member function will return a Doc pointer if there is one or null if there is not one.

In the dialog InitInstance do this:

CIPDebugTestApp* pApp = (CIPDebugTestApp*)AfxGetApp();
CIPDebugTestDoc* pDoc = pApp->GetActiveDoc();
if(pDoc != NULL){
TRACE0("Found Doc pointer");
}
else{
TRACE0("No doc pointer");
}

The above gets a pointer to the main app class and calls the GetActiveDoc() member funtion you created above. There may be a better way to get a doc pointer into the dailog but this works fine for me. May take some time for it to sink in :)

Brother C
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top