vc获取程序本身的版本号

void CVersionInfoDlg::OnOK()  [喝小酒的网摘]http://blog.hehehehehe.cn/a/1666.htm
{
    // TODO: Add extra validation here
    
    //CDialog::OnOK();
    GetApplicationVersion();
}

void CVersionInfoDlg::GetApplicationVersion()
{
    TCHAR szFullPath[MAX_PATH];
    DWORD dwVerInfoSize = 0;
    DWORD dwVerHnd;
    VS_FIXEDFILEINFO * pFileInfo;
    
    GetModuleFileName(NULL, szFullPath, sizeof(szFullPath));
    dwVerInfoSize = GetFileVersionInfoSize(szFullPath, &dwVerHnd);
    if (dwVerInfoSize)
    {
        // If we were able to get the information, process it:
        HANDLE  hMem;
        LPVOID  lpvMem;
        unsigned int uInfoSize = 0;
        
        hMem = GlobalAlloc(GMEM_MOVEABLE, dwVerInfoSize);
        lpvMem = GlobalLock(hMem);
        GetFileVersionInfo(szFullPath, dwVerHnd, dwVerInfoSize, lpvMem);
        
        ::VerQueryValue(lpvMem, (LPTSTR)_T("\"), (void**)&pFileInfo, &uInfoSize);
        
        int ret = GetLastError();
        WORD m_nProdVersion[4];
        
        // Product version from the FILEVERSION of the version info resource 
        m_nProdVersion[0] = HIWORD(pFileInfo->dwProductVersionMS); 
        m_nProdVersion[1] = LOWORD(pFileInfo->dwProductVersionMS);
        m_nProdVersion[2] = HIWORD(pFileInfo->dwProductVersionLS);
        m_nProdVersion[3] = LOWORD(pFileInfo->dwProductVersionLS); 
        
        CString strVersion ;
        strVersion.Format(_T("The file's version : %d.%d.%d.%d"),m_nProdVersion[0],
            m_nProdVersion[1],m_nProdVersion[2],m_nProdVersion[3]);
        
        GlobalUnlock(hMem);
        GlobalFree(hMem);
        
        AfxMessageBox(strVersion);
    }


更多请参考

你可能感兴趣的:(MFC)