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
    }
  • 相关阅读:
    【jQuery日期处理】两个时间大小的比较
    CSS 盒子模型(Box model)中的 padding 与 margin
    如何优雅地制作精排 ePub —— 个人电子书制作规范及基本样式表
    异常处理 Exception
    Log4net
    HttpServerUtility类
    MVC 数据验证
    BigRender
    CSS中的块级元素与行级元素
    使用jQuery.form插件,实现完美的表单异步提交
  • 原文地址:https://www.cnblogs.com/eaglexmw/p/11172127.html
Copyright © 2011-2022 走看看