【MFC】如何修改多文档视图的标签

新建工程同之前的几篇博客

新建一个调用菜单,并实现其内容

以下代码演示创建时设置标题,并保存到子框架中

复制代码
#include "MFCApplication9Doc.h"
#include "MFCApplication9View.h"
void CMainFrame::On32771()
{
	CMFCApplication9Doc* pDoc;
	POSITION pos = theApp.m_pDocTemplate->GetFirstDocPosition();
	int i = 1;
	while (pos != NULL)
	{
		pDoc = (CMFCApplication9Doc*)(theApp.m_pDocTemplate->GetNextDoc(pos));
		if (pDoc == NULL) break;

		POSITION pos1 = pDoc->GetFirstViewPosition();
		if (pos1 != NULL)
		{
			while (TRUE)
			{
				CMFCApplication9View* pView = (CMFCApplication9View*)pDoc->GetNextView(pos1);
				if(pView==NULL) break;
				CFrameWnd* pFrame = pView->GetParentFrame();
				CString strTitle;
				strTitle.Format(_T("第%d个页面"), i++);
				pFrame->SetWindowText(strTitle);
				pFrame->SetTitle(strTitle);
			}
		}
	}
}

为了在切换窗口时保持标题,需要修改子框架的以下函数

复制代码
void CChildFrame::OnUpdateFrameTitle(BOOL bAddToTitle)
{
	CString str = GetTitle();
	SetWindowText(str);

	// CMDIChildWndEx::OnUpdateFrameTitle(bAddToTitle);
}

注意不要调用父类的函数

最后效果如下图:

源代码见文章绑定的资源

相关推荐
qq_479875431 天前
C++ 网络编程中的 Protobuf 消息分发 (Dispatcher) 设计模式
网络·c++·设计模式
Tandy12356_1 天前
手写TCP/IP协议——IP层输出处理
c语言·网络·c++·tcp/ip·计算机网络
博语小屋1 天前
实现简单日志
linux·服务器·数据库·c++
ZouZou老师1 天前
C++设计模式之装饰器模式:以家具生产为例
c++·设计模式·装饰器模式
ZouZou老师1 天前
C++设计模式之桥接模式:以家具生产为例
c++·设计模式·桥接模式
呱呱巨基1 天前
Linux 进程概念
linux·c++·笔记·学习
liulilittle1 天前
C++ 浮点数封装。
linux·服务器·开发语言·前端·网络·数据库·c++
ZouZou老师1 天前
C++设计模式之组合模式:以家具生产为例
c++·设计模式·组合模式
yong15858553431 天前
2. Linux C++ muduo 库学习——原子变量操作头文件
linux·c++·学习
小小8程序员1 天前
STL 库(C++ Standard Template Library)全面介绍
java·开发语言·c++