RE: [perl-win32-gui-users] DC used for customdrawn Toolbar
I've tucked this code away to add to Coolbar.pm when I next get back to it. For both of your examples I was getting an error on exit - invalid methods on global destruction. Both were failing in onDeactivate event - to get round it I had to add the following: return unless $_[0]; to the first line of the event handler. I'm on 5.6.1, latest code line. Cheers, jez.
RE: [perl-win32-gui-users] DC used for customdrawn Toolbar
Hi, I'm trying to change the TextColor of a Coolmenu on _Deactivate and _Activate of the parent-window to emulate the original IE behaviour. Just so I understand what you are trying to do. Do you mean the change in the menu colour (to blue) when the mouse moves over the menu buttons in IE? 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). The structures used by a toolbar and header are different - see: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/shellcc/platform/commctls/custdraw/custdraw.asp This may, or may not be causing your problem. I assume that you are using the coolbar module by Rob May (http://www.robmay.me.uk/win32gui/)? It also exhibits the same issue that I think you are trying to solve. It might be worth pooling efforts to get this issue 'fixed' - off the top of my head, perhaps the easiest solution would be to add an CustomDraw event handler in ToolBar.xs which would pass the correct parameters (DC and draw codes) to the Perl handler. Cheers, jez.
RE: [perl-win32-gui-users] DC used for customdrawn Toolbar
Hi jez, Just so I understand what you are trying to do. Do you mean the change in the menu colour (to blue) when the mouse moves over the menu buttons in IE? I want to 'grey out' the text when $mw loses the focus. The structures used by a toolbar and header are different - see: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/shellcc/pla tform/commctls/custdraw/custdraw.asp This may, or may not be causing your problem. I assume that you are using the coolbar module by Rob May (http://www.robmay.me.uk/win32gui/)? It also exhibits the same issue that I think you are trying to solve. It might be worth pooling efforts to get this issue 'fixed' - off the top of my head, perhaps the easiest solution would be to add an CustomDraw event handler in ToolBar.xs which would pass the correct parameters (DC and draw codes) to the Perl handler. I read this article. The relevant bytes of the structures being used should be identical. Ok, I'll try to patch the ToolBar.xs, but nevertheless I'd really like to know what's the error in the provided example. Regards Uwe
RE: [perl-win32-gui-users] DC used for customdrawn Toolbar
Kind, Uwe wrote: Just so I understand what you are trying to do. Do you mean the change in the menu colour (to blue) when the mouse moves over the menu buttons I want to 'grey out' the text when $mw loses the focus. The structures used by a toolbar and header are different This appears to be key. It looks like the toolbar that uses the new NMTBCUSTOMDRAW structure (comctl32.dll 4.70) ignores colors you set in the DC. This behaviour is documented for ListViews ... but it appears not for toolbars. Setting the clrText member of the new structure seems to work a treat. I've tucked this code away to add to Coolbar.pm when I next get back to it. Regards, Rob. #!perl -w use strict; use warnings; use Win32::GUI 1.02; use Win32::API; sub I_IMAGENONE() {-2}; sub NM_CUSTOMDRAW() {-12}; sub WM_NOTIFY() {0x4E}; sub CDDS_PREPAINT() {1}; sub CDDS_ITEMPREPAINT() {65537}; sub CDRF_NOTIFYITEMDRAW() {32}; sub CDRF_DODEFAULT() {0}; sub CDRF_NEWFONT(){2}; sub RDW_INVALIDATE() {1}; # Win32::API call that we want, defined the old way for maximum # backwards compatability with Win32::API my $CopyMemory = Win32::API-new(kernel32, RtlMoveMemory, NPI, V) or die Can't find CopyMemory; my $mw = Win32::GUI::Window-new( -name = 'MainWindow', -text = 'CustomDraw', -pos = [ 100, 100 ], -size = [ 300, 350 ], -onActivate = sub { $_[0]-Toolbar-Redraw(RDW_INVALIDATE); return 1; }, -onDeactivate = sub { $_[0]-Toolbar-Redraw(RDW_INVALIDATE); return 1; }, -onTerminate = sub { -1 }, ); my $tb = $mw - AddToolbar( -name = 'Toolbar', -nodivider = 1, -flat = 1, -list = 1, ); for ( 0 .. 3 ) { $tb-AddString(Test $_); $tb-AddButtons( 1, I_IMAGENONE, 1000 + $_, TBSTATE_ENABLED, TBSTYLE_AUTOSIZE|TBSTYLE_BUTTON|BTNS_SHOWTEXT, $_ ); } $tb - Hook ( NM_CUSTOMDRAW, \onCustumDraw ); $mw-Show(); Win32::GUI::Dialog(); exit(0); sub onCustumDraw { my ($object, $wparam, $lparam, $message_type, $message_code ) = @_; return unless $message_type == WM_NOTIFY; return unless $message_code == NM_CUSTOMDRAW; my $pNMTBCD = pack ( 'L!', $lparam ); my $sNMTBCD = unpack( 'P20', $pNMTBCD ); my ($dwDrawStage, $dc ) = unpack ( 'x12IL', $sNMTBCD ); if ( $dwDrawStage == CDDS_PREPAINT ) { $object-Result(CDRF_NOTIFYITEMDRAW); } elsif ($dwDrawStage==CDDS_ITEMPREPAINT) { if($mw-{-handle} != Win32::GUI::GetForegroundWindow()) { my $clrText=pack(I,0x808080); $CopyMemory-Call($lparam+60, $clrText, 4); } $object-Result(CDRF_DODEFAULT); } else { $object-Result(CDRF_DODEFAULT); } return 0; }