From: Perl R. <pe...@co...> - 2007-08-15 23:05:50
|
D'oh! I just saw that FindWindow() and SendMessage() are both listed in the "Common Methods" of the ActivePerl documentation. I apologize that I didn't RTFM before posting! However, I can't figure out how to properly call the SendMessage() method. It requires an object reference, but how can I create an object reference to a window that isn't mine? ##################################################### use Win32::GUI; my $windowToClose = Win32::GUI::FindWindow("PGPtray_Hidden_Window","PGPtray_Hidden_Window"); # This is a window started by another application $windowToClose->Win32::GUI::SendMessage("WM_CLOSE",0,0); # This fails because $windowToClose is not an object reference. ##################################################### Thanks, Rob _____ From: Perl Rob [mailto:pe...@co...] Sent: Wednesday, August 15, 2007 12:17 PM To: 'Win32 GUI Users Mailing List' Subject: FindWindow and SendMessage Hi all, I'm attempting to close a window using the FindWindow() and SendMessage() functions as documented in MSDN. I can't get it to work, so I was wondering if anyone might help me see what's wrong with my code: ###################################################### use Win32::API; my $findWindow = Win32::API->new( 'user32', 'FindWindow', 'PP', 'P' ); my $sendMessage = Win32::API->new( 'user32', 'SendMessage', 'PIIN', 'P' ); my $windowToClose = $findWindow->Call("PGPtray_Hidden_Window","PGPtray_Hidden_Window"); $sendMessage->Call($windowToClose,"WM_CLOSE",0,0); ###################################################### In particular, I'm not sure whether I'm specifying the correct parameters for each method. (Should the parameters for FindWindow() be 'PP', with a return value of 'P'? And should the parameters for SendMessage() be 'PIIN', with a return value of 'P'?) Thanks in advance, Rob |
From: Perl R. <pe...@co...> - 2007-08-16 06:21:37
|
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 ); my $tray = Win32::GUI::FindWindow("PGPtray_Hidden_Window ","PGPtray_Hidden_Window"); Win32::GUI::SendMessage($tray,WM_CLOSE,0,0); #################################################### 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-now I can close any window (that allows it) by finding its handle and sending it the WM_CLOSE message. -Rob _____ From: Perl Rob [mailto:pe...@co...] Sent: Wednesday, August 15, 2007 5:06 PM To: 'Win32 GUI Users Mailing List' Subject: RE: FindWindow and SendMessage D'oh! I just saw that FindWindow() and SendMessage() are both listed in the "Common Methods" of the ActivePerl documentation. I apologize that I didn't RTFM before posting! However, I can't figure out how to properly call the SendMessage() method. It requires an object reference, but how can I create an object reference to a window that isn't mine? ##################################################### use Win32::GUI; my $windowToClose = Win32::GUI::FindWindow("PGPtray_Hidden_Window","PGPtray_Hidden_Window"); # This is a window started by another application $windowToClose->Win32::GUI::SendMessage("WM_CLOSE",0,0); # This fails because $windowToClose is not an object reference. ##################################################### Thanks, Rob _____ From: Perl Rob [mailto:pe...@co...] Sent: Wednesday, August 15, 2007 12:17 PM To: 'Win32 GUI Users Mailing List' Subject: FindWindow and SendMessage Hi all, I'm attempting to close a window using the FindWindow() and SendMessage() functions as documented in MSDN. I can't get it to work, so I was wondering if anyone might help me see what's wrong with my code: ###################################################### use Win32::API; my $findWindow = Win32::API->new( 'user32', 'FindWindow', 'PP', 'P' ); my $sendMessage = Win32::API->new( 'user32', 'SendMessage', 'PIIN', 'P' ); my $windowToClose = $findWindow->Call("PGPtray_Hidden_Window","PGPtray_Hidden_Window"); $sendMessage->Call($windowToClose,"WM_CLOSE",0,0); ###################################################### In particular, I'm not sure whether I'm specifying the correct parameters for each method. (Should the parameters for FindWindow() be 'PP', with a return value of 'P'? And should the parameters for SendMessage() be 'PIIN', with a return value of 'P'?) Thanks in advance, Rob |
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. |