If I make a new button class inheriting from CButton
, specifying the BS_OWNERDRAW
style , and overriding the DrawItem
method I can control the rendering of the button, like this:
void CMyButton::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct) {
CDC dc;
dc.Attach(lpDrawItemStruct->hDC);
RECT rect = lpDrawItemStruct->rcItem;
dc.FillSolidRect(&rect, RGB(0, 0xFF, 0));
dc.Detach();
}
m_button.Create(L"Foo", WS_CHILD | WS_VISIBLE | BS_OWNERDRAW, CRect(0, 150, 100, 200), this, IDC_FOO);
I get the following result:
which is what I hoped for. However if I instead inherit my button from CSplitButton, which adds the BS_SPLITBUTTON
style, I get the following result:
which is not the result I had hoped for (I had hoped it would look exactly the same as the CButton
). The DrawItem
method isn't being called in this case so I guess BS_SPLITBUTTONS
are treated differently by the system.
How can I get the result I want, a button with split button behaviour with customized drawing?
As it says in MSDN for BS_OWNERDRAW:
(My emphasis).
If you're doing your own drawing, you have to do all of it yourself.