// TODO: Add your message handler code here CRect rect; GetClientRect(&rect); dc.SetBkColor(m_BackColor); dc.SetBkMode(TRANSPARENT); CFont *pFont=GetParent()->GetFont(); CFont* pOldFont; pOldFont=dc.SelectObject(pFont); dc.SetTextColor(m_TextColor); dc.DrawText(m_strCaption,&rect,DT_CENTER); dc.SelectObject(pOldFont); // Do not call CStatic::OnPaint() for painting messages }但是在使用时, CColorStatic m_Timer; m_Timer.SubclassDlgItem(IDC_TIMER,this); void CNetServerDlg::OnTimer(UINT nIDEvent) { // TODO: Add your message handler code here and/or call default if(nIDEvent==TIMER_SHOW) { CTime _time; CString m_time; _time=CTime::GetCurrentTime(); m_time=_time.Format("%H:%M:%S"); SetDlgItemText(IDC_TIMER,m_time); /*m_Timer.SetCaption(m_time); m_Timer.SetTextColor(RGB(0,0,255));*/ } CDialog::OnTimer(nIDEvent); } 在Timer中就显示不出来,如果不在Timer中就可以,例如 m_Timer.SetCaption("测试"); m_Timer.SetTextColor(RGB(0,0,255));
我写的扩展CStatic类,响应它的=WM_CTRCOLOR消息就行了: HBRUSH CExStatic::CtlColor(CDC* pDC, UINT nCtlColor) { // TODO: Change any attributes of the DC here pDC->SetTextColor( RGB(255,0,0) ); pDC->SetBkMode(TRANSPARENT); return((HBRUSH)GetStockObject(NULL_BRUSH)); } 然后生成一个CExStatic变量就行了
void CColorStatic::OnPaint()
{
CPaintDC dc(this); // device context for painting
// TODO: Add your message handler code here
CRect rect;
GetClientRect(&rect);
dc.SetBkColor(m_BackColor);
dc.SetBkMode(TRANSPARENT);
CFont *pFont=GetParent()->GetFont();
CFont* pOldFont;
pOldFont=dc.SelectObject(pFont);
dc.SetTextColor(m_TextColor); dc.DrawText(m_strCaption,&rect,DT_CENTER);
dc.SelectObject(pOldFont);
// Do not call CStatic::OnPaint() for painting messages
}但是在使用时,
CColorStatic m_Timer;
m_Timer.SubclassDlgItem(IDC_TIMER,this);
void CNetServerDlg::OnTimer(UINT nIDEvent)
{
// TODO: Add your message handler code here and/or call default
if(nIDEvent==TIMER_SHOW)
{
CTime _time;
CString m_time;
_time=CTime::GetCurrentTime();
m_time=_time.Format("%H:%M:%S");
SetDlgItemText(IDC_TIMER,m_time);
/*m_Timer.SetCaption(m_time);
m_Timer.SetTextColor(RGB(0,0,255));*/
}
CDialog::OnTimer(nIDEvent);
}
在Timer中就显示不出来,如果不在Timer中就可以,例如
m_Timer.SetCaption("测试");
m_Timer.SetTextColor(RGB(0,0,255));
HBRUSH CExStatic::CtlColor(CDC* pDC, UINT nCtlColor)
{
// TODO: Change any attributes of the DC here
pDC->SetTextColor( RGB(255,0,0) );
pDC->SetBkMode(TRANSPARENT);
return((HBRUSH)GetStockObject(NULL_BRUSH));
}
然后生成一个CExStatic变量就行了
还是刷新显示不出来
这句话执行后就一直在OnPaint中执行,所以strCaption和颜色等都没有赋值进去那,所以没有显示出来,但是我如果不加时钟,直接
m_Timer.SubclassDlgItem(IDC_TIMER,this);
//this->SetTimer(TIMER_SHOW,1000,0);
m_Timer.SetCaption("测试");
m_Timer.SetTextColor(RGB(0,0,255));
就可以显示"测试"两字,是什么原因?
我现在是在
Ontimer中
if(nIDEvent==TIMER_SHOW)
{
CTime _time;
CString m_time;
_time=CTime::GetCurrentTime();
m_time=_time.Format("%H:%M:%S");
//SetDlgItemText(IDC_TIMER,m_time);
m_Timer.SetCaption(m_time);
m_Timer.SetTextColor(RGB(0,0,255));
}
记得有个AlphaBlend直接实现alpha效果,但是只能画位图。