VC中实现透明窗体--SetLayeredWindowAttributes
2009-07-27 20:38
585 查看
在VC中有一实现窗口透明的函数-----SetLayeredWindowAttributes(在5.0及以后版本中有)
函数原型
BOOL SetLayeredWindowAttributes(
HWND hwnd, //想要实现透明的窗体句柄
COLORREF crKey, //颜色
BYTE bAlpha, //Alpha值,取值范围是[0,255]
DWORD dwFlags //LWA_COLORKEY(=1)表示使用透明色; LWA_ALPHA(=2)表示使用 Alpha值
);
例子:
1、新建一基于对话框的MFC程序-----TransparentWindow
2、在 CTransparentWindowDlg 类的 OnInitDialog() 函数中加入以下代码(在 return TRUE; 前面)
SetWindowLong(this->m_hWnd,GWL_EXSTYLE,GetWindowLong(this->m_hWnd,GWL_EXSTYLE)^0x80000);
HINSTANCE hInst = LoadLibrary(_T("User32.DLL"));
if(hInst)
{
typedef BOOL (WINAPI *MYFUNC)(HWND,COLORREF,BYTE,DWORD);
MYFUNC fun = NULL; //取得SetLayeredWindowAttributes函数指针
fun=(MYFUNC)GetProcAddress(hInst, "SetLayeredWindowAttributes");
if(fun)
{
fun(this->m_hWnd,0,128,2);
}
FreeLibrary(hInst);
}
3、编译、运行完成
函数原型
BOOL SetLayeredWindowAttributes(
HWND hwnd, //想要实现透明的窗体句柄
COLORREF crKey, //颜色
BYTE bAlpha, //Alpha值,取值范围是[0,255]
DWORD dwFlags //LWA_COLORKEY(=1)表示使用透明色; LWA_ALPHA(=2)表示使用 Alpha值
);
例子:
1、新建一基于对话框的MFC程序-----TransparentWindow
2、在 CTransparentWindowDlg 类的 OnInitDialog() 函数中加入以下代码(在 return TRUE; 前面)
SetWindowLong(this->m_hWnd,GWL_EXSTYLE,GetWindowLong(this->m_hWnd,GWL_EXSTYLE)^0x80000);
HINSTANCE hInst = LoadLibrary(_T("User32.DLL"));
if(hInst)
{
typedef BOOL (WINAPI *MYFUNC)(HWND,COLORREF,BYTE,DWORD);
MYFUNC fun = NULL; //取得SetLayeredWindowAttributes函数指针
fun=(MYFUNC)GetProcAddress(hInst, "SetLayeredWindowAttributes");
if(fun)
{
fun(this->m_hWnd,0,128,2);
}
FreeLibrary(hInst);
}
3、编译、运行完成
相关文章推荐
- VC++ 实现整个对话框透明的效果SetLayeredWindowAttributes
- (转)xp下实现窗体透明特效/异形窗口SetLayeredWindowAttributes函数
- 窗体透明效果的实现 渐进式等SetLayeredWindowAttributes的用法
- 用SetLayeredWindowAttributes实现窗口透明
- 工作问题积累(八)SetLayeredWindowAttributes(设置透明窗体)
- 用SetLayeredWindowAttributes实现窗口透明
- 透明窗口(窗口上面文字图片等内容不透明)的实现(使用SetLayeredWindowAttributes API函数)
- WinAPI透明窗体SetLayeredWindowAttributes
- WinAPI透明窗体SetLayeredWindowAttributes( 转)
- 使用SetLayeredWindowAttributes API 实现透明窗口
- VC6.0使用SetLayeredWindowAttributes实现透明效果
- SetLayeredWindowAttributes 函数的使用方法,对话框透明的方法
- Win7下的异形窗体——SetLayeredWindowAttributes()的应用注意
- VC++调用UpdateLayeredWindow实现半透明窗体【转】
- VC++调用UpdateLayeredWindow实现半透明窗体【转】
- VC++ SetLayeredWindowAttributes
- WinAPI: SetLayeredWindowAttributes - 设置窗口的透明
- 使用SetLayeredWindowAttributes函数设置窗口透明色与透明度
- 渐进式透明的设置(SetLayeredWindowAttributes的用法)
- VC++调用UpdateLayeredWindow实现半透明窗体【转】