Categories: MSDN / DotNet / Java / Scripts / Linux / PHP Ask - La ask - La Answer

Suppressing save file option

I would be very grateful for some help. I'm working on a program written
by previous authors with which I need to make some changes. On starting
up the program I want it to skip over asking the user for a filename, and
found that in the code fragment:

...
ASSERT_VALID(pDoc);
CString nameFile=pDoc->GetPathName();
if (nameFile.IsEmpty()) {
CString newName=pDoc->GetTitle();
if (!AfxGetApp()->DoPromptFileName(newName,
AFX_IDS_SAVEFILE, OFN_HIDEREADONLY | OFN_PATHMUSTEXIST,
FALSE, pDoc->GetDocTemplate()))
return;
nameFile = newName;
pDoc->SetPathName(nameFile);
}
...

I can replace the statement "CString newName=pDoc->GetTitle()" by "CString
newName="FILENAME.XXX", and comment out the following four lines (the 2nd
and 3rd lines are of course really a continuation of the 1st), i.e. the condition
and return statements, and the program works without prompting for a filename.

However, on termination, I'm unable to suppress the box:
_________________________________
|Programname Windows Application |
|(?) Save Changes to FILENAME.XXX |
| |
| [Yes] [No] [Cancel] |
| - - |
|_________________________________|

and I have to click on the "No" button. In looking through a simple example
in Visual C++ (in fact the "Scribble" example), whenever I close the program
without saving the file I get this message, and even in the simple example
I can't find a way of supressing it.

Eventually I need to re-write large parts of the program, but for the time
being I want to run the program without asking for a filename, then discard
the dummy filename on completion without user intervention. No matter how
the program is closed, I need to suppress the message box above. I would
be very grateful of knowing a simple way of suppressing the message box no
matter where the mouse is clicked to close the program.

Christopher M. Sharp
[2124 byte] By [Christopher Sharp] at [2007-11-10 12:52:02]
# 1 Re: Suppressing save file option
The virtual function CDocument::SaveModified, which the framework calls when user
closes the document, displays this message box if the m_bModified flag is set to
TRUE. You can override this function to e.g. suppress this behaviour.

Cheers,
Christof

Christopher Sharp wrote:

> I would be very grateful for some help. I'm working on a program written
> by previous authors with which I need to make some changes. On starting
> up the program I want it to skip over asking the user for a filename, and
> found that in the code fragment:
>
> ...
> ASSERT_VALID(pDoc);
> CString nameFile=pDoc->GetPathName();
> if (nameFile.IsEmpty()) {
> CString newName=pDoc->GetTitle();
> if (!AfxGetApp()->DoPromptFileName(newName,
> AFX_IDS_SAVEFILE, OFN_HIDEREADONLY | OFN_PATHMUSTEXIST,
> FALSE, pDoc->GetDocTemplate()))
> return;
> nameFile = newName;
> pDoc->SetPathName(nameFile);
> }
> ...
>
> I can replace the statement "CString newName=pDoc->GetTitle()" by "CString
> newName="FILENAME.XXX", and comment out the following four lines (the 2nd
> and 3rd lines are of course really a continuation of the 1st), i.e. the condition
> and return statements, and the program works without prompting for a filename.
>
> However, on termination, I'm unable to suppress the box:
> _________________________________
> |Programname Windows Application |
> |(?) Save Changes to FILENAME.XXX |
> | |
> | [Yes] [No] [Cancel] |
> | - - |
> |_________________________________|
>
> and I have to click on the "No" button. In looking through a simple example
> in Visual C++ (in fact the "Scribble" example), whenever I close the program
> without saving the file I get this message, and even in the simple example
> I can't find a way of supressing it.
>
> Eventually I need to re-write large parts of the program, but for the time
> being I want to run the program without asking for a filename, then discard
> the dummy filename on completion without user intervention. No matter how
> the program is closed, I need to suppress the message box above. I would
> be very grateful of knowing a simple way of suppressing the message box no
> matter where the mouse is clicked to close the program.
>
> Christopher M. Sharp
Christof Helm at 2007-11-11 20:40:29 >
# 2 Re: Suppressing save file option
Try looking for any Invalidate() statements and remark those out. If the
document is never invalidated, then there would be no reason for the app
to ask if you want to save or not.

Marc

"Christopher Sharp" <info@csharp.com> wrote:
>
>I would be very grateful for some help. I'm working on a program written
>by previous authors with which I need to make some changes. On starting
>up the program I want it to skip over asking the user for a filename, and
>found that in the code fragment:
>
>...
>ASSERT_VALID(pDoc);
>CString nameFile=pDoc->GetPathName();
>if (nameFile.IsEmpty()) {
> CString newName=pDoc->GetTitle();
> if (!AfxGetApp()->DoPromptFileName(newName,
> AFX_IDS_SAVEFILE, OFN_HIDEREADONLY | OFN_PATHMUSTEXIST,
> FALSE, pDoc->GetDocTemplate()))
> return;
> nameFile = newName;
> pDoc->SetPathName(nameFile);
>}
>...
>
>I can replace the statement "CString newName=pDoc->GetTitle()" by "CString
>newName="FILENAME.XXX", and comment out the following four lines (the 2nd
>and 3rd lines are of course really a continuation of the 1st), i.e. the
condition
>and return statements, and the program works without prompting for a filename.
>
>However, on termination, I'm unable to suppress the box:
> _________________________________
>|Programname Windows Application |
>|(?) Save Changes to FILENAME.XXX |
>| |
>| [Yes] [No] [Cancel] |
>| - - |
>|_________________________________|
>
>and I have to click on the "No" button. In looking through a simple example
>in Visual C++ (in fact the "Scribble" example), whenever I close the program
>without saving the file I get this message, and even in the simple example
>I can't find a way of supressing it.
>
>Eventually I need to re-write large parts of the program, but for the time
>being I want to run the program without asking for a filename, then discard
>the dummy filename on completion without user intervention. No matter how
>the program is closed, I need to suppress the message box above. I would
>be very grateful of knowing a simple way of suppressing the message box
no
>matter where the mouse is clicked to close the program.
>
>Christopher M. Sharp
marc cohn at 2007-11-11 20:41:26 >
# 3 Re: Suppressing save file option
Dear Christof,

Thanks for your very useful tip. However, being still quite new to C++/Visual
C++, I'm not very familiar as to how to override CDocument::SaveModified
to set m_bModified to FALSE.

In the interim I found that by adding to the code associated with one of
the buttons the function _exit(0) causes the program to terminate neatly.
If I try exit(0) (without the "_") an error message is generated.

I'm doing all this at the moment under Windows 3.11 and Visual C++1.52, as
the code was apparently written under that system, and currently won't work
with Windows 95/98 and Visual C++6.

Cheers, Christopher.

Christof Helm <c.helm@okay.net> wrote:
>The virtual function CDocument::SaveModified, which the framework calls
when user
>closes the document, displays this message box if the m_bModified flag is
set to
>TRUE. You can override this function to e.g. suppress this behaviour.
>
>Cheers,
>Christof
Christopher Sharp at 2007-11-11 20:42:30 >
# 4 Re: Suppressing save file option
Marc:

Thanks, I'll check through the code as I know there are some Invalidate()
statements. This is perhaps an alternate idea to Christof's suggestion.

Christopher

"marc cohn" <marc-cohn@home.com> wrote:
>
>Try looking for any Invalidate() statements and remark those out. If the
>document is never invalidated, then there would be no reason for the app
>to ask if you want to save or not.
>
>Marc
Christopher Sharp at 2007-11-11 20:43:31 >