Win32::API SetLayeredWindowAttributes for Transparent Perl/Tk Window
From: e (e_at_corvairproject.com)
Date: 07/30/04
- Next message: David Marshall: "HTML::Form, Multiple select Elements with Same name"
- Previous message: Amir Karger: "Namespace for Z-machine parse/translate module"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Fri, 30 Jul 2004 10:43:16 -0600
I'm playing around, trying to make my perl/tk window transparent with
the help of Win32::API. I've researched on msdn, and figured out all
the calls I need to make - but all of my calls to
SetLayeredWindowAttributes seem to fail (the function returns 0, and
seems to set an error of '127' which is "The specified procedure could
not be found."
What interests me is the third parameter of SetLayeredWindowAttributes
according to msdn, is a BYTE... but Win32::API doesn't seem to support
parameters of byte so I am declaring the third parameter as a char.
For the record, I am running Windows XP, ActiveState Perl 5.6.1 build 638.
Has anybody had luck doing this? An example is below:
#!/usr/local/bin/perl -w
use Tk;
use Win32::API;
my $Main = new MainWindow;
$Main->configure(-title => "poo");
my $f = $Main->Frame(qw(-relief sunken -borderwidth 1 ));
$f->pack(qw(-fill both -expand 1));
$f->Button(-text => 'Trans', -command => \&trans)->pack();
MainLoop;
sub trans {
my $WS_EX_LAYERED = hex(80000);
my $GWL_EXSTYLE = (-20);
my $LWA_ALPHA = hex(2);
my $FindWindow = new Win32::API("user32", "FindWindow", [P,P], N);
my $GetLastError = new Win32::API("kernel32","GetLastError",'',N);
my $UpdateWindow = new Win32::API("user32","UpdateWindow",[N],N);
my $GetWindowLong = new Win32::API("user32","GetWindowLong",[N,I],N);
my $SetWindowLong = new Win32::API("user32","SetWindowLong",[N,I,N],N);
my $SetLayeredWindowAttributes = new Win32::API("user32",
"SetLayeredWindowAttributes",[N,N,C,N],N);
my $class = "TkTopLevel";
my $name = $Main->title;
my $topHwnd = $FindWindow->Call($class, $name);
my $swl = $SetWindowLong->Call($topHwnd, $GWL_EXSTYLE,
($GetWindowLong->Call($topHwnd, $GWL_EXSTYLE) | $WS_EX_LAYERED));
print "swl $swl\n";
my $slwa = $SetLayeredWindowAttributes->Call($topHwnd, 0, 179,
$LWA_ALPHA);
my $err= $GetLastError->Call();
print "slwa $slwa $err\n";
}
- Next message: David Marshall: "HTML::Form, Multiple select Elements with Same name"
- Previous message: Amir Karger: "Namespace for Z-machine parse/translate module"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]