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.
Re: Getting to the active document
Re: Getting to the active document
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));
Re: Getting to the active document
Quote:
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.
Re: Getting to the active document
Quote:
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?
Re: Getting to the active document
Quote:
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
Re: Getting to the active document
Quote:
Originally Posted by
GCDEF
Yes that works. Thank you very much.
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.