我有个对话框程序,背景是一幅图,上面有个静态文本框(CStatic), 想实现文本框的背景是透明的,
但隔一段时间改变文字内容,我已经实现透明功能,但当我改变文字内容时,旧的未能消去,
新的覆盖在就文字上面。
透明功能通过给对话框类添加以下消息函数实现:
HBRUSH CCColorStaticST_demoDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
// TODO: Change any attributes of the DC here if(nCtlColor == CTLCOLOR_STATIC)//对话框:CTLCOLOR_DLG 按钮:CTLCOLOR_BTN
{
pDC->SetBkMode(TRANSPARENT); //设置背景透明
return HBRUSH(GetStockObject(HOLLOW_BRUSH));
} return hbr;
// TODO: Return a different brush if the default is not desired
return hbr;
}
我用以下函数测试,最后结果是乱七八糟的一堆,重叠在一起,
而不是我期望的依次显示aaaa,bbbbbbbb,cccccccccccccvoid CCColorStaticST_demoDlg::OnButton1()
{
// TODO: Add your control notification handler code here m_cstrStaticMy = "aaaa"; // 定义: CStatic m_cstrStaticMy
UpdateData(FALSE); Sleep(1000); m_cstrStaticMy = "bbbbbbbb";
UpdateData(FALSE); Sleep(1000); m_cstrStaticMy = "cccccccccccc";
UpdateData(FALSE);
}
请大家帮我!非常感谢!
但隔一段时间改变文字内容,我已经实现透明功能,但当我改变文字内容时,旧的未能消去,
新的覆盖在就文字上面。
透明功能通过给对话框类添加以下消息函数实现:
HBRUSH CCColorStaticST_demoDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
// TODO: Change any attributes of the DC here if(nCtlColor == CTLCOLOR_STATIC)//对话框:CTLCOLOR_DLG 按钮:CTLCOLOR_BTN
{
pDC->SetBkMode(TRANSPARENT); //设置背景透明
return HBRUSH(GetStockObject(HOLLOW_BRUSH));
} return hbr;
// TODO: Return a different brush if the default is not desired
return hbr;
}
我用以下函数测试,最后结果是乱七八糟的一堆,重叠在一起,
而不是我期望的依次显示aaaa,bbbbbbbb,cccccccccccccvoid CCColorStaticST_demoDlg::OnButton1()
{
// TODO: Add your control notification handler code here m_cstrStaticMy = "aaaa"; // 定义: CStatic m_cstrStaticMy
UpdateData(FALSE); Sleep(1000); m_cstrStaticMy = "bbbbbbbb";
UpdateData(FALSE); Sleep(1000); m_cstrStaticMy = "cccccccccccc";
UpdateData(FALSE);
}
请大家帮我!非常感谢!
解决方案 »
- 关于showwindow的问题
- IOCP 疑惑,wsasend() 函数里面的细节问题
- vc 编译出错问题fatal error C1189: #error : include 'stdafx.h' before including this file for PCH
- 如何连接打印机,打印出一直文档信息。
- 有谁能翻译并解释一段英文啊!
- 请问我用Visio(visual studio 2003 代的) 生成的C++文件,为什么报错??????
- single document
- 怎么创建远线程并使之运行?
- 窗口排列问题——我打开的窗口总是覆盖在一起
- VC工程PNG图片显示
- 能简单讲讲CPAINTDC和CCLIENTDC之间的区别吗
- 网络菜鸟提问!!!求救啊
return HBRUSH(GetStockObject(WHITE_BRUSH));//你可以把sleep的时间改长点来观察效果!
静态文本框的背景又变得不透明了,反而在我的图片上出现了一块方形灰影.
{ HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor); switch(nCtlColor)
{
case CTLCOLOR_DLG:
static HBRUSH hbrdlg = ::CreateSolidBrush( RGB(255, 255, 255) );
pDC->SetBkColor(TRANSPARENT);
return hbrdlg;
} // TODO: Return a different brush if the default is not desired
return hbr;
}
{ HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor); switch(nCtlColor)
{
case CTLCOLOR_DLG:
static HBRUSH hbrdlg = ::CreateSolidBrush( RGB(255, 255, 255) );
pDC->SetBkColor(TRANSPARENT);
return hbrdlg;
} // TODO: Return a different brush if the default is not desired
return hbr;
}
{ HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor); switch(nCtlColor)
{
case CTLCOLOR_DLG:
static HBRUSH hbrdlg = ::CreateSolidBrush( RGB(255, 255, 255) );
pDC->SetBkColor(TRANSPARENT);
return hbrdlg;
} // TODO: Return a different brush if the default is not desired
return hbr;
}