For Programmers: Free Programming Magazines  


Home > Archive > PerlTk > August 2004 > Transparent Perl/Tk Window: Win32::API SetLayeredWindowAttributes









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Transparent Perl/Tk Window: Win32::API SetLayeredWindowAttributes
e

2004-07-30, 3:56 pm

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";
}
e

2004-08-03, 9:05 am

Fred Toewe wrote:

>
> Works about the same for me on WinXP PRO, Perl 5.8.4m, Tk 900.024. My
> output is:
>
> C:\Documents and Settings\Toewe\My Documents\Temp>trans.pl
> swl 2304
> slwa 0 127
> swl 526592
> slwa 0 127
> swl 526592
> slwa 0 127
> swl 526592
> slwa 0 127
>


Funny thing is.. I took a 3rd party app that is supposed to let you
make any window transparent... and it doesn't work on perl/tk windows.
So.. looks like it is a tk issue...

http://www.chime.tv/products/glass2k.shtml is the 3rd party app.

Eric
Jeff Hobbs

2004-08-07, 8:56 pm

e wrote:

> 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."


This won't work in Tk, because you actually need a different
type of window class. I'm not sure that the MSDN specifies
this, but I found out the MSDN docs were insufficient when
actually implementing this functionality. You can find a
patch for it in the 'tktoolkit' SF project (core Tk dev area).
This is for Tcl/Tk, but you can apply it to the Perl/Tk
sources without too many changes I expect.

--
Jeff Hobbs
http://www.ActiveState.com/, a division of Sophos
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2010 codecomments.com