Windows MFC 全局模态 实现 (二)
来源:互联网 发布:微盘,南风知我意 编辑:程序博客网 时间:2024/06/05 23:42
本文由 @lonelyrains 出品,转载请注明出处。
文章链接: http://blog.csdn.net/lonelyrains/article/details/39297015
所以这里记录一下使用透明窗口的实现方法:
1、工程中插入一个对话框
2、设置对话框属性 去掉Title bar的勾
3、增加一个OnInitDialog函数,在这个函数里实现后续调用
4、在OnInitDialog内增加设置对话框全屏
<pre name="code" class="cpp">CRect m_FullScreenRect;int nFullWidth=GetSystemMetrics(SM_CXSCREEN);int nFullHeight=GetSystemMetrics(SM_CYSCREEN);m_FullScreenRect.left = 0;m_FullScreenRect.top = 0;m_FullScreenRect.right = m_FullScreenRect.left + nFullWidth;m_FullScreenRect.bottom = m_FullScreenRect.top + nFullHeight;MoveWindow(0,0,m_FullScreenRect.Width(),m_FullScreenRect.Height(),1);
5、在OnInitDialog内增加设置对话框透明
typedef BOOL (WINAPI *lpfnSetLayeredWindowAttributes)(HWND hWnd, COLORREF crKey, BYTE bAlpha, DWORD dwFlags);lpfnSetLayeredWindowAttributes SetLayeredWindowAttributes;//设置成边缘透明COLORREF maskColor=RGB(0,0,0);HMODULE hUser32 = GetModuleHandle(TEXT("user32.dll")); //加载动态链接库SetLayeredWindowAttributes = (lpfnSetLayeredWindowAttributes)GetProcAddress(hUser32,"SetLayeredWindowAttributes");//取得SetLayeredWindowAttributes函数指针//为窗口加入WS_EX_LAYERED扩展属性SetWindowLong(this->GetSafeHwnd(), GWL_EXSTYLE, GetWindowLong(GetSafeHwnd(), GWL_EXSTYLE)^WS_EX_LAYERED);//调用SetLayeredWinowAttributes函数SetLayeredWindowAttributes(this->GetSafeHwnd(), maskColor, 1, LWA_ALPHA); // 至少要设置为1透明度,0表示不存在该对话框FreeLibrary(hUser32); //释放动态链接库6、在需要模态的对话框的原父窗口调用透明全屏框的DoModal
7、在透明全屏框的OnInitDialog最后增加线程调用需要模态的对话框的DoModal。使用线程调用的原因是为了防止阻塞正常弹出全屏透明框
8、在线程调用需要模态框的DoModal之后,增加透明框的退出代码
over
工程源码
这种方法最需要改善的地方是对话框的封装:假设有多个需要全局模态的对话框,直接继承某个类,就自动成了具有全局模态特性的对话框,而不需要每个对话框单独写代码弄一次。
0 0
- Windows MFC 全局模态 实现 (二)
- Windows MFC 全局模态 实现
- MFC实现全局热键
- MFC实现全局热键
- MFC学习笔记(二)之全局对象
- MFC版哈希值计算器的实现(二)
- MFC截图程序的实现(二)
- MFC实现2048游戏(二)
- MFC实现俄罗斯方块二
- 读书笔记--MFC Windows程序设计(二)
- Windows全局钩子实现方案回顾
- Windows编程实现自定义全局热键
- Windows编程实现自定义全局热键
- 一起学MFC(二) Windows应用程序编程模型
- windows下网络编程(二)——MFC CAsyncSocket
- 二、使用继承实现设置全局视图
- Liferay全局配置(二)
- Liferay全局配置(二)
- 虚函数与构造函数、析构函数
- How to Build ffmpeg with NDK r9
- PHP的魔术方法2
- Java屏幕截图及剪裁
- Cannot find executable for CFBundle
- Windows MFC 全局模态 实现 (二)
- MyEclipse中文乱码问题
- MySQL内核月报 2014.09
- Andriod 学习——Activity之间的跳转,以及Activity的生命周期。
- 用汇编看c++中的类型转换
- iOS Developer:真机测试
- 理解C语言-第22课 数组基础
- truncate、delete、drop三者的区别
- 简单的选择结构程序设计的总结