Articles   Members Online:
-Article/Tip Search
-News Group Search over 21 Million news group articles.
Member Area
-Account Center
-Top 10 NEW!!
-Submit Article/Tip
-Forums Upgraded!!
-My Articles
-Edit Information
-Become a Member
-Why sign up!
-Chat Online!
-Indexes NEW!!
-Build your resume
-Find a job
-Post a job
-Resume Search
-Link to us
Visit Embarcadero
Embarcadero Community
How to detect which item of an open TComboBox dropdown list the mouse is over Turn on/off line numbers in source code. Switch to Orginial background IDE or DSP color Comment or reply to this aritlce/tip for discussion. Bookmark this article to my favorite article(s). Print this article
Delphi 2.x
User Rating
No Votes
# Votes
DSP, Administrator
Reference URL:
			Author: Tomas Rutkauskas

How would I display a hint over items in a ComboBox dropdown if the item text of 
the highlighted item is wider than the dropdown? I also want to be able to do the 
same thing in a ListBox. For a ComboBox I don't know how to proceed. There is no 
ItemAtPos method for a ComboBox. My first thought was no problem, I'll look at the 
source for TListBox.ItemAtPos and create a TComboBox.ItemAtPos method. However, I 
ran into a wall. TListBox.ItemAtPos uses the LB_GetItemRect message to do its 
magic. There is no corresponding CB_GetItemRect message for a ComboBox. Does anyone 
out there have any ideas on how to proceed?

2   procedure TForm1.appIdle(sender: TObject; var done: Boolean);
3   var
4     pt: TPoint;
5     wnd: HWND;
6     buf: array[0..128] of Char;
7     i: Integer;
8   begin
9     GetCursorPos(pt);
10    wnd := WindowFromPoint(pt);
11    buf[0] := #0;
12    if wnd <> 0 then
13    begin
14      GetClassName(wnd, buf, sizeof(buf));
15      if StrIComp(buf, 'ComboLBox') = 0 then
16      begin
17        Windows.ScreenToClient(wnd, pt);
18        i := SendMessage(wnd, LB_ITEMFROMPOINT, 0, lparam(PointToSmallpoint(pt)));
19        if i >= 0 then
20        begin
21          SendMessage(wnd, LB_GETTEXT, i, integer(@buf));
22          statusbar1.simpletext := buf;
23          Exit;
24        end;
25      end;
26    end;
27    statusbar1.simpletext := '';
28  end;

As to showing a custom hint, there is a CM_HINTSHOW message that is send to a control before a hint is popped up. It comes with a pointer to a record that allows you to customize the hints position and the hint text. The thing is undocumented, like all the internal VCL messages, so you need to use the VCL source to figure out how it is used. Or search for examples in the newsgroups archives. When the mouse moves to the next item you call Application.Cancelhint to remove the old hint and wait for the new one to reappear. Application has a number of hint-related properties you can tweak to make the hint appear fast.

Vote: How useful do you find this Article/Tip?
Bad Excellent
1 2 3 4 5 6 7 8 9 10


Share this page
Download from Google

Copyright © Mendozi Enterprises LLC