如何使CStatic控件(MFC)透明? [英] How to make a CStatic control (MFC) transparent?

查看:700
本文介绍了如何使CStatic控件(MFC)透明?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用程序有一个启动对话框,其中包含填充整个对话框的图像。另外还有一个CStatic控件,它显示用户的一些变量信息。我通过以下代码使CStatic控件透明:

  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 那么没有显示任何信息文本(既不是旧的也不是新的)。



你知道如何使静态控件变得透明,以便我也可以覆盖它一个新的文本?



感谢您的帮助!



解决方案:
来自Sanja的 codeproject-link 的方法2(改编)为我工作。

  GetDlgItem(IDC_STATIC_INFO) - > SetWindowText(tmp); 
CRect rect;
GetDlgItem(IDC_STATIC_INFO) - > GetWindowRect(& rect);
ScreenToClient(& rect);
InvalidateRect(& rect);
UpdateWindow();


解决方案

您可以找到透明静态样本 here


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);
}

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?

Thanks for your help!

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)透明?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆