VC多文档MFC程序的背景色改变
2010-12-06 17:09
441 查看
VC 建立多文档工程,CMainFrame主框架设置了背景色,但是当打开一个新文档非最大化状态时,鼠标点住拖动 主框架的背景色不能时时刷新,请问这个问题怎么解决? 很急很急,十万火急 下面贴出代码: 1./*截获MDI客户窗口WM_PAINT消息,在这个函数中向主框架窗口发送WM_PAINT/消息, 在该消息的处理函数中实现彩色位图的显示或者设置背景色*/ BOOL CMainFrame::PreTranslateMessage(MSG* pMsg) { // TODO: Add your specialized code here and/or call the base class if ( pMsg->hwnd == m_hWndMDIClient && pMsg->message == WM_PAINT ) { Invalidate() ;
} return CMDIFrameWnd::PreTranslateMessage(pMsg); } 2./*设置主框架背景色或者贴上一张位图*/ void CMainFrame::OnPaint() { // CPaintDC dc(this); // device context for painting // TODO: Add your message handler code here CDC dc; dc.m_hDC = ::GetDC( this->m_hWndMDIClient ); dc.SetBkMode( TRANSPARENT ); CRect clientRect; GetClientRect( &clientRect ); dc.FillSolidRect( &clientRect, RGB(100,100,255) ); dc.DeleteDC(); CMDIFrameWnd::OnPaint(); // Do not call CMDIFrameWnd::OnPaint() for painting messages }
————以上为转载
综上可以完成但存在一些问题:当移动子文档窗口的时候会出现背景不及时重绘,解决方法 在CChildFrame类中假如CChildFrame::OnMove(int x, int y) 函数
void CChildFrame::OnMove(int x, int y) { CMDIChildWnd::OnMove(x, y); // TODO: Add your message handler code here
CWnd * pwnd =((CBKGroundApp *)AfxGetApp())->m_pMainWnd;
((CMainFrame*)pwnd)->OnPaint();
}
CMainFrame中的OnPaint()函数需要变为public;
要使得打开时背景色就变成想要的 就得在InitInstance()函数中加上
pMainFrame->Invalidate();
相关文章推荐
- VC多文档MFC程序的背景色不能时时刷新
- VC++ 中改变对话框及相关控件的背景色(MFC)
- 让VC++编写的MFC多文档程序不自动创建空白窗口
- 如何改变VC6文档程序默认的打开文件对话框
- VC++ 中改变对话框及相关控件的背景色(MFC)
- VC下MFC程序调用console程序-存储文档的路径问题
- MFC程序中文档标题、主窗口标题、子窗口标题的改变
- vc中改变对话框的背景色(MFC)
- vc++ 单文档程序添加窗口移动事件(不是大小改变),以实现子窗口的伴随移动
- VC 2010 + MFC:自定义文档视图框架,去除新建、保存、打开等菜单功能,让文档程序个性化
- VC-基础:MFC单文档程序架构解析
- 如何改变VC程序的标题和文档标题
- 孙鑫VC学习笔记:第十五讲 (四) 编写一个基于MFC对话框的聊天程序
- MFC让文档/视图结构程序支持滚动条
- vc++解决单文档打印程序中打印预览与打印大小不等问题
- 改变单文档的背景色
- MFC文档视图结构程序结构总揽
- VC6 单文档 替换MFC默认的菜单栏和工具栏
- VC2010 MFC中实现printf调试功能,即MFC程序利用控制台输出调试信息。
- 以CRichEditView为基类的MFC单文档程序向导建立后编译成功运行失败问题