欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

mfc对控件画背景图

程序员文章站 2022-10-31 16:00:07
mfc对控件画背景图 // 创建画刷 m_hredbrush = createsolidbrush(rgb(255, 0, 0)); m_hgreenbrush = createsolidbrush...

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