-
February 27th, 2014, 04:05 PM
#1
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.
-
February 27th, 2014, 04:15 PM
#2
Re: Getting to the active document
-
February 27th, 2014, 04:23 PM
#3
Re: Getting to the active document
Victor Nijegorodov
-
February 27th, 2014, 04:37 PM
#4
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));
-
February 27th, 2014, 06:41 PM
#5
Re: Getting to the active document
Originally Posted by Gregorina
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.
-
February 27th, 2014, 07:06 PM
#6
Re: Getting to the active document
Originally Posted by GCDEF
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?
-
February 27th, 2014, 07:39 PM
#7
Re: Getting to the active document
Originally Posted by Gregorina
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
-
February 28th, 2014, 07:19 PM
#8
Re: Getting to the active document
Originally Posted by GCDEF
Yes that works. Thank you very much.
-
March 1st, 2014, 12:10 AM
#9
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|