VS2010 单文档+多视图+Outlook风格
先来个段子
十年生死两茫茫,喜羊羊,灰太狼。舒克贝塔,蓝猫话凄凉。纵使相逢应不识,圣斗士,美猴王。老夫聊发少年狂,治肾亏,不含糖。锦帽貂裘,千骑用康王。为报倾城随太守,三百年,九芝堂。夜来幽梦忽还乡,学外语,新东方。相顾无言,洗洗更健康。
------------------调皮的分割线-----------------------
Outlook风格在http://blog.csdn.net/wlsgzl/article/details/32083145中已经实现了,这里只搞一下多视图。
=======好羡慕出双入对的分割线========
先分析下VS2010给的示例代码OutlookMultiViews,看看相关的部分。
在COutlookMultiViewsApp的InitInstance中
将CSingleDocTemplate的构造函数的第4个参数改为自己的类
BOOL COutlookMultiViewsApp::InitInstance()
{
// Initialize OLE libraries
if (!AfxOleInit())
{
AfxMessageBox(IDP_OLE_INIT_FAILED);
return FALSE;
} AfxEnableControlContainer(); // Standard initialization
// If you are not using these features and wish to reduce the size
// of your final executable, you should remove from the following
// the specific initialization routines you do not need. // Change the registry key under which our settings are stored.
// TODO: You should modify this string to be something appropriate
// such as the name of your company or organization.
SetRegistryKey(_T("Microsoft\\MFC\\Samples")); LoadStdProfileSettings(); // Load standard INI file options (including MRU) SetRegistryBase (_T("Settings")); // Initialize all Managers for usage. They are automatically constructed
// if not yet present
InitContextMenuManager();
InitKeyboardManager(); // Register the application's document templates. Document templates
// serve as the connection between documents, frame windows and views. CSingleDocTemplate* pDocTemplate;
pDocTemplate = new CSingleDocTemplate(
IDR_MAINFRAME,
RUNTIME_CLASS(COutlookMultiViewsDoc),
RUNTIME_CLASS(CMainFrame), // main SDI frame window
RUNTIME_CLASS(/*COutlookMultiViewsView*/CFV1));//改为自己的视图类
AddDocTemplate(pDocTemplate); // Parse command line for standard shell commands, DDE, file open
CCommandLineInfo cmdInfo;
ParseCommandLine(cmdInfo); // Dispatch commands specified on the command line
if (!ProcessShellCommand(cmdInfo))
return FALSE; // The one and only window has been initialized, so show and update it.
m_pMainWnd->ShowWindow(SW_SHOW);
m_pMainWnd->UpdateWindow(); return TRUE;
}
主框架窗口类CMainFrame中的视图成员变量
// Array of views attached to single document
CView * m_pViews[NUMVIEWS];
// Index to current view
UINT m_nCurView;
在CMainFrame的InitViews中
void CMainFrame::InitViews ()
{
m_nCurView = 0; // Save index of the currently active view class
CView* pActiveView = GetActiveView(); m_pViews[0] = pActiveView;//这里MFC让默认的模板作为第一个视图数组成员
// m_pViews[1] = (CView*) new CView1;
// m_pViews[2] = (CView*) new CView2;
// m_pViews[3] = (CView*) new CView3;
m_pViews[1] = (CView*) new CFV2;//改为自己的视图类,我这里是CFormView类型的
m_pViews[2] = (CView*) new CFV3;//改为自己的视图类,我这里是CFormView类型的
m_pViews[3] = (CView*) new CFV4;//改为自己的视图类,我这里是CFormView类型的 CDocument* pCurrentDoc = GetActiveDocument(); // Initialize a CCreateContext to point to the active document.
// With this context, the new view is added to the document
// when the view is created in CView::OnCreate().
CCreateContext newContext;
newContext.m_pNewViewClass = NULL;
newContext.m_pNewDocTemplate = NULL;
newContext.m_pLastView = NULL;
newContext.m_pCurrentFrame = NULL;
newContext.m_pCurrentDoc = pCurrentDoc; CRect rect(0, 0, 0, 0); // gets resized later for (int nView = 1; nView < NUMVIEWS; nView++)
{
// Create the new view. In this example, the view persists for
// the life of the application. The application automatically
// deletes the view when the application is closed.
m_pViews[nView]->Create(NULL, NULL,
(AFX_WS_DEFAULT_VIEW & ~WS_VISIBLE),
// views are created with the style of AFX_WS_DEFAULT_VIEW
// In MFC 4.0, this is (WS_BORDER | WS_VISIBLE | WS_CHILD)
rect, this,
IDD_FORMVIEW1-1 + nView, &newContext);//这里面的ID是连续定义的(在resource.h中),便于循环处理。 // When a document template creates a view, the WM_INITIALUPDATE
// message is sent automatically. However, this code must
// explicitly send the message, as follows. //m_pViews [nView]->OnInitialUpdate();//这里要注意,如果是CFormView类型的视图,要注掉。
}
}
然后再在COutlookMultiViewsApp的InitInstance中添加对InitViews的调用。
// Dispatch commands specified on the command line
if (!ProcessShellCommand(cmdInfo))
return FALSE; ((CMainFrame*)m_pMainWnd)->InitViews ();//调用InitViews // The one and only window has been initialized, so show and update it.
m_pMainWnd->ShowWindow(SW_SHOW);
m_pMainWnd->UpdateWindow();
在CMainFrame的消息映射宏中
感觉这个是手工添加的,因为Wizard添加不了ON_COMMAND_RANGE的宏,好像。
BEGIN_MESSAGE_MAP(CMainFrame, CFrameWnd)
ON_WM_CREATE()
ON_COMMAND(ID_VIEW_CUSTOMIZE, OnViewCustomize)
ON_REGISTERED_MESSAGE(AFX_WM_RESETTOOLBAR, OnToolbarReset)
ON_REGISTERED_MESSAGE(AFX_WM_TOOLBARMENU, OnToolbarContextMenu)
ON_COMMAND(ID_VIEW_OUTLOOKBAR, OnViewOutlookBar)
ON_UPDATE_COMMAND_UI(ID_VIEW_OUTLOOKBAR, OnUpdateViewOutlookBar)
ON_COMMAND_RANGE(ID_SHORTCUT_1, ID_SHORTCUT_4, OnOutlookBarShortcut)//就是这个,对这四个ID代表的按钮做处理
ON_UPDATE_COMMAND_UI_RANGE(ID_SHORTCUT_1, ID_SHORTCUT_4, OnUpdateOutlookBarShortcut)
ON_COMMAND(ID_VIEW_CAPTIONBAR, OnViewCaptionBar)
ON_UPDATE_COMMAND_UI(ID_VIEW_CAPTIONBAR, OnUpdateViewCaptionBar)
ON_COMMAND_RANGE(ID_VIEW_APPLOOK_2000, ID_VIEW_APPLOOK_2007_4, OnAppLook)
ON_UPDATE_COMMAND_UI_RANGE(ID_VIEW_APPLOOK_2000, ID_VIEW_APPLOOK_2007_4, OnUpdateAppLook)
END_MESSAGE_MAP()
在CMainFrame的OnOutlookBarShortcut中
void CMainFrame::OnOutlookBarShortcut(UINT id)
{
const int nIndex = id - ID_SHORTCUT_1;//点击的是哪一个。连续ID定义的好处。 ASSERT( nIndex >=0 && nIndex < NUMVIEWS );
if ( nIndex < 0 || nIndex >= NUMVIEWS )
return;
if (!m_pViews)
return; CView* pNewView = m_pViews[nIndex];
if (!pNewView)
return;
CView* pActiveView =GetActiveView();
if ( !pActiveView ) // No currently active view
return;
if ( pNewView == pActiveView ) // Already there
return; m_nCurView = nIndex; // Store the new current view's index // exchange view window ID's so RecalcLayout() works
UINT temp = ::GetWindowLong(pActiveView->m_hWnd, GWL_ID);
::SetWindowLong(pActiveView->m_hWnd, GWL_ID,::GetWindowLong(pNewView->m_hWnd, GWL_ID));
::SetWindowLong(pNewView->m_hWnd, GWL_ID, temp); // Display and update the new current view - hide the old one
pActiveView->ShowWindow(SW_HIDE);
pNewView->ShowWindow(SW_SHOW);
SetActiveView(pNewView);
RecalcLayout();
pNewView->Invalidate(); //下面的这个是改变标题栏的内容,无关。
CString strCaption;
strCaption.Format (_T("View %d"), nIndex + 1);
m_wndCaptionBar.SetText (strCaption);
m_wndCaptionBar.RedrawWindow ();
}
大致就是这些。
VS2010 单文档+多视图+Outlook风格的更多相关文章
- MFC单文档多视图程序设计与Splitter拆分窗口
1. 创建不同的子frame. 在文档视图程序中 CMainFrame(class CMainFrame : public CMDIFrameWndEx) 继承自 CMDIFrameWnd (CMDI ...
- vs2010 单文档MFC 通过加载位图文件作为客户区背景
实现效果: 这个其实是一个非常常见的功能,大家都会考虑给自己简单的工程做一个背景界面.其实只要在view类中重载OnEraseBkgnd()这个函数就好了. 代码如下: BOOL CdddView:: ...
- VS2010/MFC编程入门之四十(文档、视图和框架:各对象之间的关系)
前面一节中鸡啄米进行了文档.视图和框架的概述,本节主要讲解文档.视图.框架结构中各对象之间的关系. 各个对象之间的关系 文档.视图.框架结构中涉及到的对象主要有:应用程序对象.文档模板对象.文档对象. ...
- MFC文档、视图和框架
文档.视图.框架 文档/视图结构是MFC提供的一种不错的设计,它将数据的处理和显示分开来,这样更便于我们对程序的维护和扩展. 文档 文档对象用于管理和维护数据,包括保存数据.取出数据以及 ...
- VS2010-MFC(文档、视图和框架:各对象之间的关系)
转自:http://www.jizhuomi.com/software/223.html 前面一节进行了文档.视图和框架的概述,本节主要讲解文档.视图.框架结构中各对象之间的关系. 各个对象之间的关系 ...
- VS2010/MFC编程入门之二(利用MFC向导生成单文档应用程序框架)
VS2010/MFC编程入门之二(利用MFC向导生成单文档应用程序框架)-软件开发-鸡啄米 http://www.jizhuomi.com/software/141.html 上一讲中讲了VS20 ...
- Win7_Ultimate + VS2010 + openGL_MFC单文档应用开发框架搭建步骤
Win7_Ultimate + VS2010 + openGL单文档应用开发框架搭建步骤 上一个配置是基于OpenGL的开发工具配置的,下面就是基于Vs2010的MFC单文档应用开发. 通过网上查找资 ...
- 【2016.3.30项目技术记录】]VS2010自动生成MFC单文档框架程序的修改:去除属性框,在CViewTree类中添加鼠标单击响应
转自http://blog.csdn.net/yanfeiouc2009/archive/2010/06/07/5653360.aspx 手头上有个东西要用到单文档,由于想省事,直接用VS2010做了 ...
- VS2010/MFC编程入门之四十一(文档、视图和框架:分割窗口)
上一节中鸡啄米讲了文档.视图和框架结构中各对象之间的关系,本节主要讲讲在MFC中如何分割窗口. 分割窗口概述 分割窗口,顾名思义,就是将一个窗口分割成多个窗格,在每个窗格中都包含有视图,或 ...
随机推荐
- VC使用libcurl模拟登录CSDN并自动评论资源以获取积分
环境:Win7 64位+VC2008 软件及源码下载:(http://pan.baidu.com/s/1jGE52pK) 涉及到的知识点: C++多线程编程 libcurl的使用(包括发送http请求 ...
- KMP算法详解 --- 彻头彻尾理解KMP算法
前言 之前对kmp算法虽然了解它的原理,即求出P0···Pi的最大相同前后缀长度k. 但是问题在于如何求出这个最大前后缀长度呢? 我觉得网上很多帖子都说的不是很清楚,总感觉没有把那层纸戳破, 后来翻看 ...
- JS代码放置位置、变量与数据类型、运算符与逻辑表达运算符
内容简要: 1.JS代码放置位置的问题: 2.变量与数据类型: 3.运算符与逻辑表达式的运算符 我的位置 全局问题:为何在网页推荐位置(一般在<head></head>内部 ...
- Js中各类型数据到bool的转换
在返回Json字符串给前台时遇到的问题,返回的bool数据总是为TRUE 特意查了一下,发现了Js中各类数据转换到bool型是的结果. 希望能给遇到同样问题的人一点帮助. 数据类型 转换为bool ...
- 与众不同 windows phone (52) - 8.1 新增控件: AutoSuggestBox, ListView, GridView, SemanticZoom
[源码下载] 与众不同 windows phone (52) - 8.1 新增控件: AutoSuggestBox, ListView, GridView, SemanticZoom 作者:webab ...
- python之import机制
1. 标准 import Python 中所有加载到内存的模块都放在 sys.modules .当 import 一个模块时首先会在这个列表中查找是否已经加载了此模块,如果加载了则只是将 ...
- Spring核心概念之AOP
一.AOP 的概念 AOP(Aspect Oriented Programming)的缩写,面向切面编程,主要作用就是对代码进行增强处理. 理解面向切面编程的含义:就是在不改变原有程序的基础上为代码增 ...
- git 使用笔记(二)
续 2.15 删除文件 $ rm testDel.txt删除掉工作区的testDel.txt文件, 1)这时可以通过git checkout -- testDel.txt从版本库恢复该文件到工作区 2 ...
- Verilog学习笔记设计和验证篇(二)...............同步有限状态机
上图表示的就是数字电路设计中常用的时钟同步状态机的结构.其中共有四个部分产生下一状态的组合逻辑F.状态寄存器组.输出组合逻辑G.流水线输出寄存器组.如果状态寄存器组由n个寄存器组成,就可以记忆2^n个 ...
- C++之函数重载
函数重载定义: 如果同一作用域内的几个函数名字相同但形参列表不同; 重载与const形参: Record (Phone); = Record(const Phone); Record(Phone*) ...