I have Buttons with the style BS_OWNERDRAW set.
I don't want to reinvent the whole wheel to draw the button, only add a simple aspect.
I have tested this, but the BaseClass CButton::DrawItem(lpDrawItemStruct) does nothing draw here. It is empty.
Do I have something missed?
void CMyButton::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct)
{
// Call the base class to draw the standard button appearance
ModifyStyle(BS_OWNERDRAW, 0); // remove BS_OWNERDRAW style
CButton::DrawItem(lpDrawItemStruct);
ModifyStyle(0, BS_OWNERDRAW); // add BS_OWNERDRAW style back
// Draw now my stuff
:
}
You are right in that by using owner-drawing controls you feel like re-inventing the wheel, and this is because Microsoft doesn't provide some
DoStandardDrawing()function (allowing for customization before and after the call), so you have to do everything yourself. And what makes things worse is that there is no some official documentation of say, what should be the drawing actions for an owner-drawn control to achieve a standard look (which a developer could modify so as to achieve some customization). Only some examples here and there or tutorials on sites like codeproject dating back to early 2000s (so you would get a nice Win2K look!).Also, I find it very laborious to draw everything yourself, as you would have to take into account all button-state combinations (selected, uselected, pushed, hovering etc etc) to achieve the standard look and behaviour first (and then see how to modify it).
But since your application uses the MFC library, you can derive your class from CMFCButton instead. It provides a lot of customization options, as data members and protected (but virtual and thus overridable) function members. You can see their default implementation in afxbutton.cpp (and add or delete things or completely modify it). And if your desired customization can be achieved by modifying the data members or calling the public functions only (in VS's Properties Editor, or in
OnInitDialog()), you may not even need to define a new class at all. It would be good to put a standard button (for testing) just next, to compare their look and behaviour.