MFC中对编码文件的操作01

这篇具有很好参考价值的文章主要介绍了MFC中对编码文件的操作01。希望对大家有所帮助。如果存在错误或未考虑完全的地方,请大家不吝赐教,您也可以点击"举报违法"按钮提交疑问。

1、自定义类获取项目中全部对话框ID和头文件子路径

(1)、创建单例类

public:
static SetAllChinesefunctions*Instance();
private:
static SetAllChinesefunctions*_Instance;


SetAllChinesefunctions*SetAllChinesefunctions::Instance()
{
    if(nullptr == _Instance)
    {
        _Instance = new SetAllChinesefunctions;
    }
    return _Instance;
}

(2)、查找CFileFind类

这个类用于查找指定根目录下面的文件和文件夹,或者特定的文件。

1)、FindFile 函数会返回一个BOOL值,如果为1说明当前路径下还有文件或文件夹。参数是你指定的目录。

2)、FindNextFile函数,无参数,查找下一个文件或者文件夹。

3)、IsDots函数,无参数,用于判断当前文件夹是不是.或者..目录,是返回1。

4)、IsDirectory函数,无参数,用于判断当前是不是文件夹,是文件夹返回1。

CFileFind finder;
	CString searchPath = sPrjRoot + _T("\\*");//指定要去查找的路径
	BOOL bWorking = finder.FindFile(searchPath);//查找当前路径下面的文件和文件夹
	while (bWorking)
	{
		bWorking = finder.FindNextFile();

		if (finder.IsDots()) continue;

		if (finder.IsDirectory())
		{
			_iterfind(finder.GetFilePath());
			continue;
		}

		// 查找.h文件
		CString sFileName = finder.GetFileName();
		if (sFileName.Right(2).MakeLower() == _T(".h"))
		{
			_findDlgID(finder.GetFilePath());
		}
	}

(3)、当前类CFindDlgIDAndClassFile全部代码文章来源地址https://www.toymoban.com/news/detail-835793.html

#pragma once
#include <map>
#include"../TMLCHelper/StdioFileCodePage.h"

class CFindDlgIDAndClassFile
{
public:
	CFindDlgIDAndClassFile();
	~CFindDlgIDAndClassFile();
	static CFindDlgIDAndClassFile* Instance();
	void Find(const CString& sPrjRoot);

	bool IsExistDlgID(const CString& sID)
	{
		return(m_mapDlgIDAndClassFile.find(sID) != m_mapDlgIDAndClassFile.end());
	}
	
private:
	static CFindDlgIDAndClassFile* _Instance ;
	void _iterfind(const CString& sPrjRoot);
	void _findDlgID(const CString& sFileH);
	CString m_sRootPath;
public:
	std::map<CString, CString> m_mapDlgIDAndClassFile;   // 对话框ID - 类文件子路径
};

#define FINDDLGANDCLASS (*CFindDlgIDAndClassFile::Instance())

#include "stdafx.h"
#include "FindDlgIDAndClassFile.h"
#include <fstream>
#include <string>

//CFindDlgIDAndClassFile* _Instance = nullptr;

CFindDlgIDAndClassFile::CFindDlgIDAndClassFile()
{
}


CFindDlgIDAndClassFile::~CFindDlgIDAndClassFile()
{
}
CFindDlgIDAndClassFile* CFindDlgIDAndClassFile::_Instance = nullptr;  // 初始化 _Instance 为 nullptr
CFindDlgIDAndClassFile* CFindDlgIDAndClassFile::Instance()
{
	if (nullptr == _Instance)
	{
		_Instance = new CFindDlgIDAndClassFile;
	}

	return _Instance;
}

void CFindDlgIDAndClassFile::Find(const CString& sPrjRoot)
{
	m_sRootPath = sPrjRoot;
	m_mapDlgIDAndClassFile.clear();
	_iterfind(sPrjRoot);
}


void CFindDlgIDAndClassFile::_iterfind(const CString& sPrjRoot)
{
	CFileFind finder;
	CString searchPath = sPrjRoot + _T("\\*");//指定要去查找的路径
	BOOL bWorking = finder.FindFile(searchPath);//查找当前路径下面的文件和文件夹
	while (bWorking)
	{
		bWorking = finder.FindNextFile();

		if (finder.IsDots()) continue;

		if (finder.IsDirectory())
		{
			_iterfind(finder.GetFilePath());
			continue;
		}

		// 查找.h文件
		CString sFileName = finder.GetFileName();
		if (sFileName.Right(2).MakeLower() == _T(".h"))
		{
			_findDlgID(finder.GetFilePath());
		}
	}
}

void CFindDlgIDAndClassFile::_findDlgID(const CString& sFileH)
{
	CString sFilePath = sFileH;
	bool bDesignTime = false;

	CString stxt;
	CStdioFileCodePage file;
	file.OpenWithoutType(sFileH, CFile::modeRead);
	file.JumpBOM();
	while (file.ReadStringWithOutType(stxt))
	{
			int ipos1 = stxt.Find(_T("IDD ="));
			int ipos2 = stxt.Find(_T("IDD="));
			if (ipos1 != -1 || ipos2 != -1)
			{
				int ipos = (ipos1 > 0) ? (ipos1 + 5) : (ipos2 + 4);
				int ipose = stxt.Find('}', ipos);
				CString sID;
				if (ipose == -1)
				{
					 sID=stxt.Mid(ipos);
				}
				else
				{
					 sID = stxt.Mid(ipos, ipose - ipos);
				}
				
				sID.TrimLeft();
				sID.TrimRight();
				sFilePath.Replace(m_sRootPath, _T(""));
				sFilePath.Replace(L".h", _T(""));
				m_mapDlgIDAndClassFile[sID] = sFilePath;
				file.Close();
				return;
			}
	}
}


到了这里,关于MFC中对编码文件的操作01的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处: 如若内容造成侵权/违法违规/事实不符,请点击违法举报进行投诉反馈,一经查实,立即删除!

领支付宝红包 赞助服务器费用

相关文章

  • MFC中不同编码格式内容的写入

    把CString中的内容写到UTF16LE中去,可以使用WriteString或者Write。 WriteString函数会把UNICODE字符串以UTF16LE编码格式写入,遇到空字符会提前结束 Write函数则不受空字符的影响,不会提前结束。 使用WriteString向UTF16LE中写入CString类型的文本。 WriteString在写入文本内容后可以指针定位在

    2024年02月22日
    浏览(28)
  • mfc 动态加载dll库,Mat转CImage,读ini配置文件,鼠标操作,在edit控件上画框,调试信息打印

    h文件中添加 cpp文件中添加 左键按下弹起,右键按下弹起 TRACE(\\\"temp= %dn\\\", temp);

    2024年02月07日
    浏览(26)
  • MFC自定义控件ID操作————MFC+Halcon学习中的那些坑

    趁着大三寒假抓紧学习halcon与mfc,为未来职业发展做准备,今天和大家分享一个我在学习mfc与halcon过程中踩到的坑,足足困扰了我半天.... 程序很简单..就是在halcon中读取摄像头,并且用mfc开发一个简单的界面,将视频显示出来,完成体内容如下 发现这个图片控件的ID有些奇怪

    2024年02月05日
    浏览(27)
  • MFC操作excel

    步骤: 安装microsoft的excel软件,因为只有ms的excel软件才提供了有关的类库 选中工程,添加类→MFC→Typelib中的MFC类 选中类库, 在可用类类型库中选择Microsoft Excel Object Library(据版本有可能细微之不同) 添加需要使用的接口,根据网上大部分人的说法和能满足我需要的类就只有

    2024年02月16日
    浏览(25)
  • 【MFC实践】基于MFC向导C++制作计算器(附文件)

    MFC(Microsoft Foundation Classes)向导是一套用于简化Windows应用程序开发的工具集。 它建立在Microsoft Foundation Classes(MFC)之上,为开发人员提供了一种更直观、高效的方式来构建图形用户界面(GUI)应用程序。MFC向导通过提供可视化设计工具、代码生成器等功能,使得开发者能够

    2024年01月16日
    浏览(32)
  • MFC140.dll缺失的修复方法,安装MFC140.dll文件

    大家好,今天我要和大家分享的是如何正确安装和使用MFC140.dll。MFC140.dll是一种常见的动态链接库文件,它是Microsoft Foundation Classes(MFC)的一部分,被广泛应用于Windows操作系统中的各种应用程序中。在本文中,我们将详细介绍MFC140.dll缺失的修复方法。 MFC140.dll是一个非常重要的

    2024年02月11日
    浏览(38)
  • MFC删除Button控件具体操作

    删除Button按键; 删除xxxDlg.h中消息映射函数定义 删除xxxDlg.cpp中“DoDataExchange”和“BEGIN_MESSAGE_MAP”中的相关代码 删除xxxDlg.cpp中按键响应函数

    2024年02月09日
    浏览(29)
  • mfc140.dll丢失的解决方法,解析mfc140.dll这个文件

    其实大部分人在使用计算机过程中,您可能会遇到mfc140.dll丢失的错误提示。这个错误会导致一些应用程序无法正常运行,那么要如何解决这个问题呢?今天小编就来给大家详细的解析mfc140.dll这个文件以及教大家 mfc140.dll丢失的解决方法。 目录 一. mfc140.dll是什么文件 二. mf

    2024年02月09日
    浏览(42)
  • 找不到mfc100.dll的解决方法,怎么修复mfc100.dll文件

    当我们在使用电脑时,时常可能会遇到各类系统提示的错误信息。\\\"找不到mfc100.dll\\\" 就是这些错误之一,该错误提示会妨碍我们执行一些应用程序或特定代码。为了帮助读者克服这个技术障碍,本篇文章将详尽阐明导致该问题的根本原因,并提供一系列的解决方案。接下来,让

    2024年01月21日
    浏览(37)
  • MFC|选择获取文件路径

    参考:mfc按钮选择文件或者文件夹(https://blog.csdn.net/qq_39433050/article/details/130261518) 点击按钮槽函数,选择文件

    2024年02月09日
    浏览(31)

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

博客赞助

微信扫一扫打赏

请作者喝杯咖啡吧~博客赞助

支付宝扫一扫领取红包,优惠每天领

二维码1

领取红包

二维码2

领红包