Wow that is interesting. DrawItem never gets called when SS_RIGHT is
specified. I haven't been able to find anything on this.
As a work-around, you can do the same thing in OnPaint without ownerdraw.
"AliR \(VC++ MVP\)" <AliR@online.nospam> wrote:
Can you post the entire CMyStatic class? It looks like the problem is
I was hoping that was the case, but I don't think that's possible.
Below is code that reproduces the problem. When run, the code draws a
red rectangle, a green rectangle, and that's it. The third one doesn't
draw in blue or black -- it just doesn't draw at all. But the Create()
call does not fail. If I set a breakpoint inside the "case" statement
for SS_RIGHT, it never breaks. The "case" statements for both SS_LEFT
and SS_CENTER are both hit repeatedly.
----- MyStatic.h -----
class CMyStatic : public CStatic
afx_msg void DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct);
----- MyStatic.cpp -----
m_static_style = SS_CENTER;
m_static_style = GetStyle() & SS_TYPEMASK;
void CMyStatic::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct)
CDC* dc = CDC::FromHandle(lpDrawItemStruct->hDC);
// If SS_LEFT is specified, draw red
dc->FillSolidRect(&lpDrawItemStruct->rcItem, RGB(255, 0, 0));
// If SS_CENTER is specified, draw green
dc->FillSolidRect(&lpDrawItemStruct->rcItem, RGB(0, 255, 0));
// If SS_RIGHT is specified, draw blue
dc->FillSolidRect(&lpDrawItemStruct->rcItem, RGB(0, 0, 255));
// Anything else, draw black
dc->FillSolidRect(&lpDrawItemStruct->rcItem, RGB(0, 0, 0));
----- Code in the parent dialog class -----
// The rest of this class is just the automatically generated
// code from the MFC app wizard, aside from the addition of
// the declarations of m_label_1, m_label_2, and m_label_3.
m_label_1.Create("1", WS_CHILD | WS_VISIBLE | SS_LEFT,
CRect(0, 10, 100, 25), this);
m_label_2.Create("2", WS_CHILD | WS_VISIBLE | SS_CENTER,
CRect(0, 30, 100, 45), this);
m_label_3.Create("3", WS_CHILD | WS_VISIBLE | SS_RIGHT,
CRect(0, 50, 100, 65), this);