Solved
Win32::API::Struct Question about WINDOWPLACEMENT
Posted on 2004-10-07
I am trying to reposition a window using Win32::API. I believe my struct in this case is malformed but I don't know what is malformed about it -- and the WinAPI just gives me a genertic "The parameter is incorrect.". Any advise would be great -- thanks.
--- CODE BELOW ---
use warnings;
use strict;
use Win32;
use Win32::API;
use Win32::API::Struct;
my $FindWindow = new Win32::API('user32', 'FindWindow', 'PP', 'N');
my $SetWindowPlacement = new Win32::API('user32', 'SetWindowPlacement', 'NP', 'N');
Win32::API::Struct->typedef( 'WINDOWPLACEMENT', qw(
UINT length;
UINT flags;
UINT showCmd;
POINT ptMinPosition;
POINT ptMaxPosition;
RECT rcNormalPosition;
));
Win32::API::Struct->typedef( 'POINT', qw(
LONG x;
LONG y;
));
Win32::API::Struct->typedef( 'RECT', qw(
LONG left;
LONG top;
LONG right;
LONG bottom;
));
my $window = $FindWindow->Call("Notepad", 'Untitled - Notepad');
my $UpperLeftPoint = new Win32::API::Struct->new( 'POINT' );
$UpperLeftPoint->{'x'} = 1;
$UpperLeftPoint->{'y'} = 1;
my $WindowSize = new Win32::API::Struct->new( 'RECT' );
$WindowSize->{'left'} = 1;
$WindowSize->{'top'} = 1;
$WindowSize->{'right'} = 1000;
$WindowSize->{'bottom'} = 1000;
my $WindowPlacement = new Win32::API::Struct->new( 'WINDOWPLACEMENT' );
$WindowPlacement->{'flags'} = 0;
$WindowPlacement->{'showCmd'} = 0;
$WindowPlacement->{'ptMinPosition'} = $UpperLeftPoint;
$WindowPlacement->{'ptMaxPosition'} = $UpperLeftPoint;
$WindowPlacement->{'rcNormalPosition'} = $WindowSize;
$WindowPlacement->{'length'} = $WindowPlacement->{'sizeof'};
print "Window: $window\n";
print "SetWindowPlacement: ".$SetWindowPlacement->Call($window, $WindowPlacement)."\n\n";
print "Errors (if any): ".Win32::FormatMessage(Win32::GetLastError());