码迷,mamicode.com
首页 > 其他好文 > 详细

在关于对话框中,自动获取当前程序的版本,以显示

时间:2019-07-11 20:02:08      阅读:93      评论:0      收藏:0      [点我收藏+]

标签:text   span   win   window   ati   inf   filename   ever   col   

在关于对话框中,自动获取当前程序的版本,以显示

在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
}

 

在关于对话框中,自动获取当前程序的版本,以显示

标签:text   span   win   window   ati   inf   filename   ever   col   

原文地址:https://www.cnblogs.com/eaglexmw/p/11172127.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!