获取参数
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);
}
}
本文介绍了一个使用Windows控件进行自定义绘图的例子。具体展示了如何通过获取控件句柄、设备上下文(DC),以及客户区矩形来绘制指定颜色的矩形。此方法适用于需要对界面元素进行精确控制的应用场景。

2068

被折叠的 条评论
为什么被折叠?



