#include <winver.h> // winver.lib为对应的库文件,m_sTitle为theApp的一个变量,
char m_sTitle[MAX_PATH];
DWORD dwSize,dwHandle;
BYTE *byData, *lpFileDes,*lpVers;
char sAppName[MAX_PATH];//,sTitle[256];
CString strVersion;
unsigned int uLen;
char *sTmp;
//获得版本号 s
printf(sAppName,"%s.exe",AfxGetApp()->m_pszExeName); //若为MFC程序, 可用此句获得当前程序(或DLL)文件所在目录 dwSize=GetFileVersionInfoSize(sAppName,&dwHandle);
byData=new BYTE[dwSize+10];
GetFileVersionInfo(sAppName,0,dwSize,byData);
VerQueryValue(byData,TEXT("//StringFileInfo//080404B0//ProductVersion"),(void **)&lpVers,&uLen); //040904B0为英文 080404B0为中文
VerQueryValue(byData,TEXT("//StringFileInfo//080404B0//FileDescription"),(void **)&lpFileDes,&uLen);
//去掉版本号的最后一位,并将','改为'.'
strVersion=lpVers; strVersion.Replace(",",".");
strVersion.Replace(" ","");
strVersion=strVersion.Left(strVersion.ReverseFind('.'));
sprintf(m_sTitle," 项目名Version %s",strVersion);
SetWindowText(theApp.m_sTitle); //显示版本号