about.cpp

来自「IO函数调用测试」· C++ 代码 · 共 502 行 · 第 1/2 页

CPP
502
字号
//

void CAbout::DisplayProcessorVersionInfo ()
{
    BOOL                bRecognized ;
    SYSTEM_INFO         si ;
    CString     Buffer;
    CString     Format;

    // Get current system information
    // Zero the structure as Windows 95 and older versions of Windows NT
    // do not initialize *all* fields of the structure (specifically,
    // wProcessorLevel and wProcessorRevision. Unfortunately, the
    // documentation does not say *which* versions of Windows NT do not
    // support setting these fields. Therefore use the new fields if
    // they seem to have been set. otherwise use the "obsolete" fields.

    ZeroMemory (&si, sizeof (si)) ;
    ::GetSystemInfo (&si) ;
    

    // Determine processor architecture
    bRecognized = TRUE ;
    switch (si.wProcessorArchitecture) {
        default:
            bRecognized = FALSE ;
            Buffer.LoadString (IDS_PROCESSOR_ARCHITECTURE_UNKNOWN );
            break ;

        case PROCESSOR_ARCHITECTURE_INTEL:  // Intel
            switch (si.wProcessorLevel) {
                default:
                    bRecognized = FALSE ;
                    Buffer.LoadString ( IDS_PROCESSOR_LEVEL_INTEL_UNKNOWN) ;
                    break ;

                case 3:                     // Intel 80386
                    Format.LoadString (
                                IDS_PROCESSOR_ARCHITECTURE_INTEL_386_486);
                    Buffer.FormatMessage ( Format,
                        TEXT ("80386"),
                        LOBYTE (si.wProcessorRevision)) ;
                    break ;

                case 4:                     // Intel 80486
                    Format.LoadString (
                                IDS_PROCESSOR_ARCHITECTURE_INTEL_386_486);
                    Buffer.FormatMessage ( Format,
                        TEXT ("80486"),
                        LOBYTE (si.wProcessorRevision)) ;
                    break ;

                case 5:                     // Intel Pentium
                    Format.LoadString (
                                IDS_PROCESSOR_ARCHITECTURE_INTEL_PENTIUM);
                    Buffer.FormatMessage ( Format,
                        TEXT ("Pentium"),
                        HIBYTE (si.wProcessorRevision),
                        LOBYTE (si.wProcessorRevision)) ;
                    break ;
            }
            break ;

        case PROCESSOR_ARCHITECTURE_MIPS:   // MIPS
            switch (si.wProcessorLevel) {   // 00xx - xx is 8-bit implementation #
                Format.LoadString (IDS_PROCESSOR_ARCHITECTURE_MIPS);
                default:
                    bRecognized = FALSE ;
                    Buffer.LoadString (IDS_PROCESSOR_LEVEL_MIPS_UNKNOWN);
                    break ;

                case 0x0004:                // MIPS R4000
                    Buffer.FormatMessage (Format,
                        TEXT ("R4000"),
                        LOBYTE (si.wProcessorRevision)) ;
                    break ;
            }
            break ;

        case PROCESSOR_ARCHITECTURE_ALPHA:  // Alpha
            Format.LoadString (IDS_PROCESSOR_ARCHITECTURE_ALPHA);
            switch (si.wProcessorLevel) {   // xxxx - 16-bit processor version #
                default:
                    bRecognized = FALSE ;
                    Buffer.LoadString (IDS_PROCESSOR_LEVEL_ALPHA_UNKNOWN);
                    break ;

                case 21064:                 // Alpha 21064
                    Buffer.FormatMessage (Format,
                        TEXT ("21064"),
                        (TCHAR)(HIBYTE (si.wProcessorRevision) + (TCHAR) 'A'),
                        LOBYTE (si.wProcessorRevision)) ;
                    break ;

                case 21066:                 // Alpha 21066
                    Buffer.FormatMessage ( Format,
                        TEXT ("21066"),
                        (TCHAR)(HIBYTE (si.wProcessorRevision) + (TCHAR) 'A'),
                        LOBYTE (si.wProcessorRevision)) ;
                    break ;

                case 21164:                 // Alpha 21164
                    Buffer.FormatMessage ( Format,
                        TEXT ("21164"),
                        (TCHAR)(HIBYTE (si.wProcessorRevision) + (TCHAR) 'A'),
                        LOBYTE (si.wProcessorRevision)) ;
                    break ;
            }
            break ;

        case PROCESSOR_ARCHITECTURE_PPC:    // Power PC
            Format.LoadString (IDS_PROCESSOR_ARCHITECTURE_PPC);
            switch (si.wProcessorLevel) {   // xxxx - 16-bit processor version #
                default:
                    bRecognized = FALSE ;
                    Buffer.LoadString (IDS_PROCESSOR_LEVEL_PPC_UNKNOWN);
                    break ;

                case 1:                     // Power PC 601
                    Buffer.FormatMessage (Format,
                        TEXT ("601"),
                        HIBYTE (si.wProcessorRevision),
                        LOBYTE (si.wProcessorRevision)) ;
                    break ;

                case 3:                     // Power PC 603
                    Buffer.FormatMessage (Format,
                        TEXT ("603"),
                        HIBYTE (si.wProcessorRevision),
                        LOBYTE (si.wProcessorRevision)) ;
                    break ;

                case 4:                     // Power PC 604
                    Buffer.FormatMessage (Format,
                        TEXT ("604"),
                        HIBYTE (si.wProcessorRevision),
                        LOBYTE (si.wProcessorRevision)) ;
                    break ;

                case 6:                     // Power PC 603+
                    Buffer.FormatMessage (Format,
                        TEXT ("603+"),
                        HIBYTE (si.wProcessorRevision),
                        LOBYTE (si.wProcessorRevision)) ;
                    break ;

                case 9:                     // Power PC 604+
                    Buffer.FormatMessage (Format,
                        TEXT ("604+"),
                        HIBYTE (si.wProcessorRevision),
                        LOBYTE (si.wProcessorRevision)) ;
                    break ;

                case 20:                    // Power PC 620
                    Buffer.FormatMessage (Format,
                        TEXT ("620"),
                        HIBYTE (si.wProcessorRevision),
                        LOBYTE (si.wProcessorRevision)) ;
                    break ;
            }
            break ;
    }

    // If the processor type isn't yet recognized, check the, supposedly,
    // "obsolete" dwProcessorType field of the SYSTEM_INFO structure for
    // a reasonable value and use it.
    if (!bRecognized) {
        switch (si.dwProcessorType) {
            case PROCESSOR_INTEL_386:
                Buffer.LoadString (IDS_PROCESSOR_NOREV_INTEL_386);
                break ;

            case PROCESSOR_INTEL_486:
                Buffer.LoadString (IDS_PROCESSOR_NOREV_INTEL_486);
                break ;

            case PROCESSOR_INTEL_PENTIUM:
                Buffer.LoadString (IDS_PROCESSOR_NOREV_INTEL_PENTIUM);
                break ;

            case PROCESSOR_MIPS_R4000:
                Buffer.LoadString (IDS_PROCESSOR_NOREV_MIPS_R4000);
                break ;

            case PROCESSOR_ALPHA_21064:
                Buffer.LoadString (IDS_PROCESSOR_NOREV_ALPHA_21064);
                break ;
        }
    }

    SetDlgItemText (IDC_ABOUT_PROCESSORVERSION, Buffer) ;
}

BOOL CAbout::OnInitDialog() 
{
        CDialog::OnInitDialog();
        
        CenterWindow (NULL) ;

        // Update controls with application version info
        DisplayExecutableVersionInfo () ;

        // Update controls with operating system version info
        DisplayOperatingSystemVersionInfo () ;

        // Update controls with processor version info
        DisplayProcessorVersionInfo () ;
        
        return TRUE;  // return TRUE unless you set the focus to a control
                      // EXCEPTION: OCX Property Pages should return FALSE
}

NTTYPE CAbout::GetNTVersion ()
{
    TCHAR      szValue [256] ;
    DWORD      dwType = 0;
    DWORD      dwSize = sizeof (szValue) ;
    HKEY       hKey   = NULL ;
    LONG       lStatus ;

static const TCHAR szProductOptions []   = TEXT("SYSTEM\\CurrentControlSet\\Control\\ProductOptions") ;
static const TCHAR szProductType []      = TEXT("ProductType") ;
static const TCHAR szWinNT []            = TEXT("WINNT") ;      //  Windows NT Workstation is running
static const TCHAR szServerNT []         = TEXT("SERVERNT") ;   //  Windows NT Server (3.5 or later) is running
static const TCHAR szAdvancedServerNT [] = TEXT("LANMANNT") ;   //  Windows NT Advanced Server (3.1) is running

    lStatus = ::RegOpenKeyEx (HKEY_LOCAL_MACHINE,szProductOptions, 0, KEY_QUERY_VALUE, &hKey) ;
    if (ERROR_SUCCESS != lStatus)
        return typeDefault ;            // Windows NT

    lStatus = ::RegQueryValueEx (hKey, szProductType, NULL, &dwType, (LPBYTE)szValue, &dwSize) ; 
    ::RegCloseKey (hKey) ;
    if (ERROR_SUCCESS != lStatus)
        return typeDefault ;            // Windows NT

    if (0 == _tcsicmp (szWinNT, szValue))
        return typeWorkstation ;        // Windows NT Workstation
    else if (0 == _tcsicmp (szServerNT, szValue))
        return typeServer ;             // Windows NT Server
    else if (0 == _tcsicmp (szAdvancedServerNT, szValue))
        return typeAdvancedServer ;     // Windows NT Advanced Server (3.1)

    return typeDefault ;                // Windows NT
}

void CAbout::OnMore() 
{
 AfxGetApp()->WinHelp(AuthorHelp, HELP_CONTEXT);
 CDialog::OnOK();	
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?