I've been trying to implement a "smart" combobox dropdown list. To get an
idea of what I'm talking about, compare the font dropdowns in Wordpad and
Word. In Wordpad, type "ar" into the control and "ar" is what you see. Tab
away of the control and it gets replaced with "Arial". That is easy enough
to implement and is shown in the example below. In Word, the behaviour is
slightly more sophisticated. Type "ar" and you see "Arial", with the final
three letters highlighted. This is what I'm trying to emulate. Again, it
would be easy enough if I could get the "change" notification from the
underlying edit control, but I can't see how to do that.

 

I guess the first question is if this is a built-in behaviour of the
combobox that I'm missing?

 

Assuming it's not, I started by getting the handle of the edit control. That
is easy enough, and its validity can be seen by the line in the combobox
"GotFocus" event. I then tried to "hook" the change event, but it doesn't
work (incidentally, should those EN_ constants be defined in
Win32::GUI::Constants?) I assume the problem is that the control is not
owned directly by Win32::GUI.

 

Does anyone have any ideas? I would have thought that an ability to "hook"
events for non-owned windows would be useful in other situations.

 

Cheers,

Glenn

 

============================================================================
=====================

 

#!perl -w

 

use Win32::GUI();

use Win32::GUI::Constants qw(/^GW_/);

 

use constant EN_CHANGE => 768;

 

my ($hCB, $hED, $hTX);

 

$mw = new Win32::GUI::Window(

-name       => "mw",

-title      => "ComboBox Test",

-pos        => [100, 100],

-size       => [200, 200],

-dialogui   => 1,

);

 

$mw->AddCombobox(

      -name   => "cb",

      -size   => [170, 110],

      -pos    => [10, 20],

      -vscroll  => 1,

      -dropdown => 1,

      -tabstop  => 1,

      -onGotFocus => sub { Win32::GUI::Text($hCB,"Test");

                         1 },

      -onLostFocus => sub { if ((my $i = $mw->cb->FindString($mw->cb->Text))
>= 0) 

                                          {
$mw->cb->Text($mw->cb->GetString($i)) } 

                         1 },

);

 

foreach (sort qw(Red Green Blue Yellow Black White)) {
$mw->cb->AddString($_) }

 

$mw->cb->SetExtendedUI(1);          # Down arrow to drop down list

 

$mw->AddTextfield(

      -name     => "tx",

      -size     => [154, 24],

      -left     => 10,

      -top      => 50,

      -tabstop  => 1,

);

 

sub CB_Change { print "CB Change\n" }

sub TX_Change { print "TX Change\n" }

 

$hCB = $mw->cb->{-handle};

$hED = $mw->cb->GetWindow(GW_CHILD);

$hTX = $mw->tx->{-handle};

 

print "Combobox control's handle is $hCB\n";

print "Combobox edit control's handle is $hED\n";

print "Textfield control's handle is $hTX\n";

 

$mw->tx->Hook(EN_CHANGE,\&TX_Change);

Win32::GUI::Hook($hCB,EN_CHANGE,\&CB_Change);

 

$mw->Show();

Win32::GUI::Dialog();

Reply via email to