【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);
}

注意不要调用父类的函数

最后效果如下图:

源代码见文章绑定的资源

相关推荐
君生我老20 分钟前
C++自写list类
c++
阿猿收手吧!34 分钟前
【C++】异步编程:std::async终极指南
开发语言·c++
REDcker38 分钟前
gRPC开发者快速入门
服务器·c++·后端·grpc
doupoa1 小时前
内存指针是什么?为什么指针还要有偏移量?
android·c++
冉佳驹1 小时前
C++ ——— 异常处理的核心机制和智能指针管理
c++·异常捕获·异常继承体与多态·重载抛异常·raii思想·智能指针shared_ptr·weak_ptr指针
C++ 老炮儿的技术栈1 小时前
Qt 编写 TcpClient 程序 详细步骤
c语言·开发语言·数据库·c++·qt·算法
yuuki2332331 小时前
【C++】继承
开发语言·c++·windows
梵刹古音1 小时前
【C++】 析构函数
开发语言·c++
wangjialelele2 小时前
Linux下的IO操作以及ext系列文件系统
linux·运维·服务器·c语言·c++·个人开发
打工哪有不疯的2 小时前
使用 MSYS2 为 Qt (MinGW 32/64位) 完美配置 OpenSSL
c++·qt