CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Guest

    Accessing CDocument-member functions

    I´m creating a simple single-document application using the MFC wizard which for demonstration purposes prints various textmessages in the document window. Those can be selected by a few options in the menu-bar. I tried to implement the handler (something like ON_FILE_NEWMSG) for this Menu-option in the main program (in my case, Demo.cpp). However, to access a function (settext(CString)) I defined in the Document class I guess I need to use a pointer to the document to call the function that will change the text line ( something like ptrtodoc->settext("Hello world"); ).
    The problem about this is that I don´t know how to get this pointer. I know that there is a function called CSingledocTemplate that somehow creates and links the mainframe, the view and the document, but this just returns a Pointer to a SingledocTemplate. Besides, I´m not sure if this pointer is global, so it probably wouldn´t be of any use anyway.
    Please help, as this is REALLY beginning to bug me..


  2. #2
    Guest

    Re: Accessing CDocument-member functions

    If you used the AppWizard, you will have a funtion called GetDocument() in your view. To get the pointer to the document just use:

    CMyDocument* pDoc = GetDocument();

    then

    pDoc->MyDocumentFunction();

    to run a funciton in the document object.


  3. #3
    Join Date
    Apr 1999
    Posts
    24

    Re: Accessing CDocument-member functions


    CMyDocument *MyDoc = (CMyDocument *)GetDocument();
    Mydoc->settext("Hello world");



Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured