Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

The Close Window Button (x) 1

Status
Not open for further replies.

Bones3

Programmer
Jul 27, 2003
151
US
Is there a way for the programmer to control what happens when the user clicks the main window's close button (the x at the top right)? Suppose, for example, I would like to perform some cleanup operations before calling exit. Or perhaps I would like to prompt the user to save something.

-Bones
 
I've never used it, but the wm help file includes this, which I think will do what you want:
wm protocol window ?name? ?command?
This command is used to manage window manager protocols such as WM_DELETE_WINDOW. Name is the name of an atom corresponding to a window manager protocol, such as WM_DELETE_WINDOW or WM_SAVE_YOURSELF or WM_TAKE_FOCUS. If both name and command are specified, then command is associated with the protocol specified by name. Name will be added to window's WM_PROTOCOLS property to tell the window manager that the application has a protocol handler for name, and command will be invoked in the future whenever the window manager sends a message to the client for that protocol. In this case the command returns an empty string. If name is specified but command isn't, then the current command for name is returned, or an empty string if there is no handler defined for name. If command is specified as an empty string then the current handler for name is deleted and it is removed from the WM_PROTOCOLS property on window; an empty string is returned. Lastly, if neither name nor command is specified, the command returns a list of all the protocols for which handlers are currently defined for window.
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.

_________________
Bob Rashkin
rrashkin@csc.com
 
Yes, this does what I want. Quick reference for future investigators:

Code:
wm protocol . WM_DELETE_WINDOW {
   # Do cleanup
   exit
}

Thanks!

-Bones
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top