rf中resourceid_解决VC++ MFC程序resource.h头文件中ID重复问题
解決VC++ MFC程序resource.h頭文件中ID重復(fù)問(wèn)題
2018-12-07
一般MFC開(kāi)發(fā)的時(shí)候,如果有些資源是從其他工程中移植到本工程的,
而在資源移植的時(shí)候都要將對(duì)應(yīng)的資源ID復(fù)制到本工程的resource.h文件中。
此時(shí)不管你在不在本工程中添加資源ID,resource.h文件中的ID可能都有重復(fù)的,一般再添加資源ID后,肯定有重復(fù)的。
可用下列代碼解決此問(wèn)題,將代碼復(fù)制到空的win32控制臺(tái)應(yīng)用程序,將ressource.h拖入編譯后產(chǎn)生可執(zhí)行文件,即可解決此問(wèn)題。
[cpp]view plaincopyprint?
#include?
#include?
#include?
#include?
using?namespace?std;
typedef?struct?{
string?line_header;
string?line_id_name;
int?line_id_value;
bool?ishex;//value值是16進(jìn)制?
bool?isdef;//是id定義字符串?
}FILE_ONE_LINE;
void?handle_error(char?*?err)
{
cout<
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");
}
///文件讀開(kāi)始處理
list?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<
}
else
{
line.line_header?=?temp;
line.isdef?=?false;
l.push_back(line);
//cout<
}
}
if(is)
is.close();
///文件讀處理完畢
int?index=-1;
list::iterator?it?=?l.begin();
for(;it?!=?l.end();it?++)
{
if(index<0)
index?=?it?->line_id_value;
if(it?->line_id_value?>=?100?&&?index?
index?=?it?->line_id_value;
if(it?->line_id_value?>=?1000?&&?index?
index?=?it?->line_id_value;
if(it?->line_id_value?>=?30000?&&?index?
index?=?it?->line_id_value;
if(it?->isdef)
it?->line_id_value?=?index++;
}
///文件寫開(kāi)始
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<line_header<line_id_name<
}
else
{
os<line_header<
}
}
if(os)
os.close();
///文件寫處理完畢
l.clear();
cout<
system("pause");
return?0;
}
_Flash
免責(zé)聲明:本文僅代表文章作者的個(gè)人觀點(diǎn),與本站無(wú)關(guān)。其原創(chuàng)性、真實(shí)性以及文中陳述文字和內(nèi)容未經(jīng)本站證實(shí),對(duì)本文以及其中全部或者部分內(nèi)容文字的真實(shí)性、完整性和原創(chuàng)性本站不作任何保證或承諾,請(qǐng)讀者僅作參考,并自行核實(shí)相關(guān)內(nèi)容。
http://www.pinlue.com/style/images/nopic.gif
總結(jié)
以上是生活随笔為你收集整理的rf中resourceid_解决VC++ MFC程序resource.h头文件中ID重复问题的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: arthas 排查内存溢出_Java程序
- 下一篇: bouml 逆向分析c++_JS逆向之漫