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
    }
  • 相关阅读:
    C#加密解密
    软件推广常去网站
    C#双缓冲
    C#截图相关代码
    C# 如何在空间运行时调整控件位置和大小
    微信小程序蓝牙打印机demo
    解决办法 not Signedoffby author/committer/uploader in commit message footer
    C# 多线程任务 Task
    2019 TFUG 成都 Coding Lab 圆满结束
    微信小程序元素的定位相对绝对固定
  • 原文地址:https://www.cnblogs.com/eaglexmw/p/11172127.html
Copyright © 2011-2022 走看看