mfc对控件画背景图
mfc对控件画背景图
// 创建画刷
m_hredbrush = createsolidbrush(rgb(255, 0, 0));
m_hgreenbrush = createsolidbrush(rgb(0, 255, 0));
m_hsourcebrush = createsolidbrush(rgb(240, 240, 240));
初始化控件样式
((cstatic*)getdlgitem(idc_static_zj))->modifystyle(0, ws_border | ss_blackframe | ss_blackrect);
//((cstatic*)getdlgitem(idc_static_zj))->invalidate(true);
((cstatic*)getdlgitem(idc_static_laser))->modifystyle(0, ws_border | ss_blackframe | ss_blackrect);
//((cstatic*)getdlgitem(idc_static_laser))->invalidate(true);
((cstatic*)getdlgitem(idc_static_jxwd2))->modifystyle(0, ws_border | ss_blackframe | ss_blackrect);
重绘控件时的样式
((cstatic*)getdlgitem(idc_static_zj))->modifystyle(ws_border | ss_blackframe | ss_blackrect, 0);
((cstatic*)getdlgitem(idc_static_zj))->invalidate(true);
((cstatic*)getdlgitem(idc_static_laser))->modifystyle(ws_border | ss_blackframe | ss_blackrect, 0);
((cstatic*)getdlgitem(idc_static_laser))->invalidate(true);
((cstatic*)getdlgitem(idc_static_jxwd2))->modifystyle(ws_border | ss_blackframe | ss_blackrect, 0);
((cstatic*)getdlgitem(idc_static_jxwd2))->invalidate(true);
2使用画刷
hbrush czkmonitordlg::onctlcolor(cdc* pdc, cwnd* pwnd, uint nctlcolor)
{
hbrush hbr = cdialogex::onctlcolor(pdc, pwnd, nctlcolor);
// 激光器
if ( pwnd->getdlgctrlid() == idc_static_laser )
{
//pwnd->setwindowtextw(_t(""));
switch (lasercheckstatedata)
{
case emnone:
{
/*m_sourcecolorref = pdc->getdcbrushcolor;*/
//pdc->setbkcolor(m_hsourcebrush);
//pdc->setbkcolor(pdc->setbkcolor(m_sourcecolorref););
//pdc->setbkcolor(rgb(120, 120, 120));
//pdc->setbkmode(transparent);
hbr = m_hsourcebrush;
break;
}
case emok:
{
//pdc->setbkcolor(rgb(255,0,0));
//pdc->setbkmode(transparent);
hbr = m_hgreenbrush ;
break;
}
case emerror:
{
//pdc->setbkcolor(rgb(0, 255, 0));
//pdc->setbkmode(transparent);
hbr = m_hredbrush;
break;
}
default:
break;
}
}
// 振镜
if ( pwnd->getdlgctrlid() == idc_static_zj )
{
//pwnd->setwindowtextw(_t(""));
switch (zjcheckstatedata)
{
case emnone:
{
//pdc->setbkcolor(m_sourcecolorref);
//pdc->setbkcolor(rgb(240, 240, 240));
//pdc->setbkmode(transparent);
//hbr = m_hsourcebrush;
break;
}
case emok:
{
//pdc->setbkcolor(rgb(255, 0, 0));
//pdc->setbkmode(transparent);
hbr = m_hgreenbrush ;
break;
}
case emerror:
{
//pdc->setbkcolor(rgb(0, 255, 0));
//pdc->setbkmode(transparent);
hbr = m_hredbrush;
break;
}
default:
break;
}
}
// 机箱温度
if (pwnd->getdlgctrlid() == idc_static_jxwd2)
{
switch (tmpcheckstatedata)
{
case emnone:
{
//pdc->setbkcolor(m_sourcecolorref);
//pdc->setbkcolor(rgb(240, 240, 240));
//pdc->setbkmode(transparent);
hbr = m_hsourcebrush;
break;
}
case emok:
{
//pdc->setbkcolor(rgb(255, 0, 0));
//pdc->setbkmode(transparent);
hbr = m_hgreenbrush;
break;
}
case emerror:
{
//pdc->setbkcolor(rgb(0, 255, 0));
//pdc->setbkmode(transparent);
hbr = m_hredbrush;
break;
}
default:
break;
}
}
// todo: change any attributes of the dc here
// todo: return a different brush if the default is not desired
return hbr;
}
3 删除画刷,在类的析构函数中调用
deleteobject(m_hredbrush);
deleteobject(m_hgreenbrush);
deleteobject(m_hsourcebrush);
上一篇: spring和struts整合
下一篇: JSP 实现网站在线人数统计代码
推荐阅读