EXIT via X on title bar ... -Repeated plea

EXIT via X on title bar ... -Repeated plea

The two responses I got to a previous question were not too helpful, primarily because of my "knowledge level" (read "ignorance"). So forgive me if I ask again:

In my QuickWin application I have a callback routine used when the user selects File > Exit from the program's menu. I use this to remind the user to save files if needed. Works just fine.

However when the user clicks on the Title Bar X, or shuts down the computer from the task bar, my routine is bypassed, and the program shuts down with out giving the user the option of saving files!

How does one direct Title bar x or computer shutdown to transfer control to my routine??

publicaciones de 10 / 0 nuevos
Último envío
Para obtener más información sobre las optimizaciones del compilador, consulte el aviso sobre la optimización.

This is not my area of expertise, but I wonder if using SIGNALQQ with a request for SIG$TERM would do the trick.

Steve

Steve Intel Developer Support

You need to handle a WM_CLOSE on the frame window. Here is a simple example:

program simple
use dflib
use user32
use kernel32
integer(LONG) f
common /wininfo/ f
external CatchClose
!DEC$ attributes stdcall :: CatchClose
print *, "Hello"
f = SetWindowLong (GETHWNDQQ(QWIN$FRAMEWINDOW), GWL_WNDPROC, LOC(CatchClose))
if (f == 0) print *, "Error - unable to install close handler"
pause
end

integer(4) function CatchClose (hwnd, msg, wparam, lparam)
!DEC$ attributes stdcall :: CatchClose
use user32
integer(4) hwnd, msg, wparam, lparam
integer(LONG) f
common /wininfo/ f
if (msg == WM_CLOSE) then
  call MessageBox (NULL, "Put your close code here"c, "Closing..."c, MB_OK)
end if
CatchClose = CallWindowProc (f, hwnd, msg, wparam, lparam)
return
end

James

James,

Is you recommended procedure OK in QUICK WIN?
PAUL

You bet.

James

Very Good!!

The post by James indeed works if the user calls for an exit via the X on the title bar. THANKS

BUT If the user does a computer shutdown the "save File?" warning is not invoked. This is not a show stopper but it would be nice if the Shutdown were trapped. Any suggestions?

PAUL

See my answer above - I think that's what you need for a termination handler.

Steve

Steve Intel Developer Support

Paul,

You can catch a shutdown by adding something like

else if (msg == WM_ENDSESSION) then
  call MessageBox (NULL, "Put your end session code here"c, "Closing..."c, MB_OK)

after the WM_CLOSE branch in the example I provided. However note that Windows will bring up the "Program is not responding" message if you don't complete whatever you are doing within a few seconds, not wonderful for user input.

You can also "vote down" the shutdown to make sure you get your question answered, then either allow the user to re-initiate shutdown manually or do a shutdown yourself. Depends on how important you think your interaction with the user is.

James

I think WM_QUERYENDSESSION is the better message to handle -- it is sent before WM_ENDSESSION to "ask the application about its opinion" (the WndProc should return 1 if it agrees). However, I didn't verify whether it has timeout period.

Jugoslav

Jugoslav www.xeffort.com

There won't be much difference as QM_QUERYENDSESSION also has the timeout period.

James

Inicie sesión para dejar un comentario.