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

注意不要调用父类的函数

最后效果如下图:

源代码见文章绑定的资源

相关推荐
·present·6 小时前
CSAPP(lecture 4_01)
c语言·c++
FPGA小迷弟7 小时前
用 Claude Code 重构遗留系统:从评估到落地的完整实践指南
c++·python·ai·plotly·django·ai编程·claude
程序员-King.7 小时前
【ROS1】Noetic 开发工作流程与常用命令
c++·ubuntu·ros
云深麋鹿7 小时前
C++ | 基于红黑树实现mymap与myset
开发语言·c++
傲世仙尊9 小时前
string增删查改-insert-erase-replace与find加substr组合技
c++
·present·10 小时前
CSAPP(lecture 3)
c++
别动我齐刘海11 小时前
机器人 C++ / 系统联调补强2——异常处理、Protobuf
linux·c++·人工智能·学习·算法·机器学习·机器人
basketball61611 小时前
C++ 中字符串与常见类型的转换总结
开发语言·c++
等我调个Bug11 小时前
C++智能指针通俗讲解
开发语言·c++
kyle~13 小时前
时间同步 --- PTP 与 Scheduled Action Command
c++·数码相机·机器人·传感器