Getting to the active document
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 9 of 9

Thread: Getting to the active document

  1. #1
    Join Date
    Mar 2011
    Posts
    48

    Getting to the active document

    I have a class with base class CFrameWnd. I need to have access to the activedocument as soon as the dialog box starts without any user input. I've tried accessing it from oncreate functions but because the activedocument isn't created yet, the pointer is to nothing. Are there any functions in the CFrameWnd I can override to have access to the activedocument? I hope this makes sense. This is the first time I've done something like this, any help is appreciated. Thank you so much.

  2. #2
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Posts
    12,067

    Re: Getting to the active document


  3. #3
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Wallisellen (ZH), Switzerland
    Posts
    17,352

    Re: Getting to the active document

    Victor Nijegorodov

  4. #4
    Join Date
    Mar 2011
    Posts
    48

    Re: Getting to the active document

    I can access the document no problem. If the user selects an option, once it's created, I can access it. But I need to have a thread accessing it as soon as it is created. I need to run this thread from CMainFrame as soon as the the document is created:

    Doc* pDoc = static_cast<Doc*>(GetActiveDocument());
    CWinThread* recvThread = AfxBeginThread(&recv, reinterpret_cast<void*>(pDoc));

  5. #5
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Posts
    12,067

    Re: Getting to the active document

    Quote Originally Posted by Gregorina View Post
    I can access the document no problem. If the user selects an option, once it's created, I can access it. But I need to have a thread accessing it as soon as it is created. I need to run this thread from CMainFrame as soon as the the document is created:

    Doc* pDoc = static_cast<Doc*>(GetActiveDocument());
    CWinThread* recvThread = AfxBeginThread(&recv, reinterpret_cast<void*>(pDoc));
    Perhaps your document should call a function in your CMainFrame class and pass a pointer to itself when it's created.

  6. #6
    Join Date
    Mar 2011
    Posts
    48

    Re: Getting to the active document

    Quote Originally Posted by GCDEF View Post
    Perhaps your document should call a function in your CMainFrame class and pass a pointer to itself when it's created.
    In the constructor?

    What about CFrameWnd::ActivateFrame? When I get the activedocument here the pointer is valid, and it's done automatically...seems good. But I feel like this function may be called more than once?

  7. #7
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Posts
    12,067

    Re: Getting to the active document

    Quote Originally Posted by Gregorina View Post
    In the constructor?

    What about CFrameWnd::ActivateFrame? When I get the activedocument here the pointer is valid, and it's done automatically...seems good. But I feel like this function may be called more than once?
    How about InitialUpdateFrame. It even receives a CDocument pointer as an argument.
    http://msdn.microsoft.com/en-us/library/ch3t7308.aspx

  8. #8
    Join Date
    Mar 2011
    Posts
    48

    Re: Getting to the active document

    Quote Originally Posted by GCDEF View Post
    How about InitialUpdateFrame. It even receives a CDocument pointer as an argument.
    http://msdn.microsoft.com/en-us/library/ch3t7308.aspx
    Yes that works. Thank you very much.

  9. #9
    Arjay's Avatar
    Arjay is offline Moderator / MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    11,219

    Re: Getting to the active document

    Keep in mind that you are going to synchronize access to the document if you read or write data to it from another thread.

Posting Permissions

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


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center