[VC中对话框窗体背景透明而控件不透明]

来源:互联网 发布:fdm下载元数据中 编辑:程序博客网 时间:2024/06/04 19:31

VC中对话框窗体背景透明,而对话框窗体上的控件不透明。

http://download.csdn.net/download/china0451/2375702

运用这里提供的方法,可以实现背景颜色的透明。

其原理是使用SetLayeredWindowAttributes对对话框进行的Alpha的操作。

以MFC的对话框为例讲下具体方法:

(1)OnInitDialog()中

// TODO: 在此添加额外的初始化代码
COLORREF maskColor = RGB(255,0,0);//红色
SetWindowLong(this->GetSafeHwnd(),GWL_EXSTYLE,GetWindowLong(this->GetSafeHwnd(),GWL_EXSTYLE)^0x80000);
HINSTANCE hInst=LoadLibrary(_T("User32.DLL"));
if(hInst)
{
typedef BOOL (WINAPI * MYFUNC)(HWND , COLORREF,BYTE,DWORD);
MYFUNC fun=NULL;
fun=(MYFUNC)GetProcAddress(hInst,"SetLayeredWindowAttributes");
if(fun)fun(this->GetSafeHwnd(),maskColor,255,1);
FreeLibrary(hInst);
}

(2)在OnPaint中重绘,修改对话框背景色为红色

else
{
CRect rect;
CPaintDC dc(this);
GetClientRect(rect);
dc.FillSolidRect(rect,RGB(255,0,0));


CDialogEx::OnPaint();
}

这里主要是因为使用白色的话,会把菜单栏都透明了,无法响应鼠标拖拽对话框及关闭等。



阅读全文
0 0
原创粉丝点击