I have recently started leaning some Win 32 coding. The MASM32 package is great and the example source code. One I liked was the Fast Edit program. Is there a place where I can find out how to save open files before the computer is shut down.(In case someone forgot to shut down all programs.) I guess it would be something similar to disk flushing and closing open files. Thanks.

Someone suggested I get some info from Win 32 API help. Is that available online or do I have to buy a Win 32 book.

I am impressed by the relatively small size of the Win 32 programs. It's not as good as the 256 byte DOS programs that are available.
Posted on 2002-07-03 13:29:06 by skywalker
That's not as easy as you think. Most applications actually WRITE to file when the user invokes the save command. The only method to do what you are asking for that I have in mind is to find the saving code in the application in question, and run it with CreateRemoteThread. There is more hassle to it then what its worth.
Posted on 2002-07-03 14:23:39 by comrade
A.K.
WHat you should do is this:

For each file that is open maintain an IsFileSaved flag. When the file is changed you unset the associated flag when it is saved you set the flag.

During processing of WM_CLOSE you check each flag and if it is FALSE then you either automatically save the file or prompt the user if they wish to save it.
Posted on 2002-07-03 14:32:30 by MArtial_Code
There are two messages associated with system shutdown:

WM_QUERYENDSESSION and WM_ENDSESSION
Posted on 2002-07-03 15:41:30 by tenkey
MArtial_Code, I think he's talking about saving files for other applications, not his own.
Posted on 2002-07-03 16:16:57 by comrade
I don't think so comrade...Why would A.K. want to close another applications' files? All applications I know of will, on closiing, prompt you to save if you have unsaved files. If a different application took it on itself to close another's files then it 's just asking for trouble...
Posted on 2002-07-03 16:50:39 by MArtial_Code
MArtial_Code: Re-read the opening post in this thread. He's talking about the Q(uick)Exit example in masm's first example folder. What it sounds like he wants is to programmatically and gracefully shut down each open program instead of just exiting.


A.K.: What about sending a WM_CLOSE to each open app? If I need to do any cleanup in my code I put it under the WM_CLOSE section of my message loop. Granted maybe not all programmers do that but I think that it's common practice. Then after each app closed then you can make the ExitWindowsEx call. Or just use EWX_SHUTDOWN instead of EWX_FORCE. I dunno, but you should read the ExitWindowEx entry in the win32 api help file if you haven't done so yet.

edit: MArtial_Code, maybe I'm wrong. That first post is a bit vague, but that's my impression. :) I mean if it was just his own app that he's talking about then he'd just have to take care of any save operations before the ExitWIndows call. That'd be a no-brainer. *shrugs*
Posted on 2002-07-03 18:08:23 by Will
Well, in any case, sending WM_CLOSE will only prompt the application to close. This way, most applications will pop-up a message box asking whether to save changes or not. Forcing the application to close will definitely not save any changes.
Posted on 2002-07-03 18:34:53 by comrade
Maybe it is worth to try WM_HOTKEY. Ctrl-S used often.
Posted on 2002-07-04 10:21:57 by masquer
Possibly, you could also attach to a process, hook MessageBox APIs, send the main window WM_CLOSE message. Then, when MessageBox is called about saving window, you can the message for "save" and if found, you return IDYES. If not, you let the messagebox display.
Posted on 2002-07-04 12:22:20 by comrade