zoukankan      html  css  js  c++  java
  • 在关于对话框中,自动获取当前程序的版本,以显示

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

    在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, '');
                //读取文件的版本号信息
                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
    }
  • 相关阅读:
    裂项相消
    斜率和问题
    抛物线与椭圆
    数列通项
    双曲线离心率
    优化问题
    单调性讨论
    角平分线
    隐零点
    自动任务调度系统
  • 原文地址:https://www.cnblogs.com/eaglexmw/p/11172127.html
Copyright © 2011-2022 走看看