code on shutdown

This is a discussion on code on shutdown within the Windows Programming forums, part of the Platform Specific Boards category; I'm trying to figure out how to make my program execute some code (eg. save files) if the computer is ...

  1. #1
    n3v
    n3v is offline
    irregularly symmetrical n3v's Avatar
    Join Date
    Mar 2006
    Location
    Finland
    Posts
    67

    code on shutdown

    I'm trying to figure out how to make my program execute some code (eg. save files) if the computer is shutting down. is that possible?

    how does the computer shut programs when it's shutting down?
    if i put some code into the exit function, would it run when the computer shuts down?
    If you make a man a fire,
    he will be warm for a day.
    If you set a man on fire,
    he will be warm for the rest of his life.

  2. #2
    Registered User Tonto's Avatar
    Join Date
    Jun 2005
    Location
    New York
    Posts
    1,465
    Quote Originally Posted by MSDN
    The system sends a WM_QUERYENDSESSION to the main window of each running application.

    Windows Me/98/95: The system sends a WM_QUERYENDSESSION to all applications except calling application.

    An application agrees to terminate by returning TRUE when it receives this message (or by allowing the DefWindowProc function to process the message). If any application returns FALSE when it receives the WM_QUERYENDSESSION message, the shutdown is canceled.

    After the system processes the results of the WM_QUERYENDSESSION message, it sends the WM_ENDSESSION message with the wParam parameter set to TRUE if the system is shutting down and to FALSE if it is not.
    http://msdn.microsoft.com/library/de...endsession.asp

    For console programs

    http://msdn.microsoft.com/library/de...trlhandler.asp

  3. #3
    n3v
    n3v is offline
    irregularly symmetrical n3v's Avatar
    Join Date
    Mar 2006
    Location
    Finland
    Posts
    67
    so wait, it's actually possible to stop the computer from shutting down by returning a false?
    If you make a man a fire,
    he will be warm for a day.
    If you set a man on fire,
    he will be warm for the rest of his life.

  4. #4
    pwns nooblars
    Join Date
    Oct 2005
    Location
    Portland, Or
    Posts
    1,094
    Aye that is what the documentation says. Ever had a file open in an editor and say cancle to shutting program when you said to shutdown the computer and it cancled the shutdown.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Enforcing Machine Code Restrictions?
    By SMurf in forum Tech Board
    Replies: 21
    Last Post: 03-30-2009, 08:34 AM
  2. Proposal: Code colouring
    By Perspective in forum A Brief History of Cprogramming.com
    Replies: 28
    Last Post: 05-14-2007, 08:23 AM
  3. Values changing without reason?
    By subtled in forum C Programming
    Replies: 2
    Last Post: 04-19-2007, 11:20 AM
  4. Obfuscated Code Contest
    By Stack Overflow in forum Contests Board
    Replies: 51
    Last Post: 01-21-2005, 04:17 PM
  5. Interface Question
    By smog890 in forum C Programming
    Replies: 11
    Last Post: 06-03-2002, 06:06 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21