获取参数
DRAWITEMSTRUCT drawItemStruct;
drawItemStruct.CtlID=IDC_STACOLOR;
drawItemStruct.hwndItem=GetDlgItem(IDC_STACOLOR)->GetSafeHwnd();//得到IDC_STACOLOR的句柄;
drawItemStruct.hDC=::GetDC(drawItemStruct.hwndItem);
GetDlgItem(IDC_STACOLOR)->GetClientRect(&(drawItemStruct.rcItem));//获取IDC_STACOLOR客户坐标
m_cr=cr;
OnDrawItem(IDC_STACOLOR,&drawItemStruct);//调用 OnDrawItem绘图
绘图过程
void CComboDemoDlg::OnDrawItem(int nIDCtl, LPDRAWITEMSTRUCT lpDrawItemStruct)
{
// TODO: Add your message handler code here and/or call default
CDialog::OnDrawItem(nIDCtl, lpDrawItemStruct);
if(nIDCtl==IDC_STACOLOR)
{ //获得IDC_STACOLOR的句柄
CDC *pDC=CDC::FromHandle(lpDrawItemStruct->hDC);
CBrush br(m_cr);
CRect rc=lpDrawItemStruct->rcItem;
pDC->FillRect(&rc,&br);
}
}