⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 about.c

📁 一个用vc
💻 C
📖 第 1 页 / 共 2 页
字号:
//  hwnd            Window handle for the dialog box window
//  dwPlatformId    Hardware platform ID returned by GetVersionEx
//
//  PURPOSE:        Displays the processor's version
//
//  COMMENTS:
//

static void
displayProcessorVersionInfo (HWND hwnd)
{
    BOOL        Recognized ;
    HINSTANCE   hinst ;
    SYSTEM_INFO si ;
    TCHAR       Buffer [256] ;
    TCHAR       Format [256] ;

    // 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) ;
    
    hinst = GetWindowInstance (hwnd) ;      // Get instance for LoadString

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

                case 20:                    // Power PC 620
                    formatMessageFromString (
                        Format,
                        Buffer, DIM (Buffer),
                        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 (!Recognized) {
        switch (si.dwProcessorType) {
            case PROCESSOR_INTEL_386:
                LoadString (hinst, IDS_PROCESSOR_NOREV_INTEL_386,
                            Buffer, DIM (Buffer)) ;
                break ;

            case PROCESSOR_INTEL_486:
                LoadString (hinst, IDS_PROCESSOR_NOREV_INTEL_486,
                            Buffer, DIM (Buffer)) ;
                break ;

            case PROCESSOR_INTEL_PENTIUM:
                LoadString (hinst, IDS_PROCESSOR_NOREV_INTEL_PENTIUM,
                            Buffer, DIM (Buffer)) ;
                break ;

            case PROCESSOR_MIPS_R4000:
                LoadString (hinst, IDS_PROCESSOR_NOREV_MIPS_R4000,
                            Buffer, DIM (Buffer)) ;
                break ;

            case PROCESSOR_ALPHA_21064:
                LoadString (hinst, IDS_PROCESSOR_NOREV_ALPHA_21064,
                            Buffer, DIM (Buffer)) ;
                break ;
        }
    }

    SetDlgItemText (hwnd, IDC_ABOUT_PROCESSORVERSION, Buffer) ;
}

//
//  DWORD formatMessageFromString (LPCTSTR Format, LPTSTR  Buffer, 
//                                                          DWORD nSize, ...)
//
//  Format          Format string containing message insertion markers
//  Buffer          Output string buffer
//  nSize           Size of output string buffer
//  ...             Variable number of optional parameter
//                  
//
//  PURPOSE:        
//                  Convenient helper function for calling formatMessage
//
//  COMMENTS:
//

static DWORD
formatMessageFromString (LPCTSTR Format, LPTSTR  Buffer, DWORD nSize, ...)
{
    DWORD               dwRet ;
    va_list             marker ;

    va_start (marker, nSize) ;              // Initialize variable arguments

    dwRet = FormatMessage (FORMAT_MESSAGE_FROM_STRING,
                           Format, 0, 0,
                           Buffer, nSize,
                           &marker) ;

    va_end (marker) ;                       // Reset variable arguments

    return dwRet ;
}


//
//  void aboutDlg_OnCommand (HWND hwnd, int id, hwnd hwndCtl, UINT codeNotify)
//
//  hwnd            Window handle for the dialog box window
//  id              Specifies the identifier of the menu item, control, or 
//                  accelerator.
//  hwndCtl         Handle of the control sending the message if the message
//                  is from a control, otherwise, this parameter is NULL. 
//  codeNotify      Specifies the notification code if the message is from a 
//                  control. This parameter is 1 when the message is from an
//                  accelerator. This parameter is 0 when the message is from
//                  a menu.
//
//  PURPOSE:
//                  Handle the keyboard and control notifications.
//                  An OK button press, or Enter/Esc keypress
//                  all dismiss the About dialog box.
//                  
//
//  COMMENTS:
//

static
void aboutDlg_OnCommand (HWND hwnd, int id, HWND hwndCtl, UINT codeNotify)
{
    switch (id) {
        case IDOK:                          // OK pushbutton/Enter keypress
        case IDCANCEL:                      // Esc keypress
            EndDialog (hwnd, TRUE) ;        // Dismiss the about dialog box
            break ;

        default:
            break ;
    }
}

//
//  NTTYPE getNTVersion ()
//
//  PURPOSE:        
//                  Determine the specific variant of Windows NT on which
//                  we're running.
//
//  COMMENTS:
//                  Windows NT 4.0 does not follow the documentation
//                  in the knowledgebase. Specifically, both versions set the
//                  appropriate registry key to "LANMANNT" rather than 
//                  "SERVERNT".
//

static NTTYPE
getNTVersion ()
{
    TCHAR Value [256] ;
    DWORD dwType = 0;
    DWORD dwSize = sizeof (Value) ; // sizeof, not DIM
    HKEY  hKey   = NULL ;
    LONG  lStatus ;

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

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

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

    if (0 == _tcsicmp (WinNT, Value))
        return typeWorkstation ;        // Windows NT Workstation
    else if (0 == _tcsicmp (ServerNT, Value))
        return typeServer ;             // Windows NT Server
    else if (0 == _tcsicmp (AdvancedServerNT, Value))
        return typeServer ;             // Windows NT Advanced Server (3.1)

    return typeDefault ;                // Windows NT
}

void doAbout(HWND hwnd)
{
 HINSTANCE hinst = GetWindowInstance (hwnd) ;
 DialogBox (hinst, MAKEINTRESOURCE (IDD_ABOUTBOX), hwnd, 
                                                     (DLGPROC) aboutDlgProc) ;
}

void doHow(HWND hwnd)
    {
     HINSTANCE hinst = GetWindowInstance (hwnd) ;
     DialogBox (hinst, MAKEINTRESOURCE (IDD_HOWTOBOX), hwnd, (DLGPROC) aboutDlgProc) ;
    }

⌨️ 快捷键说明

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