in reply to Win32::GUI::TreeView and bitmap masks
So, what I did was edit the BMP in photoshop, editing the black border out to "transparent" and saved the file. This seems to work. I also created a FolderClosed.Bmp and adjusted the $tv->InsertItem calls so that you get Open Folders when it's selected and Closed Folders when unselected.
The code with just a couple changes is below along with links to the updated image files.
Good luck, I hope this helps.
Update: Per bbfu's reply, I was wrong about the transparency being in the new image. I was fooled by how photoshop treated the file and then saved it as a BMP, Sorry. I guess it was too early in the AM for me. I am looking at it further now.
Update: Ok, it's fixed, see latest files and code below: Details, Enjoy!
FolderOpen
OpenMask
FolderClosed
ClosedMask
Tree.pl
#!perl/bin/perl use warnings; use strict; use Win32::GUI; my $main = Win32::GUI::Window->new( -name => 'Main', -width => 300, -height => 250, ); # NOTE: To use bitmap masks, the flag ILC_MASK (0x0001) must be set. # Also, using a 16 color bmp seem to require ILC_COLOR16 (0x0010) my $il = Win32::GUI::ImageList->new(16, 16, 0x0011, 4, 5); # This shows the image, but it's not masked $il->Add('FolderOpen.bmp', 'FolderOpenMask.bmp'); $il->Add('FolderClosed.bmp', 'FolderClosedMask.bmp'); # As does this #$il->AddBitmap( # Win32::GUI::Bitmap->new('FolderOpen.bmp', 0), # Win32::GUI::Bitmap->new('FolderOpenMask.bmp', 0), #); # And icon files don't work at all #$il->AddBitmap(Win32::GUI::Bitmap->new('FolderOpen.ico', 1)); my $tv = $main->AddTreeView( -name => 'TreeView', -width => 280, -height => 200, -top => 10, -left => 5, -buttons => 1, -rootlines => 1, -imagelist => $il, ); # Also, this doesn't seem to work, for some reason. # The ImageList has to be passed when constructing the TreeView. # Why? #$tv->SetImageList($il, 24); my $root = $tv->InsertItem( -text => 'Foo', -indent => 1, -selected => 0, -image => 1, -selectedimage => 0, ); $tv->InsertItem( -text => 'Bar', -indent => 1, -image => 1, -selectedimage => 0, ); $tv->InsertItem( -text => 'Baz', -indent => 1, -image => 1, -selectedimage => 0, -parent => $root, ); $main->Show(1); Win32::GUI::Dialog(); sub Main_Terminate { return -1; }
|
|---|