RE: [perl-win32-gui-users] listview text color
I'm afraid the short answer is "no" (as far as I'm aware)--at least not using the latest Win32::GUI release. Someone asked this a year or so ago and I looked into it, eventually coming up with a tremendous hack (using hooks) to get it to work. Since then, the XS code has changed and the hack doesn't even work any more. Having said that, I don't think it would be *too* difficult to get it to work again, but it would involve modifying the listview XS code. In case you're interested, I've included the code as a guide (it worked a couple of releases ago, but the Hook call now fails). Jez White and Chris Wearn have done some work on the listview code recently; maybe they have some ideas too... Glenn == #!perl -w use strict; use Win32(); use Win32::API; use Win32::GUI; use Data::Dumper; use constant WM_NOTIFY => 0x4E; use constant NM_CUSTOMDRAW => -12; use constant CDRF_NEWFONT => 2; use constant CDRF_NOTIFYITEMDRAW=> 32; use constant CDDS_PREPAINT => 1; use constant CDDS_ITEMPREPAINT => 65537; use constant CLR_RED=> "FF"; use constant CLR_GREEN => "00FF00"; use constant CLR_BLUE => "FF"; use constant CLR_WHITE => "FF"; use constant CLR_BLACK => "00"; my $mw = new Win32::GUI::Window( -name=> "mw", -text=> "Colour Test", -size=> [ 200, 200 ], -pos => [ 200, 200 ], ); sub mw_Terminate { return -1 } $mw->AddListView( -name => "lvList", -pos => [ 0, 0 ], -size => [ 190, 125 ], ); $mw->lvList->InsertColumn( -index => 0, -text=> "Item", ); $mw->lvList->ColumnWidth(0,180); $mw->lvList->InsertItem(-text => "One"); $mw->lvList->InsertItem(-text => "Two"); $mw->lvList->InsertItem(-text => "Three"); $mw->lvList->InsertItem(-text => "Four"); $mw->lvList->TextColor(hex(CLR_RED)); $mw->lvList->Hook(NM_CUSTOMDRAW, \&lvList_CustomDraw); my $CopyMemory=new Win32::API("kernel32", "RtlMoveMemory", "NPI", "V"); defined $CopyMemory or die "Can't find CopyMemory"; sub lvList_CustomDraw{ my ($object, $wParam, $lParam, $type, $msgcode)[EMAIL PROTECTED]; return 1 if $type!=WM_NOTIFY; 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",hex(CLR_BLUE),hex(CLR_WHITE)) } elsif ($dwItemSpec==2) { $clrText=pack("II",hex(CLR_GREEN),hex(CLR_BLACK)) } else { return } $CopyMemory->Call($lParam+48, $clrText, 8); $object->Result(CDRF_NEWFONT); } } $mw->Show; $mw->lvList->SetFocus(); Win32::GUI::Dialog(); -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of CGIexpo.com Support Sent: Tuesday, 01 February, 2005 19:18 To: perl-win32-gui-users@lists.sourceforge.net Subject: [perl-win32-gui-users] listview text color I know you can set the text color for the items in a list view: $Window->ListView->TextColor(hex("FF")); Is there any way to set the color on just one row of text leaving the others as they are? --- This SF.Net email is sponsored by: IntelliVIEW -- Interactive Reporting Tool for open source databases. Create drag-&-drop reports. Save time by over 75%! Publish reports on the web. Export to DOC, XLS, RTF, etc. Download a FREE copy at http://www.intelliview.com/go/osdn_nl ___ Perl-Win32-GUI-Users mailing list Perl-Win32-GUI-Users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/perl-win32-gui-users
Re: [perl-win32-gui-users] Using threads to keep the GUI alive
At 14:45 2005-02-01, Johan Lindstrom wrote: I think most of this could be fairly neatly encapsulated in a module so there is a small amount of synchronization code in the application. Yep, now I have a Task class (should probably be named Threads::Task or something) which encapsulates this. The demo app at: http://www.darserman.com/Perl/Loft/temp/FetchURL-threads.zip now supports a progress bar, and a cancel button to stop lengthy downloads mid way. This is (simplified) what it takes to set up a separate worker Task to fetch a web page: my $oTaskGet; BEGIN { $oTaskGet = Task->new( rsSub => sub { my ($oCaller, $oRequest) = @_; my $url = $oRequest; # ... start getting the $url #Report progress back to the main program $oCaller->response(Message::Progress->new(byteReceived => $byteReceived || 1)); #... finish getting the $url into a HTTP::Response object $oRes $oCaller->response($oRes); } ); $oTaskGet->addQueue("cancel get"); $oTaskGet->start(); } At the start() line, the new thread is spawned, waiting for a request() to be sent to it with an $url to fetch. When a request is received, the sub is called. During the lengthy download, progress information is sent back with different calls to the $oCaller->response() method. The response object can be anything, but in this case a message object is used to convey how many bytes has been received. The main program is responsible for making sense of these responses. The HTTP::Response from getting the $url is finally sent back in a response() and the sub returns, the thread going back to being idle, waiting for the next request. At the same time, in the bthFetch_Click event handler in the main program: $oTaskGet->request($url); while (1) { my $oResponse = $oTaskGet->waitResponse( sub { Win32::GUI::DoEvents() } ); if($oResponse->isa("Message::Begin")) { $win->pbDownload->SetRange(0, $oResponse->byteExpected || 1); } elsif($oResponse->isa("Message::Progress")) { $win->pbDownload->SetPos($oResponse->byteReceived); } elsif($oResponse->isa("HTTP::Response")) { my $resHttp = $oResponse; $win->tfHttp->Text($resHttp->headers_as_string()); last; } } First the request() is sent to the task thread. This is when the sub defined above kicks in and starts to fetch the web page. The call to waitResponse() blocks until there is any response object available, but in the meantime, it repeatedly calls the sub ref we provide. In Win32::GUI programs it's clever to call DoEvents() at this time. When the waitResponse() returns with a response object, we dispatch it depending on the class. If it's a Message::Progress, we update the ProgressBar control, etc. If it's the final HTTP::Response object, we're done so we exit the loop and leave the event handler. The Cancel button is handled in a similar way, but with the dedicated message queue ("cancel get") we set up before starting the thread. sub ::btnCancel_Click { $oTaskGet->request(Message::Cancel->new(), "cancel get"); } This puts a Message::Cancel object in that queue (which is different from the default request queue we sent the $url through). At the other end of the queue, in the loop fetching the web page chunks, we check to see if anything appears during the download. $oCaller->acceptQueue("cancel get") and die("cancel get\n"); In this case the queue is only used for this single purpose, so we don't need to check what kind of object it is. If anything is sent on this queue, it's time to cancel, and for LWP::UserAgent this is done by dying. That's all folks, /J -- --- -- -- -- - - -- - Johan LindströmSourcerer @ Boss Casinos johanl AT DarSerMan.com Latest bookmark: "TCP Connection Passing" http://tcpcp.sourceforge.net/ dmoz: /Computers/Programming/Languages/JavaScript/ 12