Close Down Program

Started by Marty Francom, January 16, 2006, 01:21:18 PM

Previous topic - Next topic

Marty Francom

If I have some code that needs to run at close down of the program,  where would be the best place to put it.  So that no matter how the program is closed that code will run just before the program closes.
..
Users could close the program with my "exit" button, or clicking the little "X" button in the top right hand corner of the window or might right click on the task bar Icon of the program and select close.
..
So, where would be the best place to put the special close down code?

Roger Garstang

WM_CLOSE would be the first choice.  WM_DESTROY would be the last message if you want specific.  No code would run on a task manager End Task though unless you have another app/dll monitor the process.

Mark Strickland

Marty,

This is where I process the X on the main form.  Put this in the CUSTOM event on the main form in the application.

Mark



   dim lresult as long

   SELECT CASE wMsg
 
       CASE %WM_SYSCOMMAND
           'Catch that the X was clicked
           IF ( wParam AND %SC_CLOSE ) = %SC_CLOSE THEN

               lResult = MESSAGEBOX( hWndForm, _
                           $CRLF + _
                           "Are you sure you wish to exit?", _
                           "Message", _
                           %mb_rxyesno + _
                           %MB_DEFBUTTON2 + _
                           %MB_ICONQUESTION)
               
               IF  lResult = %IDNO THEN
                   FUNCTION = 1
                   EXIT FUNCTION
               ELSE
               
                   'Do shutdown stuff here because the user selected to end
                   

                   FF_CLOSEFORM hWndForm  :' This shuts down the program


               END IF
           END IF
       
   End Select


Roger Garstang

That catches half the ways to close a Window...no need to have the code in custom, Paul made FF's generated code route all ways of closing a window to WM_CLOSE...hopefully V3 keeps this cause it is one of my favorites and elimintates trapping both types of closing.

TechSupport

Quote from: Roger GarstangWM_DESTROY would be the last message if you want specific.  

To be really exact, the WM_NCDESTROY message is the last message that a window processes.   :P

WM_DESTROY is fired before any child windows are destroyed, while WM_NCDESTROY is fired after the child controls are destroyed and just before the memory for the window is about to be freed.

Roger Garstang

Yeah, that too... :P

BTW...since when did ole Billy actaully make Windows free memory?  Must be a new version you're beta testing cause he has mine eating it all day!

One thing I wish they'd make in future versions is a function to call when the app is End Tasked, kinda like old Ctrl+Break handlers in DOS or something, maybe since the handler would be capable of hanging too it gives it like 5-10 secs to cleanup or something.  Windows would probably have to add some new ShellExecute block or something though so Apps and Viruses wouldn't be able to turn applications into IE style Pop-up Windows.

Marty Francom

Thanks for the suggestions.... That covers the majority or the close down
possibilities.