Hi Philipp,
Philipp Kursawe wrote:
I guess the first step would be to move the MSG_WM_DRAWITEM message handling to my custom listbox control
It may be your choice but it's not the first step. You need to use a double buffered CListBox
, for instance:
class CMyListBox : public CDoubleBufferWindowImpl<CMyListBox, CListBox, ATL::CControlWinTraits>
{
BEGIN_MSG_MAP(CMyListBox)
CHAIN_MSG_MAP(CDoubleBufferWindowImpl)
END_MSG_MAP()
void DoPaint(HDC hdc)
{
DefWindowProc(WM_PAINT, (WPARAM)hdc, 0);
}
};
If you subclass the listbox in your parent dialog OnInit()
, you can check with breakpoints that the dc referenced in your DrawItem()
member is the MemoryDC set in CMyListBox::DoPaint()
. My test code:
class CTest0View :
public CDialogImpl<CTest0View>,
public COwnerDraw<CTest0View>
{
public:
enum { IDD = IDD_TEST0_FORM };
CMyListBox m_lb;
void DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct)
{
// must be implemented
return;
}
BEGIN_MSG_MAP(CTest0View)
MESSAGE_HANDLER(WM_INITDIALOG, OnInit)
CHAIN_MSG_MAP(COwnerDraw<CTest0View>)
FORWARD_NOTIFICATIONS()
END_MSG_MAP()
LRESULT OnInit(UINT /\*uMsg\*/, WPARAM /\*wParam\*/, LPARAM /\*lParam\*/, BOOL& bHandled)
{
m\_lb.SubclassWindow(GetDlgItem(IDC\_LIST1));
m\_lb.AddString(L"Titi");
m\_lb.AddString(L"Tata");
m\_lb.AddString(L"Toto");
return bHandled = FALSE;
}
};
cheers, AR
When the wise (person) points at the moon the fool looks at the finger (Chinese proverb)