MFC SDI(单文档)中创建一个新窗口(半透明)
2013-01-03 23:41
549 查看
思路来自:MFC Tutorial - Creating a window with two classes
在工程中新建一个类 CChildFrame
class CChildFrame : public CFrameWnd
在构造函数中:
可选:添加WM_PAINT消息:
在CXXApp类中,添加 CChildFrame 指针变量:
在CXXApp类的 InitInstance 方法中添加:
效果如下:
在工程中新建一个类 CChildFrame
class CChildFrame : public CFrameWnd
在构造函数中:
CChildFrame::CChildFrame() { Create(NULL,"MFC Tutorial Part 1 CoderSource Window"); }
可选:添加WM_PAINT消息:
void CChildFrame::OnPaint() { CPaintDC dc(this); // device context for painting // TODO: Add your message handler code here CDC *pDC = GetDC(); CBrush brush(RGB(0, 0, 0)); CBrush *pOldBrush = pDC->SelectObject(&brush); pDC->Rectangle(0, 0, 500, 500); pDC->SelectObject(pOldBrush); // Do not call CFrameWnd::OnPaint() for painting messages }
在CXXApp类中,添加 CChildFrame 指针变量:
class CXXApp : public CWinApp { public: CChildFrame *m_pChildWnd; ... }
在CXXApp类的 InitInstance 方法中添加:
BOOL CMultilayerDisplayApp::InitInstance() { ... m_pChildWnd = new CChildFrame(); // 创建新窗口类对象 //////// 这部分用于透明此窗口对象关联的窗口/////////// //加入WS_EX_LAYERED扩展属性 SetWindowLong(m_pChildWnd->m_hWnd, GWL_EXSTYLE, GetWindowLong(m_pChildWnd->m_hWnd, GWL_EXSTYLE)^0x80000); HINSTANCE hInst = LoadLibrary("User32.DLL"); if (hInst) { typedef BOOL (WINAPI *MYFUNC)(HWND,COLORREF,BYTE,DWORD); MYFUNC fun = NULL; //取得SetLayeredWindowAttributes函数指针 fun = (MYFUNC)GetProcAddress(hInst, "SetLayeredWindowAttributes"); if (fun) { fun(m_pChildWnd->m_hWnd, 0, 128, 2); } FreeLibrary(hInst); } //////// 这部分用于透明此窗口对象关联的窗口/////////// // The one and only window has been initialized, so show and update it. m_pMainWnd->ShowWindow(SW_SHOW); m_pMainWnd->UpdateWindow(); m_pChildWnd->ShowWindow(SW_SHOW); m_pChildWnd->UpdateWindow(); return TRUE; }
效果如下:
相关文章推荐
- MFC SDI(单文档)中创建一个新窗口(半透明)
- VS2013MFC单文档工程学习笔记七 - 创建新的一个窗口并让窗口2透明
- 创建一个新的视图窗口来显示已打开的文档中的内容
- 模态窗口创建非模态窗口,MFC定时器完成对一个文件的监测,定时刷新窗口
- [MFC] SDI文档创建的文件无法找到。
- MFC 为同一个文档创建不同视图
- MFC基于对话框,在对话框上插入图像控件,在图像控件上,画一个绿色的矩形,按键盘上下左右键,矩形在图像控件上移动移动。分别创建一个文本文件和一个二进制文件,对话框退出时,文档内写入保存退出前的矩形的位
- MFC MDI项目如何一个文档显示多个不同视图类(比如文字和图表,各自拥有单独的框架窗口)
- MFC创建的MDI程序 新建一个子文档 主窗口标题自动会被追加上子文档的名字 取消此功能
- 怎样使用MFC创建一个窗口类
- MFC多文档程序启动时一个文档创建两个视图
- MFC中多文档ActiveX创建子窗口
- MFC入门学习之控件(2)创建一个对话框窗口并在运行时显示
- 让VC++编写的MFC多文档程序不自动创建空白窗口
- VS2010使用MFC创建绿色软件及单文档和多文档及一个解决方案包含多个项目的解决方法
- 使用MFC创建一个分隔的窗口的步骤
- MFC(一):win32创建一个最简单的窗口
- 创建无边框的MFC单文档(SDI)应用程序
- MFC笔记-SDI窗口创建过程总结
- 如何禁用窗口关闭按钮在一个 MFC 多文档界面 (MDI) 应用程序