www.pudn.com > MultiMonitor.rar > 操作系统版本获得.txt, change:2011-06-28,size:5269b


 /** @brief 操作系统版本定义 */ 
    enum WinVerDef 
    { 
        WIN_VER_UNKNOWN = -1, 
        WIN_VER_95 = 0, 
        WIN_VER_98, 
        WIN_VER_ME, 
        WIN_VER_NT4, 
        WIN_VER_2K, 
        WIN_VER_XP, 
        WIN_VER_XP64, 
        WIN_VER_2K3, 
        WIN_VER_2K3R2, 
        WIN_VER_VISTA, 
        WIN_VER_2K8, 
        WIN_VER_2K8R2, 
        WIN_VER_WIN7, 
    }; 
    /* 
 
            @brief          判断当前操作系统是否比指定操作系统更新 
 
            @see            WinVerDef 
 
            @param          [in]    specVer 指定的操作系统版本 
 
            @param          [out]   iResult 返回结果\n 
 
                                    返回结果大于0表示当前操作系统比指定操作系统新;\n 
 
                                    返回结果等于0表示当前操作系统和指定操作系统相同;\n 
 
                                    返回结果小于0表示当前操作系统比指定操作系统旧。 
 
            @retval         TRUE    功能执行成功,根据iResult参数进行版本比较判断 
 
            @retval         FALSE   功能执行失败 
 
            @note           None 
 
            @exception      None 
 
    */ 
 
    BOOL IsOlderSystem( WinVerDef specVer, INT* iResult ); 
 
    /** 
 
            @brief          返回当前操作系统版本 
 
            @see            WinVerDef 
 
            @param          [out]   winVer  当前操作系统版本的枚举值 
 
            @return         TRUE    功能执行成功,winVer参数返回操作系统版本 
 
            @return         FALSE   功能执行失败 
 
            @note           None 
 
            @exception      None 
 
    */ 
 
    BOOL GetWindowsVersion( WinVerDef* winVer ); 
 
// cpp 
 
// 定义目前存在的操作系统主版本号 
 
enum WinVerMajor 
{ 
    WIN_MAJOR_NT4_ME_98_95          = 4, 
    WIN_MAJOR_2K3R2_2K3_XP_2K       = 5, 
    WIN_MAJOR_WIN7_2K8R2_2K8_VISTA  = 6, 
}; 
 
// 定义目前存在的操作系统次版本号 
 
enum WinVerminor 
{ 
    WIN_MINOR_2K8_VISTA_2K_NT4_95   = 0, 
    WIN_MINOR_WIN7_2K8R2_XP         = 1, 
    WIN_MINOR_2K3R2_2K3_XP64        = 2, 
    WIN_MINOR_98                    = 10, 
    WIN_MINOR_ME                    = 90, 
}; 
 
typedef void (WINAPI *GetNativeSystemInfoFunc)(LPSYSTEM_INFO); 
 
/** @brief 返回当前的操作系统版本 */ 
 
BOOL GetWindowsVersion( WinVerDef* winVer ) 
{ 
    OSVERSIONINFOEX osversionInfo; 
    ZeroMemory( &osversionInfo, sizeof(osversionInfo) ); 
    osversionInfo.dwOSVersionInfoSize = sizeof(osversionInfo); 
    *winVer = WIN_VER_UNKNOWN; 
    if ( NULL == winVer || FALSE == GetVersionEx((LPOSVERSIONINFO)&osversionInfo) ) 
    { 
        return FALSE; 
    } 
    switch( osversionInfo.dwMajorVersion ) 
    { 
    case WIN_MAJOR_NT4_ME_98_95: 
        switch( osversionInfo.dwMinorVersion ) 
        { 
        case WIN_MINOR_2K8_VISTA_2K_NT4_95: 
            if ( VER_PLATFORM_WIN32_NT == osversionInfo.dwPlatformId ) 
            { 
                *winVer = WIN_VER_NT4; 
            } 
            else 
            { 
                *winVer = WIN_VER_95; 
            } 
            break; 
        case WIN_MINOR_98: 
            *winVer = WIN_VER_98; 
            break; 
        case WIN_MINOR_ME: 
            *winVer = WIN_VER_ME; 
            break; 
        default: 
            break; 
        } 
        break; 
    case WIN_MAJOR_2K3R2_2K3_XP_2K: 
        switch( osversionInfo.dwMinorVersion ) 
        { 
        case WIN_MINOR_2K8_VISTA_2K_NT4_95: 
            *winVer = WIN_VER_2K; 
            break; 
        case WIN_MINOR_WIN7_2K8R2_XP: 
            *winVer = WIN_VER_XP; 
            break; 
        case WIN_MINOR_2K3R2_2K3_XP64: 
            if ( VER_NT_WORKSTATION == osversionInfo.wProductType ) 
            { 
                *winVer = WIN_VER_XP64; 
                break; 
            } 
            if ( 0 != GetSystemMetrics( SM_SERVERR2 ) ) 
            { 
                *winVer = WIN_VER_2K3R2; 
            } 
            else 
            { 
                *winVer = WIN_VER_2K3; 
            } 
            break; 
        default: 
            break; 
        } 
        break; 
    case WIN_MAJOR_WIN7_2K8R2_2K8_VISTA: 
        switch( osversionInfo.dwMinorVersion ) 
        { 
        case WIN_MINOR_2K8_VISTA_2K_NT4_95: 
            if ( VER_NT_WORKSTATION == osversionInfo.wProductType ) 
            { 
                *winVer = WIN_VER_VISTA; 
            } 
            else 
            { 
                *winVer = WIN_VER_2K8; 
            } 
            break; 
        case WIN_MINOR_WIN7_2K8R2_XP: 
            if ( VER_NT_WORKSTATION == osversionInfo.wProductType ) 
            { 
                *winVer = WIN_VER_WIN7; 
            } 
            else 
            { 
                *winVer = WIN_VER_2K8R2; 
            } 
            break; 
        default: 
            break; 
        } 
        break; 
    default: 
        break; 
    } 
    return TRUE; 
} 
 
/** @brief 判断当前操作系统是否比sepcVer指定的系统更新 */ 
 
BOOL IsOlderSystem( WinVerDef specVer, INT* iResult ) 
{ 
    if ( NULL == iResult ) 
    { 
        return FALSE; 
    } 
    WinVerDef currVer = WIN_VER_UNKNOWN; 
    if ( FALSE == GetWindowsVersion( &currVer ) || WIN_VER_UNKNOWN == currVer ) 
    { 
        return FALSE; 
    } 
    else 
    { 
        *iResult = currVer - specVer; 
    } 
    return TRUE; 
}