Hello perl-win32-gui-users,

I'm trying to change the TextColor of a Coolmenu on _Deactivate and
_Activate of the parent-window to emulate the original IE behaviour.
In my understanding of the MSDN-documentation a Toolbar-Control,
receiving a NM_CUSTOMDRAW-notification, should behave in exactly the
same way as a Header does. But in contrast to a Header the DC, supplied
in the NMTBCUSTOMDRAW-structure, seems not to be the one being used to
paint the control (see example below).
On the other hand, when returning CDRF_SKIPDEFAULT, the DC you get can
be used to draw the ToolbarItems on your own (but I'm definitely too
lazy to do so).

Any suggestions?

TIA
Uwe

#!perl -w

use strict;
use Win32::GUI;

my $mw = new Win32::GUI::Window
     (  -name           =>  'MainWindow',
        -text           =>  'CustomDraw',
        -pos            =>  [ 100, 100 ],
        -size           =>  [ 300, 350 ],

        -onTerminate    =>  sub { -1 },
        -onDeactivate   =>  sub { $_ [ 0 ] -> InvalidateRect ( 0 ) },
        -onActivate     =>  sub { $_ [ 0 ] -> InvalidateRect ( 0 ) },
     );

my $ft = new Win32::GUI::Font
     (  -name           =>  'Font',
        -size           =>  8,
        -face           =>  'Tahoma',
);

my $tb = $mw -> AddToolbar
     (  -name           =>  'Toolbar',
        -pos            =>  [ 0, 0 ],
        -size           =>  [ $mw -> ScaleWidth (), 23 ],
        -font           =>  $ft,
        -nodivider      =>  1,
        -flat           =>  1,
        -list           =>  1,
        -pushstyle      =>  12,

        -onButtonClick  =>  sub { $mw-> { 'ListBox' } -> ResetContent () },
     );

for ( 0 .. 3 )
{
    $tb -> AddString  ( "Test $_" );
    $tb -> AddButtons ( 1, -2, 1000 + $_, 4,  88, $_ );
}

my $hd = $mw -> AddHeader
     (  -name           =>  'Header',
        -pos            =>  [ 0, $tb -> Height () ],
        -size           =>  [ $mw -> ScaleWidth (),
                              20
                            ],
        -font           =>  $ft,
        -buttons        =>  1,
     );

for ( 0 .. 2 )
{
    $hd -> InsertItem
         (  -index          =>  $_ ,
            -text           =>  "Test $_",
            -width          =>  $hd -> ScaleWidth () / 3,
         );
}

my $lb = $mw-> AddListbox
(       -name           =>  'ListBox',
        -pos            =>  [ 0, $tb -> Height () + $hd -> Height () ],
        -size           =>  [ $mw -> ScaleWidth (),
                              $mw -> ScaleHeight () - $tb -> Height ()
                                                    - $hd -> Height ()
                            ],
);

$hd -> Hook ( -12, \&onCustumDraw );
$tb -> Hook ( -12, \&onCustumDraw );

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

sub onCustumDraw
{
    my ($object, $wparam, $lparam, $message_type, $message_code ) = @_;

    ( return () ) unless ( $message_type == 78 );
    ( return () ) unless ( $message_code == -12 );

    my $pNMTBCD = pack (  'L!', $lparam );
    my $sNMTBCD = unpack( 'P20', $pNMTBCD );
    my ($dwDrawStage, $dc ) = unpack ( 'x12IL', $sNMTBCD );

    if ( $dwDrawStage == 1 )
    {
        $object -> Result ( 32 );
    }
    elsif ( $dwDrawStage == 65537 )
    {
        $lb -> Add ( ref ( $object ) . '          ' . $dc . '          ' .
                     Win32::GUI::DC::GetTextFace ( $dc )
                   );
        $lb -> FirstVisibleItem ( $lb -> Count () - 20 );

        ( $mw -> { '-handle' } == Win32::GUI::GetActiveWindow () )
            ?   ( Win32::GUI::DC::TextColor ( $dc, 0x00000000 ) )
            :  ( Win32::GUI::DC::TextColor ( $dc, 0x00808080 ) );
    }

    return ( 0 );
}
__END__

Reply via email to