[python-advocacy] fixing shutdown event
alexander.bladh at hotmail.com
alexander.bladh at hotmail.com
Tue Sep 29 20:10:57 CEST 2009
tk/tcl is not abele to catch WM_QUERYENDSESSION and WM_ENDSESSION tk needs to be patched ive found this patch searching around on Google
"Patch:
*** tkWinX.c Sat Oct 10 02:30:37 1998
--- tkWinX.c_new Fri Mar 12 11:25:00 1999
***************
*** 50,55 ****
--- 50,63 ----
LPARAM lParam));
static void GetTranslatedKey _ANSI_ARGS_((XKeyEvent
*xkey));
+
+ static void (*fd_tcl_exit_callback_function_ptr)() = NULL;
+
+ void fd_tcl_register_exit_callback(void (*func_ptr)())
+ {
+ fd_tcl_exit_callback_function_ptr = func_ptr;
+ }
+
/*
*----------------------------------------------------------------------
*
***************
*** 588,593 ****
--- 596,615 ----
Tk_PointerEvent(hwnd, (short) LOWORD(lParam),
(short) HIWORD(lParam));
return 1;
+
+ case WM_QUERYENDSESSION: {
+ *resultPtr = 1;
+ return 1;
+ }
+
+ case WM_ENDSESSION: {
+ if ( wParam == TRUE ) {
+ if ( fd_tcl_exit_callback_function_ptr != NULL ) {
+ (*fd_tcl_exit_callback_function_ptr)();
+ }
+ }
+ return 1;
+ }
case WM_CLOSE:
case WM_SETFOCUS:
PatchFiles:
win/tkWinX.c
And, you have to modify 'winmain.c'
extern void fd_tcl_register_exit_callback(void (*func_ptr)());
static Tcl_Interp *YOUR_TCL_INTERPRETER;
void fd_logoff_callback()
{
char * command = "YOUR_TCL_EXIT_PROC";
Tcl_Obj * cmdObj = Tcl_NewStringObj(command, -1);
if ( Tcl_GlobalEvalObj(YOUR_TCL_INTERPRETER, cmdObj) ==
TCL_ERROR
) {
exit(1);
}
}
...
/* Just before calling TkMain() */
fd_tcl_register_exit_callback(fd_logoff_callback);
...
YOUR_TCL_EXIT_PROC is the Tcl procedure that will get called when
a
logout, restart or shutdown occurs.
Comments:
To handle the WM_QUERYENDSESSION and WM_ENDSESSION events on
Windows, we
added an 'fd_tcl_register_exit_callback()' function to Tk to
register a C callback function.
When receiving a WM_ENDSESSION event with LogOff == TRUE (which
will
only
happen when all running applications returned TRUE when receiving
the
WM_QUERYENDSESSION event) the registered function will be called.
This patch currently fits our needs, but it should be generalized.
We added a 'hook' to call the registered callback function, but a
better
solution would be to provide a new Tcl builtin on Windows to
register a
Tcl logout procedure."
so is there anyone knowing c that can build this for phyton??
thanks for help /Alex
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/advocacy/attachments/20090929/b86842ba/attachment.htm>
More information about the Advocacy
mailing list