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消息的处理函数,是处理子控件发送过来的自绘消息的


版权声明:本文为y249077293原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。