Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
29236 讨论

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

pmichael
初学者
1,220 次查看
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??

0 项奖励
9 回复数
Steven_L_Intel1
1,220 次查看
This is not my area of expertise, but I wonder if using SIGNALQQ with a request for SIG$TERM would do the trick.

Steve
0 项奖励
james1
初学者
1,220 次查看
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
0 项奖励
pmichael
初学者
1,220 次查看
James,

Is you recommended procedure OK in QUICK WIN?
PAUL
0 项奖励
james1
初学者
1,220 次查看
You bet.

James
0 项奖励
pmichael
初学者
1,220 次查看
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
0 项奖励
Steven_L_Intel1
1,220 次查看
See my answer above - I think that's what you need for a termination handler.

Steve
0 项奖励
james1
初学者
1,220 次查看
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
0 项奖励
Jugoslav_Dujic
重要分销商 II
1,220 次查看
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
0 项奖励
james1
初学者
1,220 次查看
There won't be much difference as QM_QUERYENDSESSION also has the timeout period.

James
0 项奖励
回复