I think I just answered my own question :-)


The parent combobox gets a CBN_EDITCHANGE event when the text in the edit control changes. That event doesn’t appear to be implemented in Win32::GUI, but it can be “hooked” with the following line:




Again, the CBN_EDITCHANGE constant isn’t exported by Win32::GUI::Constants (maybe these are considered internal and are purposely not exported), but its value is 5.


I also notice that there is a method to get the edit control handle by using the ComboboxEx control.




From: Glenn W Munroe [mailto:gwmunroe @ gmail.com]
Sent: 16 February 2007 19:15
To: perl-win32-gui-users@lists.sourceforge.net
Subject: "Smart" Combobox



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.







#!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,




      -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



      -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";