Board index » delphi » Combobox's Listbox Event

Combobox's Listbox Event

Hi,
When a TComboBox dropped down, we can move around
inside the listbox with mouse. I can see the pre-selected
item (blue in color box) follow the mouse movement.
How can I trap this "pre-selected" items event.?
Say for instant: To show the description of the 'pre-selected'
item in the statusbar.

TIA
Hott

 

Re:Combobox's Listbox Event


Quote
> When a TComboBox dropped down, we can move around
> inside the listbox with mouse. I can see the pre-selected
> item (blue in color box) follow the mouse movement.
> How can I trap this "pre-selected" items event.?
> Say for instant: To show the description of the 'pre-selected'
> item in the statusbar.

Subclass a combobox window, get the handle of the drop-down listbox,
subclass the listbox, process WM_MOUSEMOVE and use a couple of other events
to find out the item under cursor. Not an easy job ...

--
Sincerely yours,
Eugene Mayevski

Re:Combobox's Listbox Event


Quote
"Hott" wrote...
> When a TComboBox dropped down, we can move around
> inside the listbox with mouse. I can see the pre-selected
> item (blue in color box) follow the mouse movement.
> How can I trap this "pre-selected" items event.?
> Say for instant: To show the description of the 'pre-selected'
> item in the statusbar.

You could make a OwnerDrawnFoxed style combobox
and then check the State parameter in the OnDrawItem
event....

procedure TForm1.ComboBox1DrawItem(Control: TWinControl;
  Index: Integer; Rect: TRect; State: TOwnerDrawState);
begin
  with Control as TComboBox do
  begin
    if odSelected in State then
      Label1.Caption := Items[Index]
    else
      Label1.Caption := '';

    Canvas.FillRect(Rect);
    Canvas.TextOut(Rect.Left + 2, Rect.Top, Items[Index]);
  end;
end;

HTH
--
Pieter

Re:Combobox's Listbox Event


Thanks Eugene,
  What I can see here is you are trying to trap mouse event by using the
subclass,
but, is there any way by using Win32 API to do this?

Regards
Hott

Quote
> Subclass a combobox window, get the handle of the drop-down listbox,
> subclass the listbox, process WM_MOUSEMOVE and use a couple of other
events
> to find out the item under cursor. Not an easy job ...

> --
> Sincerely yours,
> Eugene Mayevski

Re:Combobox's Listbox Event


Thanks Pieter,
  That was greate, it good enough for my purpose
I appreciate that tips.

Regards
Hott

p/s: BTW what is HTH?

Quote
"Pieter Zijlstra" <pzijlstr...@freeler.nl> wrote in message

news:3b61e4eb_1@dnews...
Quote

> You could make a OwnerDrawnFoxed style combobox
> and then check the State parameter in the OnDrawItem
> event....

> procedure TForm1.ComboBox1DrawItem(Control: TWinControl;
>   Index: Integer; Rect: TRect; State: TOwnerDrawState);
> begin
>   with Control as TComboBox do
>   begin
>     if odSelected in State then
>       Label1.Caption := Items[Index]
>     else
>       Label1.Caption := '';

>     Canvas.FillRect(Rect);
>     Canvas.TextOut(Rect.Left + 2, Rect.Top, Items[Index]);
>   end;
> end;

> HTH
> --
> Pieter

Re:Combobox's Listbox Event


Quote
"Hott" wrote...

> p/s: BTW what is HTH?

IITYWYBMAB? :)

Hope This Helps!

Just looked up the list at Borland at
http://www.borland.com/newsgroups/genl_faqs.html#acronyms
but it is not in there.

Here is another one with some more...
http://www.users.globalnet.co.uk/~logosale/abbrevs.html

--
Pieter

Re:Combobox's Listbox Event


Quote
In article <3b60f809$1_1@dnews>, Hott wrote:
> When a TComboBox dropped down, we can move around
> inside the listbox with mouse. I can see the pre-selected
> item (blue in color box) follow the mouse movement.
> How can I trap this "pre-selected" items event.?
> Say for instant: To show the description of the 'pre-selected'
> item in the statusbar.

Use a handler for the Application.OnIdle event or an actions OnUpdate
event.

Detecting which item of a open combobox dropdown the mouse is over:

procedure TForm1.appIdle(sender: TObject; var done: Boolean);
var
  pt: TPoint;
  wnd: HWND;
  buf: array[0..128] of Char;
  i: Integer;
begin
  GetCursorPos(pt);
  wnd := WindowFromPoint( pt );
  buf[0] := #0;
  If wnd <> 0 then begin
    Getclassname( wnd, buf, sizeof(buf));
    If StrIComp(buf, 'ComboLBox') = 0 Then Begin
      Windows.ScreenToClient( wnd, pt );
      i:= SendMessage( wnd, LB_ITEMFROMPOINT, 0,
                        lparam( PointToSmallpoint(pt)));
      If i >= 0 Then Begin
        sendmessage( wnd, LB_GETTEXT, i, integer(@buf));
        statusbar1.simpletext := buf;
        Exit;
      End;                    
    End;
  end;
  statusbar1.simpletext := '';
end;

Quote

> TIA
> Hott

Peter Below (TeamB)  100113.1...@compuserve.com)
No e-mail responses, please, unless explicitly requested!
Note: I'm unable to visit the newsgroups every day at the moment,
so be patient if you don't get a reply immediately.

Other Threads