MFC CStatic控件在DrawItem中自绘

1.实现PreSubclassWindow

void CStaticHref::PreSubclassWindow()
{
// TODO: Add your specialized code here and/or call the base class


CStatic::PreSubclassWindow();


DWORD dwStyle = GetStyle();  
SetWindowLong(GetSafeHwnd(),GWL_STYLE,dwStyle | SS_OWNERDRAW);
//ModifyStyle(NULL, SS_OWNERDRAW);
}

2.在virtual void DrawItem(LPDRAWITEMSTRUCT /*lpDrawItemStruct*/);中完成相关绘制

3.确保消息映射中不能有:ON_WM_PAINT(也可以直接在OnPaint中绘制)、ON_WM_DRAWITEM 消息,否则DrawItem函数不会被调用


注:第二步的是DrawItem而非OnDrawItem。OnDrawItem是ON_WM_DRAWITEM消息的处理函数,是处理子控件发送过来的自绘消息的

你可能感兴趣的:(MFC CStatic控件在DrawItem中自绘)