界面上添加一个按钮,把按钮设置为Owner Draw = true;
添加WM_DRAWITEM消息映射,映射函数为OnDrawItem
void CmfcAppDlg::OnDrawItem(int nIDCtl, LPDRAWITEMSTRUCT lpDrawItemStruct)
{
// TODO: 在此添加消息处理程序代码和/或调用默认值
CDC ButtonDC;
CRect rc;
ButtonDC.Attach(lpDrawItemStruct->hDC);
//清空绘制
ButtonDC.FloodFill(0,0,TRANSPARENT);
rc = lpDrawItemStruct->rcItem;
//按钮状态
UINT state = lpDrawItemStruct->itemState;
//绘制一个边框
ButtonDC.Draw3dRect(rc,0x0,0x100);
//背景色透明
ButtonDC.SetBkMode(TRANSPARENT);
//当按钮为焦点状态
if(state & ODS_FOCUS){
CString str = L"焦点状态";
ButtonDC.DrawText(str,str.GetLength(),&rc,DT_CENTER | DT_VCENTER | DT_SINGLELINE);
}else{
CString str = L"失去焦点";
ButtonDC.DrawText(str,str.GetLength(),&rc,DT_CENTER | DT_VCENTER | DT_SINGLELINE);
}
CDialog::OnDrawItem(nIDCtl, lpDrawItemStruct);
}
posted on 2009-01-15 12:41
BirdsHover 阅读(1339)
评论(0) 编辑 收藏 引用 所属分类:
MFC学习