Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re^9: How to close an application window in Background? (GuiTest PostMessage)

by Anonymous Monk
on Mar 21, 2014 at 12:00 UTC ( [id://1079247]=note: print w/replies, xml ) Need Help??


in reply to Re^8: How to close an application window in Background? (GuiTest PostMessage)
in thread How to close an application window in Background?

And I did this also insted of above one.

Congratulations, you found the right constants

Both did not work.

Well, hwndSendKeys () isn't perfect, but it did send ascii keys successfully to a background window

What were you expecting it to do that it didn't do for you?

  • Comment on Re^9: How to close an application window in Background? (GuiTest PostMessage)

Replies are listed 'Best First'.
Re^10: How to close an application window in Background? (GuiTest PostMessage)
by pradeep,krishna (Scribe) on Mar 21, 2014 at 12:03 UTC

    Here is my full code, Please go through it... Let me know what are the errors, and the changes to be made.

    #perl use constant WM_KEYDOWN => 0x0100; use constant WM_KEYUP => 0x0101; use Win32::GuiTest qw(FindWindowLike MenuSelect WaitWindow WMSetText + PushChildButton GetSystemMenu SetForegroundWindow); system('"start %windir%\system32\mstsc.exe"'); #--System prog +ram to open the the Remote Desktop Connection application sleep(2); #let me see the window $max_Sleep_time=5; #--Maximum wait in sec to open the Remote Desk +top Connection application WaitWindow("Remote Desktop Connection",$max_Sleep_time); @windows = FindWindowLike(0, "Remote Desktop Connection"); for (@windows) #--for each of the open windows do the follow +ing { #--MenuSelect("&Close", 0, GetSystemMenu($_,FALSE)); hwndSendKeys($_,"%{F4}") } sub hwndSendKeys { my ( $hwnd, $keys, $delay) = @_; $delay = 25 unless defined $delay; $delay /= 1000; my @k = Win32::GuiTest::parse_keys($keys); for ( my $i = 0; $i < @k; $i+=2) { if ( defined $k[$i]) { Win32::GuiTest::DbgShow("SendRawKey(@k[$i,$i+1])\n"); #~ Win32::GuiTest::SendRawKey( @k[$i,$i+1]); my( $key, $updown ) = @k[ $i, $i+1 ] ; my $wmupdown = WM_KEYDOWN(); $wmupdown = WM_KEYUP() if $updown == 2; Win32::GuiTest::PostMessage( $hwnd, $wmupdown, $key , 0 + ); select(undef,undef,undef,$delay); ## deprecated $i+=2; ### SUPER BROKEN otherwise DOUBLING bug } else { $k[$i+1]-> (); } } }

      Well, F4 isn't exactly ascii ...

      my idea is to use PostMessage (like hwndSendKeys does) to to send a close the window message ... WM_CLOSE

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1079247]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (8)
As of 2024-04-19 12:51 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found