Re: Error message when using OpenDocumentFile on read-only files
From: Dieter Lorenz (dieter_lorenz_at_web.de)
Date: 01/20/05
- Next message: Fritz Hilgemann: "Re: selection problem"
- Previous message: Tom Serface: "Re: Error message when using OpenDocumentFile on read-only files"
- In reply to: Tom Serface: "Re: Error message when using OpenDocumentFile on read-only files"
- Messages sorted by: [ date ] [ thread ]
Date: Thu, 20 Jan 2005 08:38:37 +0100
The main problem I had was that I looked for an "easy" way to open a
document in my application so I tried to use
CWinApp::OpenDocumentFile(NULL); to create an empty document and then I
wanted to load the data and so on.
Surprisingly for me it is not allowed to use a NULL pointer in this
function. I had to use the template:
CMyDocument* pDoc=NULL;
POSITION pos = GetFirstDocTemplatePosition();
pDoc = (CMyDocument*)(GetNextDocTemplate(pos)->OpenDocumentFile(NULL));
then I can change the title of the document view by
pDoc->SetTitle(lpszFileName); // (well, I have to cut off the path just to
have just the filename in the future)
One advantage is that I can open now one document several times in one
application (for me it is an advantage).
The only thing that is bothering me is the size of the document view. It is
very small so I have to look for better default size for the view of empty
documents...
Regards
Dieter
"Tom Serface" <tserface@msn.com> schrieb im Newsbeitrag
news:%2389IUUo$EHA.2584@TK2MSFTNGP09.phx.gbl...
> The document is set up for you in the main app code in the document
> template. The object is created automatically when a document is opened.
> My guess is that the default serialization stuff which the document uses
is
> trying to open the file for writing as well as reading. You can override
> the OnOpenDocument() and OnSaveDocument() functions and do this yourself
> since you will know how the data will be stored in your document object.
> The built in stuff is pretty simple and not much use so I, well, never use
> it.
>
> Tom
>
> "Dieter Lorenz" <dieter_lorenz@web.de> wrote in message
> news:357vq4F4jdqkgU1@individual.net...
> >I think I have to tell more details :-)
> >
> > I started my project with the AppWizard including "full-server" document
> > support and multiple documents. When I compile this application (nothing
> > added manual to the source code), I get an error message when I try to
> > open
> > a file with write-protection.
> >
> > I can not call a member function of a document when I did not create the
> > document yet.
> > Which function do I have to call to create a document and its view from
> > the
> > application class? Or am I totally wrong?
> >
> > Regards
> > Dieter
> >
> > "Tom Serface" <tserface@msn.com> schrieb im Newsbeitrag
> > news:uldg63k$EHA.3700@tk2msftngp13.phx.gbl...
> >> You could simply override OnOpenDocument() instead and just manage the
> > file
> >> yourself. Be sure to open the file with a shared mode if you don't
want
> > to
> >> lock it. Better yet, read the file into a buffer and close it as
quickly
> > as
> >> you can.
> >>
> >> BOOL CMyAppDoc::OnOpenDocument(LPCTSTR lpszPathName)
> >> {
> >> if(!CDocument::OnOpenDocument(lpszPathName))
> >> return false;
> >>
> >> CString cs, XMLString;
> >> BOOL m_bXMLDocument = false;
> >> CStdioFile MyFile;
> >> if(MyFile.Open( lpszPathName, CFile::modeRead | CFile::typeText ) )
{
> >> while(MyFile.ReadString(cs)) {
> >> // We need to skip the CDATA part so just add the close on
> >> // to the end of the string so we don't get a parsing error.
> >> if(cs.Find("<![CDATA") != -1) {
> >> XMLString += "</QuickDiscDoc>\n";
> >> break;
> >> }
> >> XMLString += cs;
> >> }
> >> MyFile.Close();
> >> m_bXMLDocument = XMLString.Left(2) == _T("<?");
> >> return true;
> >> }
> >>
> >> Tom
> >>
> >> "Dieter Lorenz" <dieter_lorenz@web.de> wrote in message
> >> news:356k1dF4ilu6eU1@individual.net...
> >> >I want to use the OpenDocumentFile function to open and show a
document
> > in
> >> > my application.
> >> > This works fine for files without write protection but for files
which
> > are
> >> > read-only I get an error message from
> >> >
> >> > CDocument* CTestApp::OpenDocumentFile(LPCTSTR lpszFileName)
> >> > {
> >> > // TODO: Add your specialized code here and/or call the base class
> >> >
> >> > return CWinApp::OpenDocumentFile(lpszFileName);
> >> > }
> >> >
> >> > The other problem I have with this application is that the files
which
> > are
> >> > open by my application are locked.
> >> >
> >> > I believe that these two items are closely related to each other.
> >> >
> >> > Any ideas or do you need more informations?
> >> >
> >> > Best regards
> >> > Dieter
> >> >
> >> >
> >>
> >>
> >
> >
>
>
- Next message: Fritz Hilgemann: "Re: selection problem"
- Previous message: Tom Serface: "Re: Error message when using OpenDocumentFile on read-only files"
- In reply to: Tom Serface: "Re: Error message when using OpenDocumentFile on read-only files"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|