How to make a CStatic control (MFC) transparent?(如何使 CStatic 控件 (MFC) 透明?)
问题描述
我的应用程序有一个带有填充整个对话框的图像的开始对话框.另外还有一个 CStatic 控件,它为用户显示一些可变信息.我使用以下代码使 CStatic 控件透明:
My application has a start dialog with an image which fills the whole dialog. Additionaly there is a CStatic control, which displays some variable information for the user. I made the CStatic control transparent with following code:
HBRUSH CStartbildDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
if(pWnd->GetDlgCtrlID() == IDC_STATIC_INFO)
{
pDC->SetBkMode(TRANSPARENT);
return reinterpret_cast<HBRUSH>(::GetStockObject(NULL_BRUSH));
}
else
return CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
}
当我用 GetDlgItem(IDC_STATIC_INFO)->SetWindowText 更改静态控件的文本时,新文本会与旧文本重叠(旧文本不会被删除).我曾尝试在使用 GetDlgItem(IDC_STATIC_BILD)->Invalidate() 调用 SetWindowText 图像之前重新绘制背景,但随后没有显示任何信息文本(既不是旧的也不是新).
When I change the text of the static control with GetDlgItem(IDC_STATIC_INFO)->SetWindowText, the new text overlaps the old text (the old text is not deleted). I have tried to repaint the background befor calling SetWindowText image with GetDlgItem(IDC_STATIC_BILD)->Invalidate(), but then no info text is shown (neither the old nor the new).
您知道如何使静态控件透明,以便我也可以用新文本覆盖它吗?
Do you know how I can make the static control transparent, so that I also can override it with a new text?
感谢您的帮助!
解决方案:来自 Sanja 的 codeproject-link 的方法 2(改编)对我有用.
Solution: Method 2 (adapted) from the codeproject-link from Sanja worked for me.
GetDlgItem(IDC_STATIC_INFO)->SetWindowText(tmp);
CRect rect;
GetDlgItem(IDC_STATIC_INFO)->GetWindowRect(&rect);
ScreenToClient(&rect);
InvalidateRect(&rect);
UpdateWindow();
推荐答案
你好,你可以找到透明静态示例 这里
Hi you can find transparent static sample here
这篇关于如何使 CStatic 控件 (MFC) 透明?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何使 CStatic 控件 (MFC) 透明?
基础教程推荐
- 非静态 const 成员,不能使用默认赋值运算符 2022-10-09
- 我应该对 C++ 中的成员变量和函数参数使用相同的名称吗? 2021-01-01
- 初始化列表*参数*评估顺序 2021-01-01
- 为什么派生模板类不能访问基模板类的标识符? 2021-01-01
- CString 到 char* 2021-01-01
- 通过引用传递 C++ 迭代器有什么问题? 2022-01-01
- 为什么 RegOpenKeyEx() 在 Vista 64 位上返回错误代码 2021-01-01
- GDB 显示调用堆栈上函数地址的当前编译二进制文 2022-09-05
- 如果我为无符号变量分配负值会发生什么? 2022-01-01
- 为什么 typeid.name() 使用 GCC 返回奇怪的字符以及如 2022-09-16
