Solved

Keeping original doc name even if saving as another name.

Posted on 2000-02-16
8
171 Views
Last Modified: 2013-11-20
I have an MDI doc/view with normal serialization for saving (it saves as myfile.cpw).  I've added an option to the CFileDialog so the user can save the contents of the edit boxes as a text file if they want (the default is myfile.cpw).  Everything works great except... when it comes back to the main view the document name changes to myfile.txt and the next save saves it as myfile.txt.  I'd like everything to revert back to how it was as if no save function has taken place.  In other words, I want the user to be able to save it as a text file, but when they come back it basically hasn't affected anything.  It still says myfile.cpw and is still dirty (if changes were made since the last "myfile.cpw" save).  I'm assuming I have to collect the original doc name and put it back after the functions, but I'm not sure where that's kept or the best way to handle it.  Thanks.

Jim Weiss
0
Comment
Question by:jjjkkklll
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
  • 2
8 Comments
 
LVL 1

Accepted Solution

by:
ScottyDawg earned 150 total points
ID: 2528296
You can use the functions SetTitle() and SetPathName().

However, what you're doing is non-standard perhaps you should consider and export menu item...?
0
 

Author Comment

by:jjjkkklll
ID: 2528638
Okay, I can get the title and pathname before the function does its business and put them back when it's done.  Will this affect the dirty flag?  

Also, I'm seriously considering adding an "export" menu item. If I use the same structure, though, it basically would do the same thing, right?  Only difference would be that the user would get to the CFileDialog override through an "export" menu button rather than through the "save as" item.  Would this still affect the title and pathname?  In other words, is there a way, if I put this in a separate "export" menu button, to avoid changing the title and pathname in the first place?  Is there a way to export to a text file in a vacuum?  Thanks for any help.

Jim Weiss
0
 
LVL 1

Expert Comment

by:ScottyDawg
ID: 2530364
I don't think so, but then I don't think its to much bother anyhow.

i.e.
// All called from CDocument OnExportFile() or something...

CString strPathName = GetPathName();
CString strTitle = GetTitle();
bool bDirty = IsModified();

CFileDialog FileDlg(false, ".exp");
if (FileDlg.DoModal() != IDOK)
    return;

CString strExport = FileDlg.GetPathName();
SetPathName(strExport);

AfxGetApp()->OnFileSave();

SetPathName(strPathName);
SetTitle(strTitle);
SetModified(bDirty);


A little buggy no doubt, but maybe along the lines of what you need?
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 31

Expert Comment

by:Zoppo
ID: 2530557
Hi jjjkkklll,

you can try following:

override your document's DoSave() function (unfortunately not documented virtual function of CDocument) like this:

BOOL
CMyDoc::DoSave(LPCTSTR lpszPathName, BOOL bReplace /*= TRUE*/ )
{
 CString oldName = GetPathName();
 BOOL bRet = CDocument::DoSave( lpszPathName, bReplace );
 SetPathName( oldName );
 return bRet;
}

hope that helps,

ZOPPO
0
 

Author Comment

by:jjjkkklll
ID: 2532052
Both answers are excellent and I wish I could split the points, but I'll give it to ScottyDawg for his quick first response.  The basic theory on both  seems to be to capture the oldName and put it back when I'm done saving the text file.  I have a lot of tweaking to do, but I'm on my way.

I just have one question for Zoppo (or anyone who knows) before I close this question. Regarding his (or her) code, don't I have to SetTitle() to the old name, too?  Or is setting the path name enough to handle the title and path name of the document? Actually, the more I study it, the more complex it gets. Where do I put the CFileDialog to get the new file name for the text file I'm creating?  I.e. what has to happen before I call the DoSave override?  Thanks.

Jim Weiss
0
 
LVL 1

Expert Comment

by:ScottyDawg
ID: 2534136
The FileSave business is really "busy" in CDocument. It does so much stuff before it actually calls your routines.

The best thing to do, is to step through the MFC sources and see what happens. You'll come across functions like DoPromptFilename(...), DoSave and DoFileSave. One of these you might just be able to override to get just what you want.
0
 
LVL 31

Expert Comment

by:Zoppo
ID: 2534196
Hi jjjkkklll,

You can place the file dialog into the DoSave routine, i.e.:

BOOL
CMyDoc::DoSave(LPCTSTR lpszPathName, BOOL bReplace /*= TRUE*/ )
{
 CString oldName = GetPathName();
 // remove this 'if' if you want the same handling for 'Save' and 'SaveAs'
 // if lpszPathName == NULL 'SaveAs' was selected, else 'Save'
 if ( NULL == lpszPathName )
 {
  // Do your file dialog here and set lpszPathName to the resulting file path
  // or return FALSE; if file dialog was cancelled
 }
 BOOL bRet = CDocument::DoSave( lpszPathName, bReplace );
 SetPathName( oldName );
 return bRet;
}

The CDocument::DoSave does handle the default 'Save' and 'SaveAs' behavior. It displays the file dialog if needed and validates the filename. Then it calls CDocument::OnSaveDocument().

SetTitle() is not needed when SetPathName() is used, because it's called by SetPathName().

hope that helps,

ZOPPO
0
 

Author Comment

by:jjjkkklll
ID: 2535832
Thanks, Zoppo. As I said, I wish I could split the points...
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Tab names are off by one 5 54
lucky13 challenge 11 167
zeroMAx challenge 20 135
Excel file not created as expected 7 111
In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

751 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question