如何创建透明对话框(不是不可见的),但是在MFC中可见的图像或文本是可见的? [英] how to create transparent dialog ( not invisible) but image or text drawn on it is visible in MFC?

查看:309
本文介绍了如何创建透明对话框(不是不可见的),但是在MFC中可见的图像或文本是可见的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何创建透明对话框,但是在MFC中可见在其上绘制的图像或文本. 我搜索了很多文章,但没有得到我想要的. 我想在我的项目中部署它. 帮助可以得到赞赏,请帮助.

how to create transparent dialog but image or text drawn on it is visible in MFC. I searched many articles but didn't get exactly what i want. I want to deploy this in my project. help can be appreciated please help.

推荐答案

在OnInitDialog中,您需要输入以下内容:

In OnInitDialog you put this:

SetWindowLong(m_hWnd, GWL_EXSTYLE, GetWindowLong(m_hWnd,GWL_EXSTYLE) ^ WS_EX_LAYERED);
SetLayeredWindowAttributes(m_hWnd, RGB(255,0,255), 0, LWA_COLORKEY);

RGB(255,0,255)

RGB(255,0,255) is the COLORREF for magenta. We suppose here that you don't use the color magenta anywhere in your dialog. With that all magenta pixels of your dialog will be transparent. As you want only the background to be transparent, we will paint the background of the dialog in magenta. This is done via the WM_ERASEBKGND message:

在对话框的消息映射中添加ON_WM_ERASEBKGND(),因此您的消息映射应如下所示:

In the message map of your dialog add ON_WM_ERASEBKGND(), so your message map should look like this :

BEGIN_MESSAGE_MAP(CYourDialogDlg, CDialog)
//{{AFX_MSG_MAP(CYourDialogDlg)
...
//}}AFX_MSG_MAP
  ON_WM_ERASEBKGND()
END_MESSAGE_MAP()

在对话框的头文件中,您应该具有afx_msg BOOL OnEraseBkgnd(CDC* pDC);

In the header file of your dialog you should have afx_msg BOOL OnEraseBkgnd(CDC* pDC);

在对话框的.cpp文件中输入以下内容:

In the .cpp file of your dialog put this :

BOOL CYourDialogDlg::OnEraseBkgnd(CDC *pDC)
{
  CRect clientRect ;

  GetClientRect(&clientRect) ;
  pDC->FillSolidRect(clientRect, RGB(255,0,255)) ;  // paint background in magenta

  return FALSE  ;
}

这篇关于如何创建透明对话框(不是不可见的),但是在MFC中可见的图像或文本是可见的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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