From: Robert M. <rob...@us...> - 2007-11-10 09:29:46
|
On 16/08/2007, Perl Rob <pe...@co...> wrote: > Well, I answered my own question, so I thought I'd post the answer > in case it helps someone else who wants to close a window in this > manner. Turns out I had to create a quoted word list and add > WM_CLOSE to it (as a part of my "use Win32::GUI" line): > > use Win32::GUI qw( WM_CLOSE ); > > > To be perfectly honest, I don't understand *why* that fixed the > problem, but it did. I couldn't get any windows to close until I > did that=97now I can close any window (that allows it) by finding > its handle and sending it the WM_CLOSE message. That's the syntax for getting Win32::GUI to import constants into the caller's namespace (in fact it's a very common perl syntax in general). Read the documentation for Win32::GUI::Constants for more information. If you had a 'use warnings;' line, then your earlier attempts would have given you more information about why they were not working. [As an aside you shouldn't blindly assume that sending a window a WM_CLOSE will close it - an application is perfectly entitled to catch the WM_CLOSE message and not close the window - for example many programs catch the WM_CLOSE and pop up a dialog asking whether the user really wants to exit (annoying, but it happens) - this is perhaps more useful if the application is reporting that there are unsaved changes and asking if the user wants to save them before exiting.] Regards, Rob. |