From 295d068a8883bb27f8920897695129aa94d236a9 Mon Sep 17 00:00:00 2001 From: "U-CORP\\konovv" Date: Sat, 20 Oct 2018 14:33:32 +0000 Subject: [PATCH 1/4] add more MSDN functions: IsIconic, IsZoomed, OpenIcon, plus RestoreWindow; increase version --- CHANGES | 5 ++++- GuiTest.xs | 42 ++++++++++++++++++++++++++++++++++++++++++ lib/Win32/GuiTest.pm | 26 +++++++++++++++++++++++++- 3 files changed, 71 insertions(+), 2 deletions(-) diff --git a/CHANGES b/CHANGES index e322144..6c1cb24 100644 --- a/CHANGES +++ b/CHANGES @@ -313,4 +313,7 @@ - Fixes in tests and pod 1.63 Jan 29 2016 - - Minor accumulated fixes \ No newline at end of file + - Minor accumulated fixes + +1.64 Oct 20 2018 + - add more MSDN functions: IsIconic, IsZoomed, OpenIcon, plus RestoreWindow diff --git a/GuiTest.xs b/GuiTest.xs index fb42e1f..90bdde8 100644 --- a/GuiTest.xs +++ b/GuiTest.xs @@ -1721,6 +1721,48 @@ CODE: OUTPUT: RETVAL +int +IsIconic(hWnd) + HWND hWnd; +CODE: + RETVAL = IsIconic(hWnd); +OUTPUT: + RETVAL + +int +IsZoomed(hWnd) + HWND hWnd; +CODE: + RETVAL = IsZoomed(hWnd); +OUTPUT: + RETVAL + +int +OpenIcon(hWnd) + HWND hWnd; +CODE: + RETVAL = OpenIcon(hWnd); +OUTPUT: + RETVAL + +int +RestoreWindow(hWnd) + HWND hWnd; +PREINIT: + WINDOWPLACEMENT wndpl; +CODE: + if (GetWindowPlacement(hWnd, &wndpl)) { + wndpl.showCmd = SW_RESTORE; + if (SetWindowPlacement(hWnd, &wndpl)) { + RETVAL = 1; + } else { + RETVAL = 0; + } + } else { + RETVAL = 1; /* error */ + } +OUTPUT: + RETVAL ##################################################################### # Waits for input idle for the application, which owns the window diff --git a/lib/Win32/GuiTest.pm b/lib/Win32/GuiTest.pm index 68ab2d1..6240534 100644 --- a/lib/Win32/GuiTest.pm +++ b/lib/Win32/GuiTest.pm @@ -144,6 +144,7 @@ require DynaLoader; IsCheckedButton IsChild IsGrayedButton + IsIconic IsKeyPressed IsListViewItemSel IsTabItemSel @@ -152,16 +153,19 @@ require DynaLoader; IsWindowStyle IsWindowStyleEx IsWindowVisible + IsZoomed MenuSelect MouseClick MouseMoveAbsPix MouseMoveWheel NormToScreen + OpenIcon PostMessage PushButton PushChildButton PushChildById ReadFromVirtualBuffer + RestoreWindow ScreenToClient ScreenToNorm SelComboItem @@ -242,7 +246,7 @@ require DynaLoader; } $EXPORT_TAGS{ALL}= \@EXPORT_OK; -$VERSION = '1.63'; +$VERSION = '1.64'; $debug = 0; @@ -1255,6 +1259,26 @@ Using the corresponding library function (see MSDN) it returns true if the second window is an immediate child or a descendant window of the first window. +=item BOOL IsIconic(hWnd) * + +Using the corresponding library function (see MSDN) it returns true +if the window is minimised (iconic state). + +=item BOOL OpenIcon(hWnd) * + +Using the corresponding library function (see MSDN) it opens iconised window +and returns result true if successful. + +=item BOOL IsZoomed(hWnd) * + +Using the corresponding library function (see MSDN) it returns true +if the window is maximised. + +=item BOOL RestoreWindow(hWnd) * + +Makes window into its restore state (SW_RESTORE), returns true +if successful. + =item $depth = GetChildDepth(hAncestor,hChild) Using the GetParent library function in a loop, returns the distance From fad7406084352ebe0f86985f746f86e60a2e7bf2 Mon Sep 17 00:00:00 2001 From: "U-CORP\\konovv" Date: Sun, 21 Oct 2018 19:04:57 +0000 Subject: [PATCH 2/4] Get/Set-WindowPlacement --- GuiTest.xs | 23 +++++++++++++++++++++++ lib/Win32/GuiTest.pm | 22 +++++++++++++++++++++- typemap | 6 ++++++ 3 files changed, 50 insertions(+), 1 deletion(-) diff --git a/GuiTest.xs b/GuiTest.xs index 90bdde8..d6305c0 100644 --- a/GuiTest.xs +++ b/GuiTest.xs @@ -1764,6 +1764,29 @@ CODE: OUTPUT: RETVAL +bool +GetWindowPlacement(hWnd, svwndpl) + HWND hWnd; + SV *svwndpl; +PREINIT: + WINDOWPLACEMENT wndpl; +CODE: + if (!(SvROK(svwndpl) && (svwndpl = SvRV(svwndpl)) )) + croak("Second argument to GetWindowPlacement(...) must be a reference to scalar"); + RETVAL = GetWindowPlacement(hWnd, &wndpl); + sv_setpvn(svwndpl, (const char *)&wndpl, sizeof(WINDOWPLACEMENT)); +OUTPUT: + RETVAL + +bool +SetWindowPlacement(hWnd, wndpl) + HWND hWnd; + WINDOWPLACEMENT wndpl; +CODE: + RETVAL = SetWindowPlacement(hWnd, &wndpl); +OUTPUT: + RETVAL + ##################################################################### # Waits for input idle for the application, which owns the window # hWnd. It is a wrapper around WaitForInputIdle Win32 API. diff --git a/lib/Win32/GuiTest.pm b/lib/Win32/GuiTest.pm index 6240534..8674393 100644 --- a/lib/Win32/GuiTest.pm +++ b/lib/Win32/GuiTest.pm @@ -26,7 +26,7 @@ Win32::GuiTest - Perl GUI Test Utilities. // it first might help with various compilation problems. vcvars32.bat - perl makefile.pl + perl Makefile.PL nmake nmake test nmake install @@ -141,6 +141,8 @@ require DynaLoader; GetWindowLong GetWindowRect GetWindowText + GetWindowPlacement + SetWindowPlacement IsCheckedButton IsChild IsGrayedButton @@ -1279,6 +1281,24 @@ if the window is maximised. Makes window into its restore state (SW_RESTORE), returns true if successful. +=item BOOL GetWindowPlacement(hWnd, \WINDOWPLACEMENT) + +Using the corresponding library function (see MSDN) it returns true +if the call to GetWindowPlacement is succesful. Scalar reference should be +passed as second argument, where WINDOWPLACEMENT structure will be copied, +which then could be used in consequent calls to SetWindowPlacement, or other. + +=item BOOL SetWindowPlacement(hWnd, WINDOWPLACEMENT) + +Using the corresponding library function (see MSDN) it returns true +if the call to SetWindowPlacement is succesful. WINDOWPLACEMENT should be obtained +previously by calls to GetWindowPlacement: + + Win32::GuiTest::GetWindowPlacement($w,\my $wpl); + sleep 5; # time passes + Win32::GuiTest::SetWindowPlacement($w,$wpl); + + =item $depth = GetChildDepth(hAncestor,hChild) Using the GetParent library function in a loop, returns the distance diff --git a/typemap b/typemap index cb80e76..cb03ddc 100644 --- a/typemap +++ b/typemap @@ -2,6 +2,7 @@ BOOL T_IV LONG T_IV HANDLE T_IV HWND T_IV +WINDOWPLACEMENT T_WINDOWPLACEMENT HMENU T_IV HKEY T_IV SECURITY_INFORMATION T_UV @@ -19,6 +20,11 @@ DibSect * O_OBJECT INPUT T_UV $var = ($type)SvUV($arg) +T_WINDOWPLACEMENT + if (SvTYPE($arg)==SVt_PV) + memcpy(&$var,SvPV_nolen($arg), sizeof(WINDOWPLACEMENT)); + else + croak(\"$var should be WiNDOWPLACEMENT, perl scalar\") ############################################################################# OUTPUT From a3668a35ce29f32aaa1c9f2e5c1cb6b60370832c Mon Sep 17 00:00:00 2001 From: "U-CORP\\konovv" Date: Tue, 23 Oct 2018 10:05:17 +0000 Subject: [PATCH 3/4] user-frendly higher level Get/Set-WindowPlacement --- GuiTest.xs | 4 +-- lib/Win32/GuiTest.pm | 78 +++++++++++++++++++++++++++++++++++++++++--- 2 files changed, 75 insertions(+), 7 deletions(-) diff --git a/GuiTest.xs b/GuiTest.xs index d6305c0..d9b1830 100644 --- a/GuiTest.xs +++ b/GuiTest.xs @@ -1765,7 +1765,7 @@ OUTPUT: RETVAL bool -GetWindowPlacement(hWnd, svwndpl) +_GetWindowPlacement(hWnd, svwndpl) HWND hWnd; SV *svwndpl; PREINIT: @@ -1779,7 +1779,7 @@ OUTPUT: RETVAL bool -SetWindowPlacement(hWnd, wndpl) +_SetWindowPlacement(hWnd, wndpl) HWND hWnd; WINDOWPLACEMENT wndpl; CODE: diff --git a/lib/Win32/GuiTest.pm b/lib/Win32/GuiTest.pm index 8674393..a508dd8 100644 --- a/lib/Win32/GuiTest.pm +++ b/lib/Win32/GuiTest.pm @@ -1281,23 +1281,91 @@ if the window is maximised. Makes window into its restore state (SW_RESTORE), returns true if successful. -=item BOOL GetWindowPlacement(hWnd, \WINDOWPLACEMENT) +=item my $hashref = GetWindowPlacement(hWnd); + +Returns following hash reference: + { + length => $length, # == 44 + flags => $flags, + showCmd => $showCmd, + ptMinPosition => [$x0,$y0], + ptMaxPosition => [$x1,$y1], + rcNormalPosition => [$x0,$y0,$x1,$y1], + rcDevice => [$x0,$y0,$x1,$y1], + } +which then could be modified and used in consequent calls to SetWindowPlacement. +Uses _GetWindowPlacement internally. + +=item BOOL SetWindowPlacement(hWnd, $hashref); + +Uses _SetWindowPlacement internally. + +=item BOOL _GetWindowPlacement(hWnd, \WINDOWPLACEMENT) Using the corresponding library function (see MSDN) it returns true -if the call to GetWindowPlacement is succesful. Scalar reference should be +if the call to GetWindowPlacement is succesful. Scalar reference is passed as second argument, where WINDOWPLACEMENT structure will be copied, which then could be used in consequent calls to SetWindowPlacement, or other. +You should better use higher level function GetWindowPlacement. -=item BOOL SetWindowPlacement(hWnd, WINDOWPLACEMENT) +=item BOOL _SetWindowPlacement(hWnd, WINDOWPLACEMENT) Using the corresponding library function (see MSDN) it returns true if the call to SetWindowPlacement is succesful. WINDOWPLACEMENT should be obtained previously by calls to GetWindowPlacement: - Win32::GuiTest::GetWindowPlacement($w,\my $wpl); + Win32::GuiTest::i_GetWindowPlacement($w,\my $wpl); sleep 5; # time passes - Win32::GuiTest::SetWindowPlacement($w,$wpl); + Win32::GuiTest::_SetWindowPlacement($w,$wpl); + +You should better use higher level function SetWindowPlacement. + +=cut +sub GetWindowPlacement +{ + my $hwnd = shift; + if (_GetWindowPlacement($hwnd, \my $wndpl)) { + # https://docs.microsoft.com/en-us/windows/desktop/api/winuser/ns-winuser-tagwindowplacement + # WINDOWPLACEMENT structure: + # UINT length; + # UINT flags; + # UINT showCmd; + # POINT ptMinPosition; + # POINT ptMaxPosition; + # RECT rcNormalPosition; + # RECT rcDevice; + my ($length, $flags, $showCmd, $ptMinPosition, $ptMaxPosition, + $rcNormalPosition, $rcDevice) = unpack('LLLa8a8a16a16', $wndpl); + return { + length => $length, # == 44 + flags => $flags, + showCmd => $showCmd, + ptMinPosition => [unpack('ll',$ptMinPosition)], + ptMaxPosition => [unpack('ll',$ptMaxPosition)], + rcNormalPosition => [unpack('llll',$rcNormalPosition)], + rcDevice => [unpack('llll',$rcDevice)], + }; + } + undef; +} + +sub SetWindowPlacement +{ + my ($hwnd, $href) = @_; + my $wndpl = pack('LLLl12', + $href->{length}, # == 44 + $href->{flags}, + $href->{showCmd}, + @{$href->{ptMinPosition}}, + @{$href->{ptMaxPosition}}, + @{$href->{rcNormalPosition}}, + @{$href->{rcDevice}}, + ); + return _SetWindowPlacement($hwnd, $wndpl); +} + +=pod =item $depth = GetChildDepth(hAncestor,hChild) From bdd4ca63524d258764f5136c0e694ef0b603d8b5 Mon Sep 17 00:00:00 2001 From: "U-CORP\\konovv" Date: Tue, 23 Oct 2018 10:14:58 +0000 Subject: [PATCH 4/4] ... with better documentation --- lib/Win32/GuiTest.pm | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/lib/Win32/GuiTest.pm b/lib/Win32/GuiTest.pm index a508dd8..7a11a31 100644 --- a/lib/Win32/GuiTest.pm +++ b/lib/Win32/GuiTest.pm @@ -1293,7 +1293,13 @@ Returns following hash reference: rcNormalPosition => [$x0,$y0,$x1,$y1], rcDevice => [$x0,$y0,$x1,$y1], } -which then could be modified and used in consequent calls to SetWindowPlacement. +which then could be modified and used in consequent calls to SetWindowPlacement: + + my $h = Win32::GuiTest::GetWindowPlacement($w); + $h->{rcNormalPosition}->[0] += 50; + $h->{rcNormalPosition}->[2] += 50; + Win32::GuiTest::SetWindowPlacement($w,$h); + Uses _GetWindowPlacement internally. =item BOOL SetWindowPlacement(hWnd, $hashref); @@ -1314,7 +1320,7 @@ Using the corresponding library function (see MSDN) it returns true if the call to SetWindowPlacement is succesful. WINDOWPLACEMENT should be obtained previously by calls to GetWindowPlacement: - Win32::GuiTest::i_GetWindowPlacement($w,\my $wpl); + Win32::GuiTest::_GetWindowPlacement($w,\my $wpl); sleep 5; # time passes Win32::GuiTest::_SetWindowPlacement($w,$wpl);