Thanks for the response. One more quick question that I know has been asked before but never been answered correctly (AFAIK): Is it possible to create a transparent label? Or perhaps a better question: Is it possible to overlap two transparent images such that the transparence of the top image allows the bottom image to still be visible?

I've found that the transparency of bitmaps (icons/pngs) only seems to work on the parent window. In other words if I have one png overlapping another, the second png isn't fully visible even if the only thing covering it is the transparency of the first png. Here's some example code (you can download the "blocks.png" file from my server (http://www.robjohansen.com/blocks.png)):


##### CODE BEGIN

use strict;
use Win32::GUI qw(WS_BORDER WS_CAPTION WS_CHILD WS_CLIPCHILDREN WS_CLIPSIBLINGS WS_SIZEBOX WS_THICKFRAME);
use Win32::API;
use Win32::GUI::DIBitmap;

use constant WS_EX_LAYERED => 0x00080000;
use constant LWA_COLORKEY  => 0x00000001;
use constant LWA_ALPHA     => 0x00000002;
use constant GWL_EXSTYLE   => -20;

my $mainWindow = Win32::GUI::Window->new
(
    -background ="" [153,0,0],
    -pushstyle  => WS_CLIPCHILDREN,
    -text       => 'Test',
    -size       => [500,500],
);

my $setLayeredWindowAttributes = Win32::API->new('user32', 'SetLayeredWindowAttributes', 'LLIN', 'I');
my $winstyle = $mainWindow->GetWindowLong(GWL_EXSTYLE);
$winstyle = $winstyle | WS_EX_LAYERED;
$mainWindow->SetWindowLong(GWL_EXSTYLE, $winstyle || WS_EX_LAYERED);
$setLayeredWindowAttributes->Call($mainWindow->{-handle}, 0, 255, LWA_ALPHA);

my $transparentImage = $mainWindow->AddLabel
(
    -background ="" [153,0,0],
    -bitmap     => Win32::GUI::DIBitmap->newFromFile('blocks.png')->ConvertToBitmap(),
    -pos        => [80,80],
    -size       => [128,128],
);

my $transparentImage2 = $mainWindow->AddLabel
(
    -background ="" [153,0,0],
    -bitmap     => Win32::GUI::DIBitmap->newFromFile('blocks.png')->ConvertToBitmap(),
    -pos        => [180,180],
    -size       => [128,128],
);


my $OK = $mainWindow->AddButton
(
    -background ="" [153,0,0],
    -name => 'OK',
    -text => 'OK',
    -size => [80,25],
    -pos  => [10,10],
);

$mainWindow->Center();
$mainWindow->Show();

Win32::GUI::Dialog();

sub OK_Click
{
    Win32::GUI::Change($mainWindow => -background ="" [0,0,153]);
    Win32::GUI::Change($transparentImage => -background ="" [0,0,153]);
    Win32::GUI::Change($transparentImage2 => -background ="" [0,0,153]);
    Win32::GUI::Change($OK => -background ="" [0,0,153]);
    $mainWindow->InvalidateRect(1);
    $transparentImage->InvalidateRect(1);
    $transparentImage2->InvalidateRect(1);
    $OK->InvalidateRect(1);
}


##### CODE END


Jeremy White wrote:
Hi,

I'm not sure what you example code actually does:)? If I comment out all the code for SetLayeredWindowAttributes there is no change to the window? 

You'll probably want to set the background of the button to the same color as the window as any app with windows XP styles set will use rounded buttons.

To answer your questions, you shouldn't have any issue displaying bitmaps with transparancy, it's just a case of converting it to the correct object (I use icon's with 24 or 32 bit color). In most cases WS_CLIPCHILDREN will remove flicker on resize, but there is also a -noflicker option that works in some cases (it uses double buffering). Flicker free child windows with scroll bars are no problem as WS_CLIPCHILDREN will solve the flicker issue.   

Regards,

jez.


Date: Tue, 19 Oct 2010 23:44:55 -0600
From: rob.johan...@gmail.com
To: perl-win32-gui-users@lists.sourceforge.net
Subject: [perl-win32-gui-users] Robust Windows

Hi all,

I'm trying to come up with the best approach for creating aesthetically pleasing windows that:

- Have labels whose bitmap has transparency (.png files loaded by DIBitmap)
- Don't exhibit any flicker
- Are layered windows (this seems to improve quality during animation/transparency)
- Support child windows that can be scrolled and don't flicker

Below is the code I've come up with so far (without bitmap labels). Is there anything else I should consider? Could I be doing something better?


########## CODE BEGIN

use strict;
use Win32::GUI qw(WS_CLIPCHILDREN);
use Win32::API;

use constant WS_EX_LAYERED => 0x00080000;
use constant LWA_COLORKEY  => 0x00000001;
use constant LWA_ALPHA     => 0x00000002;
use constant GWL_EXSTYLE   => -20;

my $main = Win32::GUI::Window->new
(
    -background ="" [153,0,0],
    -pushstyle => WS_CLIPCHILDREN,
    -text      => 'Test',
    -size      => [500,500],
);

my $setLayeredWindowAttributes = Win32::API->new('user32', 'SetLayeredWindowAttributes', 'LLIN', 'I');
my $winstyle = $main->GetWindowLong(GWL_EXSTYLE);
$winstyle = $winstyle | WS_EX_LAYERED;
$main->SetWindowLong(GWL_EXSTYLE, $winstyle || WS_EX_LAYERED);
$setLayeredWindowAttributes->Call($main->{-handle}, 0, 255, LWA_ALPHA);

my $OK = $main->AddButton
(
    -name => 'OK',
    -text => 'OK',
    -size => [80,25],
    -pos  => [10,10],
);

$main->Center();
$main->Show();
Win32::GUI::Dialog();

########## CODE END


Thanks,
Rob

------------------------------------------------------------------------------ Download new Adobe(R) Flash(R) Builder(TM) 4 The new Adobe(R) Flex(R) 4 and Flash(R) Builder(TM) 4 (formerly Flex(R) Builder(TM)) enable the development of rich applications that run across multiple browsers and platforms. Download your free trials today! http://p.sf.net/sfu/adobe-dev2dev
_______________________________________________ Perl-Win32-GUI-Users mailing list Perl-Win32-GUI-Users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/perl-win32-gui-users http://perl-win32-gui.sourceforge.net/
------------------------------------------------------------------------------
Nokia and AT&T present the 2010 Calling All Innovators-North America contest
Create new apps & games for the Nokia N8 for consumers in  U.S. and Canada
$10 million total in prizes - $4M cash, 500 devices, nearly $6M in marketing
Develop with Nokia Qt SDK, Web Runtime, or Java and Publish to Ovi Store 
http://p.sf.net/sfu/nokia-dev2dev
_______________________________________________
Perl-Win32-GUI-Users mailing list
Perl-Win32-GUI-Users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/perl-win32-gui-users
http://perl-win32-gui.sourceforge.net/

Reply via email to