From: Robert M. <rm...@po...> - 2007-02-26 21:16:00
|
Nice indeed. I saw your original message before I went away last week, and came up with a slightly different solution on the plane. I'll add the EN_ and CBN_ constant definitions to Win32::GUI::Constants. I also note what you say about wanting to hook the edit control and listbox control in the combobox - but I don't think it'd be trivial to add. Regards, Rob. #!perl -w use strict; use warnings; use Win32::GUI 1.05 qw(CW_USEDEFAULT WM_COMMAND VK_BACK VK_DELETE); sub CB_ERR() {-1} sub CBN_EDITUPDATE() {6} my $mw = Win32::GUI::DialogBox->new( -title => 'Drop-Down', -left => CW_USEDEFAULT, -size => [400,300], ); my $cb = $mw->AddCombobox( -dropdown => 1, -size => [100,100], ); $cb->Hook(CBN_EDITUPDATE, \&autocomplete); $cb->Add( sort qw(Red Green Blue Yellow Black White Purple Orange Brown) ); $cb->SetFocus(); $mw->Show(); Win32::GUI::Dialog(); $mw->Hide(); exit(0); sub autocomplete { my ($self, $wparam, $lparam, $type, $msgcode) = @_; return unless $type == WM_COMMAND; return unless $msgcode == CBN_EDITUPDATE; # Prevent matching for Backspace and Delete keys return if Win32::GUI::GetKeyState(VK_BACK); return if Win32::GUI::GetKeyState(VK_DELETE); # Get the text from the edit control my $edit_text = $self->Text(); my $edit_len = length($edit_text); # Get the current selection my ($start, $end) = $self->GetEditSel(); if($self->SelectString($edit_text) == CB_ERR) { # No match, restore text and selection $self->Text($edit_text); $self->SetEditSel($start, $end); } else { # Found match, SelectString changed the text for us if($end < $edit_len) { # We were editing in the middle of the string, # so keep the selection point $self->SetEditSel($start, $end); } else { # Select the added characters $self->SetEditSel($edit_len, -1); } } return 0; } __END__ Glenn W Munroe wrote: > ...and thanks to you for the feedback. It's hard to know sometimes if this > kind of stuff might be useful to someone, or if I'm just filling the list up > with garbage. > > There was a slight error in the example, by the way! I forgot the line > > -onChange => \& cbChange, > > in the combobox definition. > > All the best, > Glenn2 > >> -----Original Message----- >> From: Glenn Linderman [mailto:pe...@Ne...] >> Sent: 19 February 2007 16:35 >> To: Glenn W Munroe >> Cc: per...@li... >> Subject: Re: [perl-win32-gui-users] "Smart" Combobox >> >> On approximately 2/19/2007 8:34 AM, came the following characters from >> the keyboard of Glenn W Munroe: >>> .and for the record, here is the finished example, using the Hook >>> mentioned below. >>> >> Thanks for figuring this out. It looks good to me! I'm adding that to my >> personal "goody box" :) >> >> >> -- >> Glenn -- http://nevcal.com/ >> =========================== >> A protocol is complete when there is nothing left to remove. >> -- Stuart Cheshire, Apple Computer, regarding Zero Configuration >> Networking > > > ------------------------------------------------------------------------- > Take Surveys. Earn Cash. Influence the Future of IT > Join SourceForge.net's Techsay panel and you'll get the chance to share your > opinions on IT & business topics through brief surveys-and earn cash > http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV > _______________________________________________ > Perl-Win32-GUI-Users mailing list > Per...@li... > https://lists.sourceforge.net/lists/listinfo/perl-win32-gui-users > http://perl-win32-gui.sourceforge.net/ > |