#!perl -w use strict; use warnings; use Win32::GUI 1.02; # Some constants not defined in Win32::GUI # These definitions will get inlined by the complier, # and work with older versions of perl than "use constant" sub WM_NOTIFY {0x4E}; sub NM_CUSTOMDRAW {-12}; sub CDRF_NEWFONT {2}; sub CDRF_NOTIFYITEMDRAW {32}; sub CDDS_PREPAINT {1}; sub CDDS_ITEMPREPAINT {65537}; sub CLR_RED {0x0000FF}; sub CLR_GREEN {0x00FF00}; sub CLR_BLUE {0xFF0000}; sub CLR_WHITE {0xFFFFFF}; sub CLR_BLACK {0x000000}; my $mw = Win32::GUI::Window->new( -text => "Colour ListView", -size => [ 200, 200 ], -pos => [ 200, 200 ], ); sub mw_Terminate { return -1 } my $lv = $mw->AddListView( -pos => [ 0, 0 ], -size => [ 190, 125 ], ); $lv->InsertColumn( -index => 0, -text => "Item", ); $lv->ColumnWidth(0,180); $lv->InsertItem(-text => "One"); $lv->InsertItem(-text => "Two"); $lv->InsertItem(-text => "Three"); $lv->InsertItem(-text => "Four"); $lv->TextColor(CLR_RED); $lv->Hook(NM_CUSTOMDRAW, \&lv_CustomDraw); $mw->Show; Win32::GUI::Dialog(); exit(0); sub lv_CustomDraw { my ($object, $wParam, $lParam, $type, $msgcode) = @_; return if $type != WM_NOTIFY; return if $msgcode != NM_CUSTOMDRAW; my ($dwDrawStage, $dwItemSpec)= unpack("x12Ix20i", unpack("P40", pack("L",$lParam))); if ($dwDrawStage==CDDS_PREPAINT) { $object->Result(CDRF_NOTIFYITEMDRAW); } elsif ($dwDrawStage==CDDS_ITEMPREPAINT) { my $clrText; if ($dwItemSpec==1) { $clrText=pack("II",CLR_WHITE,CLR_BLUE); } elsif ($dwItemSpec==2) { $clrText=pack("II",CLR_GREEN,CLR_BLACK); } else { return; } substr( $lParam, 48, 8, $clrText); $object->Result(CDRF_NEWFONT); } return 0; # return 0 essential, otherwise forced Result is ignored }