在关于对话框中,自动获取当前程序的版本,以显示
在关于对话框中,自动获取当前程序的版本,以显示
在CAboutDlg的OnInitDialog接口添加如下代码,将自动从当前程序EXE文件中读取版本信息,并显示在指定CStatic中
BOOL CAboutDlg::OnInitDialog()
{
CDialogEx::OnInitDialog();//读取EXE文件所在路径 auto handle =GetModuleHandle(NULL);if (NULL !=handle) {//获得EXE文件路径 std::wstring install_dir_;
WCHAR dir[MAX_PATH]= {0};
GetModuleFileName(handle, dir, MAX_PATH);
DWORD dwHandle;
DWORD dwDataSize= ::GetFileVersionInfoSize(dir, &dwHandle);if (dwDataSize != 0) {//BYTE *strBuff = new BYTE[dwDataSize]; std::string strBuff(dwDataSize + 1, '\0');//读取文件的版本号信息 if (GetFileVersionInfo(dir, NULL, dwDataSize, &strBuff[0])){//获取文件版本号 UINT nQuerySize;
VS_FIXEDFILEINFO* pVsffi =NULL;if ( ::VerQueryValue((void **)&strBuff[0], _T("\\"), (void**)&pVsffi, &nQuerySize) )
{//获取到界面数据 CString strText;
m_file_version_.GetWindowText(strText);//格式化输出 CString strResult;
strResult.Format(strText.GetBuffer(),
HIWORD(pVsffi->dwFileVersionMS),
LOWORD(pVsffi->dwFileVersionMS),
HIWORD(pVsffi->dwFileVersionLS),
LOWORD(pVsffi->dwFileVersionLS) );//重新设置下去 m_file_version_.SetWindowText(strResult);
}
}
}
}return TRUE; //return TRUE unless you set the focus to a control//异常: OCX 属性页应返回 FALSE }