I played around with this for a while and got it to work, although I am not certain that I did it "properly" or not. The documentation does not make the requirements clear, at least not to me. ;) As far as I can tell at the moment the Mask BMP is irrelevant, and seems to be optional according to the doc. I did not take the time to delve into the MS Doc to see what may be happening under the hood, I may do that later out of curiosity ;-)

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

In reply to Re: Win32::GUI::TreeView and bitmap masks by knexus
in thread Win32::GUI::TreeView and bitmap masks by bbfu

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.