【转】设置窗口的透明度
...
设置窗口的透明度(win2000以上)
-----------------------------------
第一步 定义功能
typedef BOOL (FAR PASCAL * FUNC1)( HWND hwnd, // handle to the layered window COLORREF crKey, // specifies the color key BYTE bAlpha, // value for the blend function DWORD dwFlags // action ); 第二步 实现代码
在OnInitDialog中加入下列代码(如果在SDI里面,应该是在OnCreat里面添加)
.....
HMODULE hModule = GetModuleHandle("user32.dll"); FUNC1 SetLayeredWindowAttributes; SetLayeredWindowAttributes = (FUNC1) GetProcAddress (hModule, _T( "SetLayeredWindowAttributes" ) ); // 设置分层扩展标记 SetWindowLong(GetSafeHwnd(), GWL_EXSTYLE, GetWindowLong(GetSafeHwnd(), GWL_EXSTYLE) | 0x80000L); // 70% alpha SetLayeredWindowAttributes(GetSafeHwnd(), 0, (255 * 70) / 100, 0x2); 工作作完成,怎么样,现在你可以运行你的程序来查看效果,即使背景变化也能立刻反映到你的窗口当中,这一点比金山词霸的效果要好。
第三步:如何除去透明选项?
// 除去分层扩展标记
SetWindowLong(GetSafeHwnd(),, GWL_EXSTYLE,
GetWindowLong(GetSafeHwnd(), GWL_EXSTYLE) & ~ 0x80000L);
// 重画窗口
RedrawWindow();
注:转载文章需注明来源:VCer.net 文章地址:http://vcer.net/1198840771640.html
如果你觉得VCer.net不错,而且你愿意为VCer.net捐赠一元钱,那么点击后面的捐赠按钮吧:)
A B C D E