解决VC++ MFC程序resource.h头文件中ID重复问题
2012-12-05 16:02
381 查看
一般MFC开发的时候,如果有些资源是从其他工程中移植到本工程的,
而在资源移植的时候都要将对应的资源ID复制到本工程的resource.h文件中。
此时不管你在不在本工程中添加资源ID,resource.h文件中的ID可能都有重复的,一般再添加资源ID后,肯定有重复的。
可用下列代码解决此问题,将代码复制到空的win32控制台应用程序,将ressource.h拖入编译后产生可执行文件,即可解决此问题。
而在资源移植的时候都要将对应的资源ID复制到本工程的resource.h文件中。
此时不管你在不在本工程中添加资源ID,resource.h文件中的ID可能都有重复的,一般再添加资源ID后,肯定有重复的。
可用下列代码解决此问题,将代码复制到空的win32控制台应用程序,将ressource.h拖入编译后产生可执行文件,即可解决此问题。
#include <iostream> #include <fstream> #include <string> #include <list> using namespace std; typedef struct { string line_header; string line_id_name; int line_id_value; bool ishex;//value值是16进制? bool isdef;//是id定义字符串? }FILE_ONE_LINE; void handle_error(char * err) { cout<<err<<endl; system("pause"); exit(-1); } bool chisblank(char ch) { return ch == '\t' || ch == '\r' || ch == '\n' || ch == 32/*空格*/ || ch == '\0'; } int main(int argc,char * argv[]) { char * pfname=NULL; if(argc>=2) pfname = argv[1]; else pfname = "resource.h"; ifstream is(pfname); if(!is) { handle_error("ifstream:open file failed"); } ///文件读开始处理 list<FILE_ONE_LINE> l; char temp[2000]; char str[200]; while(!is.eof()) { is.getline(temp,2000); FILE_ONE_LINE line; line.ishex = false; if( temp[0] == '#' && temp[1] == 'd' && temp[2] == 'e' && temp[3] == 'f' && temp[4] == 'i' && temp[5] == 'n' && temp[6] == 'e' ) { line.isdef = true; char * p=temp; int seg = 0; while(1) { while(chisblank(*p)&&( *p == 32 ||*p == '\t')) { p++; } int i=0; for(;!chisblank(*p);i++,p++) { str[i]=*p; } if(seg == 0) { str[i]='\0'; line.line_header = str; } else if(seg == 1) { for(;i<40;i++) str[i]=' '; str[i]='\0'; line.line_id_name = str; } else if(seg == 2) { str[i]='\0'; if(str[0] == '0' && str[1]=='x') { line.ishex = true; sscanf(str,"%x",&line.line_id_value); } else line.line_id_value = atoi(str); } seg++; if(*p == '\n' || *p == '\0'|| seg >2) break; } l.push_back(line); //cout<<line.line_header<<'\t'<<line.line_id_name<<'\t'<<line.line_id_value<<endl; } else { line.line_header = temp; line.isdef = false; l.push_back(line); //cout<<line.line_header<<endl; } } if(is) is.close(); ///文件读处理完毕 int index=-1; list<FILE_ONE_LINE>::iterator it = l.begin(); for(;it != l.end();it ++) { if(index<0) index = it ->line_id_value; if(it ->line_id_value >= 100 && index < 100) index = it ->line_id_value; if(it ->line_id_value >= 1000 && index < 1000) index = it ->line_id_value; if(it ->line_id_value >= 30000 && index < 30000) index = it ->line_id_value; if(it ->isdef) it ->line_id_value = index++; } ///文件写开始 ofstream os(pfname); if(!os) { is.close(); handle_error("ostream:Open file failed"); } for(it = l.begin();it != l.end();it ++) { if(it ->isdef) { if(!it ->ishex) sprintf(temp,"%d",it ->line_id_value); else sprintf(temp,"0x%04x",it ->line_id_value); os<<it ->line_header<<" "<<it ->line_id_name<<" "<<temp<<'\n'; } else { os<<it ->line_header<<'\n'; } } if(os) os.close(); ///文件写处理完毕 l.clear(); cout<<"changed!OK!"<<endl; system("pause"); return 0; }
相关文章推荐
- 手动修改MFC生成文件图标及Resource.h文件重复定义问题
- MFC程序打开文件对话框出错的问题解决
- VC2005的程序文件分发问题及解决
- 关于VC6创建mfc程序提示缺少头文件或者缺少dll问题的解决
- VC++ 6.0编写MFC程序经常出现的问题及解决方法
- vc2005编译过程中"没有找到MFC80UD.DLL,因此这个程序未能启动.重新安装应用程序可能会修复此问题"? 的彻底解决
- MFC 程序解决CListCtrl控件点击项重复执行的问题
- MFC程序打开文件对话框出错的问题解决
- WinForm程序中两份mdf文件问题的解决
- 安装windows server 2003 datacenter 的 sp2时出现id\syssetup.inf文件找不到无法安装问题的解决方法
- Win7如何手动注册DLL文件以解决程序不能使用的问题
- 转:解决VC2005程序的一个运行错误“由于应用程序的配置不正确,应用程序未能启动,重新安装应用程序可能会纠正这个问题”
- 解决把eclipse程序放到myeclipse下js文件报错问题
- 程序关联文件 获取双击文件路径 MFC/VC
- winsock2.h头文件重复定义链接错误问题解决
- [C#] WinForm程序中两份mdf文件问题的解决
- WinForm程序中两份mdf文件问题的解决
- 无法启动此程序,因为计算机中丢失VCRUNTIME140.dll 尝试重新安装此程序以解决此问题
- VS2005的程序文件分发问题及解决
- 实现VC程序启动时最小化到任务栏(完美解决闪烁问题)