两个静态文本设置成不同颜色的有关问题
两个静态文本设置成不同颜色的问题
HBRUSH CSCommTestDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
switch(nCtlColor) {
///...
case CTLCOLOR_STATIC:
pDC-> SetTextColor(RGB(0,255,100)); // 还可以通过pWnd确定某一个Static
pDC-> SetBkColor(RGB(100,80,200));
break;
///...
}
// TODO: Change any attributes of the DC here
return m_brush;
// TODO: Return a different brush if the default is not desired
return hbr;
}
请问如何根据pWnd确定某一个Static,在哪加代码?加什么代码?请大家帮忙
------解决方案--------------------
设置static的变量 m_static1 m_static2 分别用这两个变量去指向pwnd
------解决方案--------------------
pWd=GetDlgItem(控件标识符),放在哪都行!
------解决方案--------------------
HBRUSH CColor::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
HBRUSH hbr = CDialogBar::OnCtlColor(pDC, pWnd, nCtlColor);
// TODO: Change any attributes of the DC here
int nID = pWnd-> GetDlgCtrlID();
if ((nID > = IDC_STATIC1) && (nID <= IDC_STATIC23))
{
int i=nID-IDC_STATIC1;
m_br.DeleteObject();
m_br.CreateSolidBrush(m_showcol[i]);
hbr = m_br;
}
return hbr;
}
这种样式的,结果你自己调试
HBRUSH CSCommTestDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
switch(nCtlColor) {
///...
case CTLCOLOR_STATIC:
pDC-> SetTextColor(RGB(0,255,100)); // 还可以通过pWnd确定某一个Static
pDC-> SetBkColor(RGB(100,80,200));
break;
///...
}
// TODO: Change any attributes of the DC here
return m_brush;
// TODO: Return a different brush if the default is not desired
return hbr;
}
请问如何根据pWnd确定某一个Static,在哪加代码?加什么代码?请大家帮忙
------解决方案--------------------
设置static的变量 m_static1 m_static2 分别用这两个变量去指向pwnd
------解决方案--------------------
pWd=GetDlgItem(控件标识符),放在哪都行!
------解决方案--------------------
HBRUSH CColor::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
HBRUSH hbr = CDialogBar::OnCtlColor(pDC, pWnd, nCtlColor);
// TODO: Change any attributes of the DC here
int nID = pWnd-> GetDlgCtrlID();
if ((nID > = IDC_STATIC1) && (nID <= IDC_STATIC23))
{
int i=nID-IDC_STATIC1;
m_br.DeleteObject();
m_br.CreateSolidBrush(m_showcol[i]);
hbr = m_br;
}
return hbr;
}
这种样式的,结果你自己调试