Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Combobox custom painting for ItemIndex = -1

82 views
Skip to first unread message

Werner Lehmann

unread,
Sep 22, 2003, 6:30:45 AM9/22/03
to
Hi,

(this is a repost, apparently the first posting from Sept 19th and a lot
of other postings vanished from the group?)

I have a dropdown style combobox (hence no editing) and want to draw
some customtext whenever the box is not dropped down and the itemindex
is -1. What is the best way to get the necessary textrect and how can I
make sure that the text is always visible under these circumstances
(itemindex = -1)?

Rgds
Werner


Yorai Aminov (TeamB)

unread,
Sep 22, 2003, 8:50:48 AM9/22/03
to
On Mon, 22 Sep 2003 12:30:45 +0200, Werner Lehmann
<leh...@media-interactive.de> wrote:

>I have a dropdown style combobox (hence no editing) and want to draw
>some customtext whenever the box is not dropped down and the itemindex
>is -1.

When no item is selected, no item drawing messages are sent. You have
to override WM_PAINT and paint the window yourself.

---
Yorai Aminov (TeamB)
http://develop.shorterpath.com/yorai
(TeamB cannot answer questions received via email.)

Werner Lehmann

unread,
Sep 22, 2003, 9:52:35 AM9/22/03
to
Hi Yorai,

>>I have a dropdown style combobox (hence no editing) and want to draw
>>some customtext whenever the box is not dropped down and the itemindex
>>is -1.
>
>
> When no item is selected, no item drawing messages are sent. You have
> to override WM_PAINT and paint the window yourself.

I tried that. First I need the text rectangle which I can pass to
DrawRect(). I tried to use GetClientRect() for this but the text is
clipped to the left (small comboborder) and to the right (combobutton).
I also tried to use EM_GETRECT with the EditHandle of the combobox but
EditHandle is always 0 so that did not work as well.

But even if I take GetClientRect and try to modify the rect by adding
the borderwidth to the left and subtracting the button widht from the
right there is another problem: If no item is selected (itemindex = -1)
and I let the list dropdown, immediately close it again (not selecting
anything) the "empty text" is gone and the combo content is painted in
clWindow.

Werner

Yorai Aminov (TeamB)

unread,
Sep 22, 2003, 1:17:41 PM9/22/03
to
On Mon, 22 Sep 2003 15:52:35 +0200, Werner Lehmann
<leh...@media-interactive.de> wrote:

>I tried that. First I need the text rectangle which I can pass to
>DrawRect(). I tried to use GetClientRect() for this but the text is
>clipped to the left (small comboborder) and to the right (combobutton).

Yeah, combo boxes are weird that way. The border and the drop-down
button are usually a part of a control's non-client area, but combo
boxes actually draw them on the client area. This means you'll have to
calculate the space taken by these elements and remove it from the
client rectangle.

Call the GetSystemParameters function to retrieve the size of the
various elements: SM_CXEDGE and SM_CYEDGE give you the width and
height of the 3D border, respectively. SM_CXHSCROLL gives you the
width of the drop-down button.

>If no item is selected (itemindex = -1)
>and I let the list dropdown, immediately close it again (not selecting
>anything) the "empty text" is gone and the combo content is painted in
>clWindow.

You'll need to trap that event and refresh the control. If all else
fails, you could probably handle the WM_LBUTTONUP message.

0 new messages