求助:关于CStatic空间变为透明后的显示问题

是这样的,工程是基于对话框的。我给对话框的背景贴了一张图
上面有一些文本空间static,
开始因为和背景不同,挺难看的,就想着让他们都透明了,但是后来发现,在我需要跟新static空间内容的时候,就会发生重叠现象。晕啊。。高手指点下,这个怎么做

我的空间是用来跟新显示时间和日期的,名称分别为:IDC_DLG_STATIC_DAY,IDC_DLG_STATIC_TIME

为了是Cstatic透明,加添OnCtlColor函数,如下:
[code=C/C++][/code]
HBRUSH CRTUPCV1Dlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor) 
{
HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);

// TODO: Change any attributes of the DC here
if((pWnd->GetDlgCtrlID()==IDC_STATIC)||(pWnd->GetDlgCtrlID()==IDC_DLG_STATIC_DAY)||(pWnd->GetDlgCtrlID()==IDC_DLG_STATIC_TIME)) 
{  
 
pDC->SetBkMode( TRANSPARENT ); //设置背景透明,这样,输出字符的时候就 //是所谓的空心字,而不是有白的底色
hbr=(HBRUSH)::GetStockObject(NULL_BRUSH); //用透明  

// TODO: Return a different brush if the default is not desired
return hbr;
}

然后在OnTimer:
void CRTUPCV1Dlg::OnTimer(UINT nIDEvent) 
{
// TODO: Add your message handler code here and/or call default
switch(nIDEvent)
{
case 0:{

SYSTEMTIME stTime;
GetLocalTime(&stTime);
m_strDlgStaticDay.Format("%4d年%2d月%2d日",stTime.wYear,stTime.wMonth,stTime.wDay);
int n=m_strDlgStaticDay.Replace(" ","0");

m_strDlgStaticTime.Format("%2d:%2d:%2d",stTime.wHour,stTime.wMinute,stTime.wSecond);
n=m_strDlgStaticTime.Replace(" ","0");


m_ctrlDlgStaticDay.SetWindowText(m_strDlgStaticDay);
m_ctrlDlgStaticTime.SetWindowText(m_strDlgStaticTime);
}break;
default:break;
}
CDialog::OnTimer(nIDEvent);
}

作者: dwlovehome   发布时间: 2011-06-14

要沉了么?各位大牛,出来指点下啊

作者: dwlovehome   发布时间: 2011-06-15

在SetDlgItemText(IDC_STATIC1, _T("XXX"));之前先InvalidateRect()该static控件区域

作者: VisualEleven   发布时间: 2011-06-15

当使static透明时,就必须要在设置static的同时用InvalidateRect刷新窗口中static控件所在部分,否则肯定会重叠的

作者: shenyi0106   发布时间: 2011-06-15

现在调用后可以进行刷新了,不过闪的很厉害
程序如下:
void CRTUPCV1Dlg::OnTimer(UINT nIDEvent) 
{
// TODO: Add your message handler code here and/or call default
switch(nIDEvent)
{
case 0:{
// m_strDlgStaticDay.Empty();
// m_strDlgStaticTime.Empty();

SYSTEMTIME stTime;
GetLocalTime(&stTime);
m_strDlgStaticDay.Format("%4d年%2d月%2d日",stTime.wYear,stTime.wMonth,stTime.wDay);
int n=m_strDlgStaticDay.Replace(" ","0");

m_strDlgStaticTime.Format("%2d:%2d:%2d",stTime.wHour,stTime.wMinute,stTime.wSecond);
n=m_strDlgStaticTime.Replace(" ","0");


m_ctrlDlgStaticDay.SetWindowText(m_strDlgStaticDay);


m_ctrlDlgStaticTime.SetWindowText(m_strDlgStaticTime);
RefreshControl(IDC_DLG_STATIC_DAY);
RefreshControl(IDC_DLG_STATIC_TIME);
}break;
default:break; 

}
CDialog::OnTimer(nIDEvent);
}
void CRTUPCV1Dlg::RefreshControl(UINT uCtlID)
{
CRect rc;  
  GetDlgItem(uCtlID)->GetWindowRect(&rc);  
  ScreenToClient(&rc);  
InvalidateRect(rc);
}
这样子的话有时候会闪动。。。

作者: dwlovehome   发布时间: 2011-06-15