Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

WM_SAVE_YOURSELF... how to use?

488 views
Skip to first unread message

Óscar Fuentes

unread,
Apr 9, 2008, 2:07:04 PM4/9/08
to
My application needs to notice when the OS (WindowsXP) shuts down or
restarts in order to close correctly, so I put this on the code:

wm protocol . WM_SAVE_YOURSELF {destroy .}

The destroy is executed, but the application is killed by the OS.

The application is a C++ one and embeds Tcl/Tk for GUI purposes. In
theory, when destroy . is executed, the Tk_MainLoop() call on the C++
code returns and the application proceeds to an orderly termination. And
this is how things happen when destroy . is executed on the Tcl side,
except on the WM_SAVE_YOURSELF case mentioned above.

What I'm missing?

I was looking at twapi for some alternative way of detecting when the OS
shuts down, but no success.

--
Oscar

Gerald W. Lester

unread,
Apr 9, 2008, 2:23:23 PM4/9/08
to

You may also have to grab the WM_DELETE_WINDOW protocol message.

--
+--------------------------------+---------------------------------------+
| Gerald W. Lester |
|"The man who fights for his ideals is the man who is alive." - Cervantes|
+------------------------------------------------------------------------+

Óscar Fuentes

unread,
Apr 9, 2008, 2:30:57 PM4/9/08
to

Hello Gerald.

"Gerald W. Lester" <Gerald...@cox.net> writes:

> Óscar Fuentes wrote:
>> My application needs to notice when the OS (WindowsXP) shuts down or
>> restarts in order to close correctly, so I put this on the code:
>>
>> wm protocol . WM_SAVE_YOURSELF {destroy .}
>>
>> The destroy is executed, but the application is killed by the OS.
>

> You may also have to grab the WM_DELETE_WINDOW protocol message.

For doing what?

From the wm protocol man page:

"Tk always defines a protocol handler for WM_DELETE_WINDOW, even if you
haven't asked for one with wm protocol. If a WM_DELETE_WINDOW message
arrives when you haven't defined a handler, then Tk handles the message
by destroying the window for which it was received."

--
Oscar

Gerald W. Lester

unread,
Apr 9, 2008, 3:02:50 PM4/9/08
to

Sorry you are correct. I was thinking that you were making some calls to do
cleanup and did not look at what was you were doing. When I've used the
protocol handlers I've always executed code to do the cleanup.

My guess is that as soon as Tk "process" the WM_SAVE_YOURSELF (i.e. after
your call returns and it releases whatever message handle it had) that MS
Windows is assuming you have done all your save processing and terminates
the process the hard way (the equivelant of a kill -9).

Can you add a callback into the C/C++ code to tell it to clean up that you
call when you get the WM_SAVE_YOURSELF message?

Óscar Fuentes

unread,
Apr 9, 2008, 3:21:42 PM4/9/08
to
"Gerald W. Lester" <Gerald...@cox.net> writes:

[snip]

> My guess is that as soon as Tk "process" the WM_SAVE_YOURSELF
> (i.e. after your call returns and it releases whatever message handle
> it had) that MS Windows is assuming you have done all your save
> processing and terminates the process the hard way (the equivelant of
> a kill -9).
>
> Can you add a callback into the C/C++ code to tell it to clean up that
> you call when you get the WM_SAVE_YOURSELF message?

That's a good idea. I'll try it.

Thanks, Gerald.

--
Oscar

Ralf Fassel

unread,
Apr 9, 2008, 3:41:51 PM4/9/08
to
* Óscar Fuentes <o...@wanadoo.es>

| My application needs to notice when the OS (WindowsXP) shuts down or
| restarts in order to close correctly, so I put this on the code:
|
| wm protocol . WM_SAVE_YOURSELF {destroy .}

I'm not sure whether this is the intended application of
WM_SAVE_YOURSELF... Googling I find references that WM_SAVE_YOURSELF
is intended as a checkpoint, not a final shutdown message.

IIRC at least the window manager on IRIX used to send this message
periodically to the application, so exiting would have a rather
strange effect on the applications' L&F.

R'

Óscar Fuentes

unread,
Apr 9, 2008, 4:34:25 PM4/9/08
to
Ralf Fassel <ral...@gmx.de> writes:

> * Óscar Fuentes <o...@wanadoo.es>
> | My application needs to notice when the OS (WindowsXP) shuts down or
> | restarts in order to close correctly, so I put this on the code:
> |
> | wm protocol . WM_SAVE_YOURSELF {destroy .}
>
> I'm not sure whether this is the intended application of
> WM_SAVE_YOURSELF... Googling I find references that WM_SAVE_YOURSELF
> is intended as a checkpoint, not a final shutdown message.


My reading from

http://groups.google.com/group/comp.lang.tcl/browse_frm/thread/47d3a14345a079eb/4c3cb6004bb853ed

and

http://groups.google.com/group/comp.lang.tcl/browse_frm/thread/5f703f2369124285/13747e842c1a437c

indicates that it is intended as an exit handler. At leas on Windows.

> IIRC at least the window manager on IRIX used to send this message
> periodically to the application, so exiting would have a rather
> strange effect on the applications' L&F.

Information like this is the reason why I restricted this approach to
Windows.

Regards,

--
Oscar

Ralf Fassel

unread,
Apr 10, 2008, 4:18:24 AM4/10/08
to
* Óscar Fuentes <o...@wanadoo.es>

I agree. My search had not found those threads...

| > IIRC at least the window manager on IRIX used to send this message
| > periodically to the application, so exiting would have a rather
| > strange effect on the applications' L&F.
|
| Information like this is the reason why I restricted this approach to
| Windows.

IMHO it is very unfortunate that WM_SAVE_YOURSELF has been reused by
Tk with different meaning on Windows...but too late to change probably.

R'

Óscar Fuentes

unread,
Apr 10, 2008, 10:26:34 AM4/10/08
to
Ralf Fassel <ral...@gmx.de> writes:

> | > IIRC at least the window manager on IRIX used to send this message
> | > periodically to the application, so exiting would have a rather
> | > strange effect on the applications' L&F.
> |
> | Information like this is the reason why I restricted this approach to
> | Windows.
>
> IMHO it is very unfortunate that WM_SAVE_YOURSELF has been reused by
> Tk with different meaning on Windows...but too late to change probably.

Even more infortunate is the fact that it is broken :-)

My experience indicates that, as Gerald suggested, the application is
killed just after the message that triggers WM_SAVE_YOURSELF is
processed.

--
Oscar

0 new messages