Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion CHANGES
Original file line number Diff line number Diff line change
Expand Up @@ -313,4 +313,7 @@
- Fixes in tests and pod

1.63 Jan 29 2016
- Minor accumulated fixes
- Minor accumulated fixes

1.64 Oct 20 2018
- add more MSDN functions: IsIconic, IsZoomed, OpenIcon, plus RestoreWindow
65 changes: 65 additions & 0 deletions GuiTest.xs
Original file line number Diff line number Diff line change
Expand Up @@ -1721,6 +1721,71 @@ 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

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
Expand Down
122 changes: 120 additions & 2 deletions lib/Win32/GuiTest.pm
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -141,9 +141,12 @@ require DynaLoader;
GetWindowLong
GetWindowRect
GetWindowText
GetWindowPlacement
SetWindowPlacement
IsCheckedButton
IsChild
IsGrayedButton
IsIconic
IsKeyPressed
IsListViewItemSel
IsTabItemSel
Expand All @@ -152,16 +155,19 @@ require DynaLoader;
IsWindowStyle
IsWindowStyleEx
IsWindowVisible
IsZoomed
MenuSelect
MouseClick
MouseMoveAbsPix
MouseMoveWheel
NormToScreen
OpenIcon
PostMessage
PushButton
PushChildButton
PushChildById
ReadFromVirtualBuffer
RestoreWindow
ScreenToClient
ScreenToNorm
SelComboItem
Expand Down Expand Up @@ -242,7 +248,7 @@ require DynaLoader;
}
$EXPORT_TAGS{ALL}= \@EXPORT_OK;

$VERSION = '1.63';
$VERSION = '1.64';

$debug = 0;

Expand Down Expand Up @@ -1255,6 +1261,118 @@ 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 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:

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);

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 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)

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);

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)

Using the GetParent library function in a loop, returns the distance
Expand Down
6 changes: 6 additions & 0 deletions typemap
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down