Overriding OpenDocumentFile
I am trying to override OpenDocumentFile. I have created a simple MIDI application with a virtual OpenDocumentFile. I would expect this function to get control when ever I try to open a file, but it never does. I have played with this for several hours...
What am I doing wrong?
virtual CDocument* OpenDocumentFile(LPCTSTR lpszFileName, BOOL bMakeVisible);
CDocument* CtestDoc::OpenDocumentFile(LPCTSTR lpszFileName, BOOL bMakeVisible)
{
CDocument *p = OpenDocumentFile(lpszFileName, bMakeVisible);
return p;
}
attached is the full listing of CtestDoc.h and CtestDoc.cpp
Thanks for all help...
[657 byte] By [
phild] at [2007-11-20 0:26:38]

# 1 Re: Overriding OpenDocumentFile
OpenDocumentFile is a member of CDocTemplate or CWinApp, not CDocument. How are you calling it?
GCDEF at 2007-11-10 23:21:30 >

# 2 Re: Overriding OpenDocumentFile
I am trying to override OpenDocumentFile.Of which base class? AFAIK CDocument doesn't have a OpenDocumentFile method.
CDocument* CtestDoc::OpenDocumentFile(LPCTSTR lpszFileName, BOOL bMakeVisible)
{
CDocument *p = OpenDocumentFile(lpszFileName, bMakeVisible);
return p;
}
will this code call itself over and over again?
- petter
# 3 Re: Overriding OpenDocumentFile
Thanks guys for responding.
Let me try and explain what I am trying to do:
I am trying to serialize my doc data using xml. To do this, I need to intercept the standard process within OpenDocumentFile and call my specialized serialization functions from there.
I guess I can put something like the following in my doc class:
BOOL CTestDoc::OnOpenDocument(LPCTSTR lpszPathName)
{
AfxGetApp()->OpenDocumentFile(lpszPathName);
return true;
}
My hope then is to override the OpenDocumentFile and and from there call my xml serialize functions... At least I think this is the correct flow/process.
Thanks to your responses, since we last communicated I put the follow code in the CWinApp class:
CDocument* CTestApp::OpenDocumentFile(LPCTSTR lpszFileName)
{
CDocument *p = NULL;
return p;
}
from the point of getting control, this now works... (code is not supposed to do anything)
Would you do anything different, or is this the correct process?
phild at 2007-11-10 23:23:34 >

# 4 Re: Overriding OpenDocumentFile
Why not just override Serialize in your document class?
The problem you're facing is that CDocuemt doesn't have an OpenDocuemtFile method, so nothing in the framework will attempt to call it. Perhaps you want to override OnOpenDocument()
GCDEF at 2007-11-10 23:24:40 >

# 5 Re: Overriding OpenDocumentFile
Need additional help, please.
OK, looking at what I did from above, I am now in CTestApp, which is good. From here I need to get a pointer back to my CTEstDoc, so I can call my own serialize function. I have tried several things but have not gotten it to work.
for example in CTestApp::OpenDocumentFile I have tried:
(CXMLTestDoc::GetDoc())->DoMySerialisze(lpszFileName);
and then in CTestDoc:
CXMLTestDoc* CXMLTestDoc::GetDoc(void)
{
return this;
}
this won't compile because it's not static, if I make it static it won't allow a 'this' pointer.
If I could get a pointer to the mainframe, I could call MDIGetActive()?
How can I get a pointer to my CTestDoc class so I can call one of its member functions?
phild at 2007-11-10 23:25:32 >

# 6 Re: Overriding OpenDocumentFile
It's hard to say what you're trying to accomplish there. It seems like you're making it harder than it needs to be. From your description earlier, it seems like you either just need to override Serialize to add you XML stuff in it. If you need more, just override OnOpenDocument() and call DoMySerialisze from inside there.
Having GetDoc be a member of your document class doesn't make sense because in order to call it, you'd already need to know what your document object was.
GCDEF at 2007-11-10 23:26:42 >
