Article View: borland.public.cppbuilder.nativeapi
Article #4811Re: Ownerdrawn combo box problem
From: Martin Golm
Date: Thu, 24 Nov 2005 09:48
Date: Thu, 24 Nov 2005 09:48
118 lines
4708 bytes
4708 bytes
Okay, here's a "working" example for the problem, i.e. it demonstrates
that something's wrong with the combo box.
class TForm1 : public TForm
{
__published:
TButton *Button1;
void __fastcall Button1Click(TObject *Sender);
private:
HWND cb;
protected:
virtual void __fastcall WndProc(Messages::TMessage &Message);
public:
__fastcall TForm1(TComponent* Owner);
__fastcall ~TForm1();
};
__fastcall TForm1::TForm1(TComponent* Owner) : TForm(Owner)
{
int style = WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS | WS_CLIPCHILDREN;
style |= CBS_DISABLENOSCROLL | CBS_DROPDOWNLIST | CBS_HASSTRINGS |
CBS_OWNERDRAWFIXED | CBS_NOINTEGRALHEIGHT | WS_BORDER;
style &= ~WS_TABSTOP;
style &= ~WS_VISIBLE;
cb = CreateWindow("COMBOBOX", "", style, 2, 2, 100, 25, Handle, 0, 0,
0);
}
__fastcall TForm1::~TForm1()
{
DestroyWindow(cb);
}
void __fastcall TForm1::WndProc(Messages::TMessage &Message)
{
switch (Message.Msg)
{
case WM_MEASUREITEM:
{
LPMEASUREITEMSTRUCT mis = (LPMEASUREITEMSTRUCT)Message.LParam;
if (mis->CtlType == ODT_COMBOBOX)
{
mis->itemHeight = 17;
Message.Result = 1;
}
break;
}
case WM_DRAWITEM:
{
LPDRAWITEMSTRUCT dis = (LPDRAWITEMSTRUCT)Message.LParam;
if (dis->CtlType == ODT_COMBOBOX)
{
DWORD backColor = GetSysColor(COLOR_WINDOW);
DWORD backColorH = GetSysColor(COLOR_HIGHLIGHT);
DWORD textColor = GetSysColor(COLOR_WINDOWTEXT);
DWORD textColorH = GetSysColor(COLOR_HIGHLIGHTTEXT);
if (dis->itemState & ODS_COMBOBOXEDIT)
{
FillRect(dis->hDC, &dis->rcItem, (HBRUSH)(backColor + 1));
TRect r(dis->rcItem);
InflateRect(&r, -1, -1);
COLORREF svTxtCol = SetTextColor(dis->hDC, RGB(255,0,127));
int mode = SetBkMode(dis->hDC, OPAQUE);
DrawText(dis->hDC, "myTest", -1, &r, DT_SINGLELINE |
DT_VCENTER);
SetTextColor(dis->hDC, svTxtCol);
SetBkMode(dis->hDC, mode);
}
else
{
DWORD bkCol = backColor;
DWORD txtCol = textColor;
if (dis->itemState & ODS_SELECTED)
{
bkCol = backColorH;
txtCol = textColorH;
}
FillRect(dis->hDC, &dis->rcItem, (HBRUSH)(bkCol + 1));
if (static_cast<int>(dis->itemID) >= 0)
{
TRect r(dis->rcItem);
InflateRect(&r, -1, -1);
SetTextColor(dis->hDC, txtCol);
char buf[256] = {0};
SendMessage(cb, CB_GETLBTEXT, dis->itemID, (LPARAM)buf);
DrawText(dis->hDC, buf, -1, &r, DT_SINGLELINE | DT_VCENTER);
}
}
Message.Result = 1;
}
break;
}
}
TForm::WndProc(Message);
}
void __fastcall TForm1::Button1Click(TObject *Sender)
{
if (!IsWindowVisible(cb))
{
ShowWindow(cb, SW_SHOW);
SendMessage(cb, CB_RESETCONTENT, 0, 0);
SendMessage(cb, CB_ADDSTRING, 0, (LPARAM)"Item 1");
SendMessage(cb, CB_ADDSTRING, 0, (LPARAM)"Item 2");
SendMessage(cb, CB_ADDSTRING, 0, (LPARAM)"Item 3");
SendMessage(cb, CB_ADDSTRING, 0, (LPARAM)"Item 4");
SendMessage(cb, CB_ADDSTRING, 0, (LPARAM)"Item 5");
SendMessage(cb, CB_ADDSTRING, 0, (LPARAM)"Item 6");
}
}
The text in the edit box is displayed just fine, but the list box isn't
(I don't even get a list box at all). The CB_ADDSTRING returns no error,
so the list box shouldn't be empty. But all I get in
DRAWITEMSTRUCT::itemID is 0xFFFFFFFF (-1). What am I doing wrong?
--
Martin
Technical Details
Message-ID:
<43858C68.6E541AE2@gmx.de>Path:
arc1-ca.pugleaf.net!g2news1.google.com!news4.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!newsfeed00.sul.t-online.de!t-online.de!83.128.0.11.MISMATCH!news-out1.kabelfoon.nl!newsfeed.kabelfoon.nl!xindi.nntp.kabelfoon.nl!news-out.newsgroups.com!propagator2-sterling.newsfeeds.com!in.nntp.be!caladan.landsraad.net!newsgroups.borland.com!not-for-mailReferences:
<4383006E.F33D5F94@gmx.de>Show Full Headers
Complete Article Headers
X-Google-Thread: 10cc67,963aa3ddf5359b86 X-Google-Attributes: gid10cc67,public X-Google-Language: ENGLISH,ASCII-7-bit Message-ID: <43858C68.6E541AE2@gmx.de> Date: Thu, 24 Nov 2005 10:48:24 +0100 From: Martin Golm <golm@gmx.de> Organization: - X-Mailer: Mozilla 4.78 [de] (Windows NT 5.0; U) X-Accept-Language: de MIME-Version: 1.0 Newsgroups: borland.public.cppbuilder.nativeapi Subject: Re: Ownerdrawn combo box problem References: <4383006E.F33D5F94@gmx.de> Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit NNTP-Posting-Host: 84.179.201.125 X-Trace: newsgroups.borland.com 1132825569 84.179.201.125 (24 Nov 2005 01:46:09 -0700) Lines: 118 Path: arc1-ca.pugleaf.net!g2news1.google.com!news4.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!newsfeed00.sul.t-online.de!t-online.de!83.128.0.11.MISMATCH!news-out1.kabelfoon.nl!newsfeed.kabelfoon.nl!xindi.nntp.kabelfoon.nl!news-out.newsgroups.com!propagator2-sterling.newsfeeds.com!in.nntp.be!caladan.landsraad.net!newsgroups.borland.com!not-for-mail