现在的位置: 首页 > 综合 > 正文

DRAWITEMSTRUCT结构体的应用

2014年02月20日 ⁄ 综合 ⁄ 共 719字 ⁄ 字号 评论关闭

获取参数

 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);
 }
}

抱歉!评论已关闭.