界面上添加一個(gè)按鈕,把按鈕設(shè)置為Owner Draw = true;
添加WM_DRAWITEM消息映射,映射函數(shù)為OnDrawItem
void CmfcAppDlg::OnDrawItem(int nIDCtl, LPDRAWITEMSTRUCT lpDrawItemStruct)
{
// TODO: 在此添加消息處理程序代碼和/或調(diào)用默認(rèn)值
CDC ButtonDC;
CRect rc;
ButtonDC.Attach(lpDrawItemStruct->hDC);
//清空繪制
ButtonDC.FloodFill(0,0,TRANSPARENT);
rc = lpDrawItemStruct->rcItem;
//按鈕狀態(tài)
UINT state = lpDrawItemStruct->itemState;
//繪制一個(gè)邊框
ButtonDC.Draw3dRect(rc,0x0,0x100);
//背景色透明
ButtonDC.SetBkMode(TRANSPARENT);
//當(dāng)按鈕為焦點(diǎn)狀態(tài)
if(state & ODS_FOCUS){
CString str = L"焦點(diǎn)狀態(tài)";
ButtonDC.DrawText(str,str.GetLength(),&rc,DT_CENTER | DT_VCENTER | DT_SINGLELINE);
}else{
CString str = L"失去焦點(diǎn)";
ButtonDC.DrawText(str,str.GetLength(),&rc,DT_CENTER | DT_VCENTER | DT_SINGLELINE);
}
CDialog::OnDrawItem(nIDCtl, lpDrawItemStruct);
}
posted on 2009-01-15 12:41
BirdsHover 閱讀(1353)
評(píng)論(0) 編輯 收藏 引用 所屬分類:
MFC學(xué)習(xí)