MFC CStatic控件在DrawItem中自绘

来源:互联网 发布:java高级工程师培训 编辑:程序博客网 时间:2024/06/04 19:24

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

0 0
原创粉丝点击