On 27/01/2008, Waldemar Biernacki <[EMAIL PROTECTED]> wrote:
> Thank you Robert,
>
> Now I resolved the problem putting many square bitmap buttons. The result is
> OK. But I would be more happy if I cound put transparent (for instance ico
> files) instead od bmp files. Is it possible? (I've tried to use all the
> machinary but I haven't got any image...)

When asking me for on-topic help, please keep the conversation on list
so that everyone else can see the reply and the answers get archive
(hopefully preventing me from having to answer questions multiple
times).

I'm not entirely clear what you want.  I think I've posted the code
below to the list before.  It shows how to use an ImageList of type
ILS_MASKED to generate transparent button images.  IIRC you have to
have toolbars with the 'flat' style.  The transparent parts of the
image in this case are defined by a specific colour, and the
background is shown when the button is hovered over ('hot'), or is
selected.

I don't have examples, but it is possible to create ImageLists that
use a secondary image to determine where the transparent parts should
be ... an exercise for the reader?

Regards,
Rob.

#!perl -w
# A demo of the toolbar capabilities.
# Here is a list of things that I haven't yet made work or might be
useful to add
# - get the customisation to work.  Needs research on exactly which
notifications need handling
#   Simply setting CCS_ADJUSTABLE style does not seem to be enough
# - handle the tooltip request for text - needs a handler like
NeedsText in tooltip.xs
# - extend model to allow passing I_IMAGECALLBACK as bitmap reference
in AddButton to get toolbar to
#   issue TBN_GETDISPINFO to retrieve image index.
# - toolbar.xs comments on AddString suggests that AddString should
accept a list of strings.  This should
#   be fixed (or perhaps better to add method AddStrings() that does)
# - would be nice if AddButtons STRING field could be a string as well
as an index.

use strict;
use warnings;

use Win32::GUI 1.05 qw(:toolbar ILC_MASK);
use Win32::GUI::BitmapInline ();

sub IMAGE_X() {16}; # X dimension for buttons in our toolbar
sub IMAGE_Y() {15}; # Y dimension for images in our toolbar

# Create a menu - that we'll use for the drop-down menu from the toolbar
# buttons.
my $menu = Win32::GUI::Menu->new(
    "" => "PopUpMenu",
    "> MenuItem&1" => { -name => "MI1", -onClick => sub { print
"MenuItem1 clicked\n";} },
    "> MenuItem&2" => { -name => "MI2", -onClick => sub { print
"MenuItem2 clicked\n";} },
    "> -"          => 0,
    "> MenuItem&3" => { -name => "MI3", -onClick => sub { print
"MenuItem3 clicked\n";} },
);
my $popupmenu = $menu->{PopUpMenu};

# Main Window
my $mw = Win32::GUI::Window->new(
        -title => "Toolbar Demo",
        -size => [500,300],
);

# A bitmap for our toolbar
my $bmp = new Win32::GUI::BitmapInline( q(
Qk0GAwAAAAAAADYAAAAoAAAAEAAAAA8AAAABABgAAAAAANACAADEDgAAxA4AAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA////////////
////////////////////////////////////////////AAAAAAAA////////////////AAAAAAAA
AAAAAAAAAAAAAAAA////////////////AAAAAAAA////////////////////////AAAAAAAA////
////////////////////AAAAAAAA////////////////////////AAAAAAAA////////////////
////////AAAAAAAA////////////////////////AAAAAAAA////////////////////////AAAA
AAAA////////////////////////AAAAAAAA////////////////////////AAAAAAAA////////
////////////////AAAAAAAA////////////////////////AAAAAAAA////////////////////
////AAAAAAAA////////////////////////AAAAAAAA////////////////////////AAAAAAAA
////////////////////////AAAAAAAA////////////////AAAAAAAAAAAAAAAA////////////
////////////AAAAAAAA////////////////////AAAAAAAAAAAA////////////////////////
AAAAAAAA////////////////////////AAAAAAAA////////////////////////AAAAAAAA////
////////////////////////////////////////////////////AAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
) );

# A masked imagelist to put the toolbar buttons into
my $images = Win32::GUI::ImageList->new(
        IMAGE_X,
        IMAGE_Y,
        ILC_MASK,
        1,
        1,
);

# Add the bitmap to the imagelist, generating the mask from the
background colour (0xFFFFFF)
$images->AddBitmapMasked($bmp, 0xFFFFFF);

# Add a toolbar to the main window
# TBSTYLE_LIST - puts label captions to the right of the labels,
rather than below the labels
# TBSTYLE_TOOLTIPS - creates a tooltip control to manage tooltips
associated with the toolbar
my $tools = $mw->AddToolbar(
        -imagelist => $images,
    -flat => 1,
        #-pushstyle => CCS_ADJUSTABLE,
        -pushstyle => TBSTYLE_LIST,
        -pushstyle => TBSTYLE_TOOLTIPS,
        -onButtonClick => \&ToolbarButtonClick,
);

# Set extended syles.  It took me a long time to determine that this was NOT
# the same as using -pushexstyle on the AddToolbar method.
# TBSTYLE_EX_DRAWDDARROWS - causes drop down arrows to be drawn to the
right of toolbar icons
# TBSTYLE_EX_MIXEDBUTTONS - causes the text associated with a button
not to be drawn, unless the
#  button has the BTNS_SHOWTEXT style.  Instead the text is used by
default for the tooltip(this
#  behaviour can be stopped by processing the TBN_GETTIPINFO notification)
$tools->SetExtendedStyle(TBSTYLE_EX_DRAWDDARROWS|TBSTYLE_EX_MIXEDBUTTONS);

# Add some strings to the toolbars string table
$tools->AddString("Button 1");
$tools->AddString("Button 2 - on/off");
$tools->AddString("Button 3 - group");
$tools->AddString("Button 4 - group");
$tools->AddString("Button 5 - dropdown");
$tools->AddString("DropMenu");

# Add the buttons
# BITMAP is a zero-based index to the image in the toolbar's image
list, except when
#  STYLE is TBSTYLE_SEP.  In this case it is the spacing on either
side of the seperator
#  in pixels.
# COMMAND is an (application-wide) unique number.
# STRING is a zero-based index into the tooltip's string table
$tools->AddButtons(
        8,
        # BITMAP, COMMAND, STATE,                           STYLE,
           STRING
        0,        1,       TBSTATE_ENABLED,                 TBSTYLE_BUTTON,
                0,
        0,        2,       TBSTATE_ENABLED,                 TBSTYLE_CHECK,
                1,
        20,       0,       TBSTATE_ENABLED,                 TBSTYLE_SEP,
                0,
        0,        3,       TBSTATE_ENABLED|TBSTATE_CHECKED,
TBSTYLE_CHECK|TBSTYLE_GROUP,      2,
        0,        4,       TBSTATE_ENABLED,
TBSTYLE_CHECK|TBSTYLE_GROUP,      3,
        20,       0,       TBSTATE_ENABLED,                 TBSTYLE_SEP,
                0,
        0,        5,       TBSTATE_ENABLED,                 TBSTYLE_DROPDOWN,
                4,
        0,        6,       TBSTATE_ENABLED,
BTNS_WHOLEDROPDOWN|BTNS_SHOWTEXT, 5,
);

# Adjuxt the button sizes for the text and images
$tools->AutoSize();

$mw->Show();
Win32::GUI::Dialog();
exit(0);

sub ToolbarButtonClick
{
  my ($self, $index, $drawmenu) = @_;

  print "Toolbar:  Button index: $index, Draw menu: $drawmenu\n";

  if($drawmenu) {
    # Button has the TBSTYLE_DROPDOWN or BTNS_WHOLEDROPDOWN style

    # Get the button corners, and convert to screen co-ordinates
    my ($l, $t, $r, $b) = $self->GetRect($index);
    ($l, $t) = $self->ClientToScreen($l, $t);
    ($r, $b) = $self->ClientToScreen($r, $b);

    # Display and interact with the popup menu.
    $self->TrackPopupMenu($popupmenu, $l, $b, $l, $t, $r, $b);
  }

  return 1;
}
__END__

-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
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