⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 vcresrepairdlg.cpp

📁 VC RES资源修复工具
💻 CPP
字号:
// VCResRepairDlg.cpp : implementation file

//



#include "stdafx.h"

#include "VCResRepair.h"

#include "VCResRepairDlg.h"



#ifdef _DEBUG

#define new DEBUG_NEW

#undef THIS_FILE

static char THIS_FILE[] = __FILE__;

#endif



/////////////////////////////////////////////////////////////////////////////

// CAboutDlg dialog used for App About



class CAboutDlg : public CDialog

{

public:

	CAboutDlg();



// Dialog Data

	//{{AFX_DATA(CAboutDlg)

	enum { IDD = IDD_ABOUTBOX };

	//}}AFX_DATA



	// ClassWizard generated virtual function overrides

	//{{AFX_VIRTUAL(CAboutDlg)

	protected:

	virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support

	//}}AFX_VIRTUAL



// Implementation

protected:

	//{{AFX_MSG(CAboutDlg)

	//}}AFX_MSG

	DECLARE_MESSAGE_MAP()

};



CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)

{

	//{{AFX_DATA_INIT(CAboutDlg)

	//}}AFX_DATA_INIT

}



void CAboutDlg::DoDataExchange(CDataExchange* pDX)

{

	CDialog::DoDataExchange(pDX);

	//{{AFX_DATA_MAP(CAboutDlg)

	//}}AFX_DATA_MAP

}



BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)

	//{{AFX_MSG_MAP(CAboutDlg)

		// No message handlers

	//}}AFX_MSG_MAP

END_MESSAGE_MAP()



/////////////////////////////////////////////////////////////////////////////

// CVCResRepairDlg dialog



CVCResRepairDlg::CVCResRepairDlg(CWnd* pParent /*=NULL*/)

	: CDialog(CVCResRepairDlg::IDD, pParent)

{

	//{{AFX_DATA_INIT(CVCResRepairDlg)

	m_nBegNum = 96;

	//}}AFX_DATA_INIT

	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32

	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);

}



void CVCResRepairDlg::DoDataExchange(CDataExchange* pDX)

{

	CDialog::DoDataExchange(pDX);

	//{{AFX_DATA_MAP(CVCResRepairDlg)

	DDX_Text(pDX, IDC_BEG_NUM, m_nBegNum);

	//}}AFX_DATA_MAP

}



BEGIN_MESSAGE_MAP(CVCResRepairDlg, CDialog)

	//{{AFX_MSG_MAP(CVCResRepairDlg)

	ON_WM_SYSCOMMAND()

	ON_WM_PAINT()

	ON_WM_QUERYDRAGICON()

	//}}AFX_MSG_MAP

END_MESSAGE_MAP()



/////////////////////////////////////////////////////////////////////////////

// CVCResRepairDlg message handlers



BOOL CVCResRepairDlg::OnInitDialog()

{

	CDialog::OnInitDialog();



	// Add "About..." menu item to system menu.



	// IDM_ABOUTBOX must be in the system command range.

	ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);

	ASSERT(IDM_ABOUTBOX < 0xF000);



	CMenu* pSysMenu = GetSystemMenu(FALSE);

	if (pSysMenu != NULL)

	{

		CString strAboutMenu;

		strAboutMenu.LoadString(IDS_ABOUTBOX);

		if (!strAboutMenu.IsEmpty())

		{

			pSysMenu->AppendMenu(MF_SEPARATOR);

			pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);

		}

	}



	// Set the icon for this dialog.  The framework does this automatically

	//  when the application's main window is not a dialog

	SetIcon(m_hIcon, TRUE);			// Set big icon

	SetIcon(m_hIcon, FALSE);		// Set small icon

	

	// TODO: Add extra initialization here

	

	return TRUE;  // return TRUE  unless you set the focus to a control

}



void CVCResRepairDlg::OnSysCommand(UINT nID, LPARAM lParam)

{

	if ((nID & 0xFFF0) == IDM_ABOUTBOX)

	{

		CAboutDlg dlgAbout;

		dlgAbout.DoModal();

	}

	else

	{

		CDialog::OnSysCommand(nID, lParam);

	}
	
}



// If you add a minimize button to your dialog, you will need the code below

//  to draw the icon.  For MFC applications using the document/view model,

//  this is automatically done for you by the framework.



void CVCResRepairDlg::OnPaint() 

{

	if (IsIconic())

	{

		CPaintDC dc(this); // device context for painting



		SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);



		// Center icon in client rectangle

		int cxIcon = GetSystemMetrics(SM_CXICON);

		int cyIcon = GetSystemMetrics(SM_CYICON);

		CRect rect;

		GetClientRect(&rect);

		int x = (rect.Width() - cxIcon + 1) / 2;

		int y = (rect.Height() - cyIcon + 1) / 2;



		// Draw the icon

		dc.DrawIcon(x, y, m_hIcon);

	}

	else

	{

		CDialog::OnPaint();

	}

}



// The system calls this to obtain the cursor to display while the user drags

//  the minimized window.

HCURSOR CVCResRepairDlg::OnQueryDragIcon()

{

	return (HCURSOR) m_hIcon;

}



void CVCResRepairDlg::OnOK() 

{

	// TODO: Add extra validation here

	CFileDialog fileDialog(TRUE,NULL,"resource.h",NULL,"资源文件(*.h)|*.h||");

	if(fileDialog.DoModal() == IDOK)

	{

		UpdateData(TRUE);

		CString strInfo = _T("");

		strInfo.Format("是否要将资源头文件资源ID,替换成从最小值%d开始吗?",m_nBegNum);

		if(MessageBox(strInfo,"系统提示",MB_YESNO) == IDYES)

		   DoRepair(fileDialog.GetPathName());

	}

}



void CVCResRepairDlg::DoRepair(CString strFileNam)

{

	UINT k = m_nBegNum;



	CStringList strList;

	

	//计算文件的行数,分配行存储字符串列表

	FILE *fp;



	fp = fopen(strFileNam,"r");

    

    char ch = '\n';

    int i = 0;



	while(!feof(fp))

	{

		ch = (char)fgetc(fp);

		if(ch == '\n')

		{

           i++;

		   CString str;

		   strList.AddTail(str);

		}

	}

	fclose(fp);

    

	//读取文件,将文件内容以行的形式存储在字符串列表里

	FILE *fp1;



	fp1 = fopen(strFileNam,"r");

    

	i = 0;

	CString *str = &strList.GetAt(strList.FindIndex(i));

	while(!feof(fp1))

	{

		ch = (char)fgetc(fp1);

		if(feof(fp1))

			break;



		*str += ch;

		

		if(ch == '\n')

		{

            i++;		   

			POSITION p = strList.FindIndex(i);

			if(p)

			{

			   str = &strList.GetAt(p);

			}

		}

	}

	fclose(fp1);

    

	POSITION p1 = strList.GetHeadPosition();

	while(p1)

	{

		 str = &strList.GetNext(p1);

		 if(str->Find("#define") != -1)

		 {

		     CString strTemp = _T("");

			 int iLen = str->GetLength();

			 int j = 1;

			 while(str->GetAt(iLen - j) != ' ')

				 j++;

			 CString strNum = _T("");

			 strNum.Format("%d",k);

			 k++;

			 str->Format("%s%s%c",str->Left(iLen - j + 1),strNum,'\n');

		 }

	}

	

	//替换原有文件

	FILE *fp2;



	fp2 = fopen(strFileNam,"w+");



	POSITION p2 = strList.GetHeadPosition();

	while(p2)

	{

		 str = &strList.GetNext(p2);

		 fputs(str->GetBuffer(0),fp2);

	}

	fclose(fp2);



	strList.RemoveAll();

	

	

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -