about.cpp

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

CPP
502
字号
// About.cpp : implementation file
//

#include "stdafx.h"

#include "help.h"
#include "IOExplorer.h"
#include "About.h"
#include "winver.h"
#include "WinReg.h"

#define DIM(x) (sizeof(x) / sizeof(x[0]))

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

static DWORD aContextIds [] = { 
#if 0
    IDC_ABOUT_FILEDESCRIPTION,  IDH_ABOUT_FILEDESCRIPTION,
    IDC_ABOUT_VERSION,          IDH_ABOUT_VERSION,
    IDC_ABOUT_LEGALCOPYRIGHT,   IDH_ABOUT_LEGALCOPYRIGHT,
    IDC_ABOUT_COMMENTS,         IDH_ABOUT_COMMENTS,
    IDC_ABOUT_OSVERSION,        IDH_ABOUT_OSVERSION,
    IDC_ABOUT_PROCESSORVERSION, IDH_ABOUT_PROCESSORVERSION,
    IDC_ABOUT_LEGALTRADEMARKS,  IDH_ABOUT_LEGALTRADEMARKS,
#endif
    0,                          0
} ;

/////////////////////////////////////////////////////////////////////////////
// CAbout dialog


CAbout::CAbout(CWnd* pParent /*=NULL*/)
        : CDialog(CAbout::IDD, pParent)
{
        //{{AFX_DATA_INIT(CAbout)
                // NOTE: the ClassWizard will add member initialization here
        //}}AFX_DATA_INIT
}


void CAbout::DoDataExchange(CDataExchange* pDX)
{
        CDialog::DoDataExchange(pDX);
        //{{AFX_DATA_MAP(CAbout)
        DDX_Control(pDX, IDC_ABOUT_LEGALCOPYRIGHT, c_LegalCopyright);
        DDX_Control(pDX, IDC_ABOUT_FILEDESCRIPTION, c_FileDescription);
        //}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CAbout, CDialog)
        //{{AFX_MSG_MAP(CAbout)
        ON_WM_CONTEXTMENU()
        ON_WM_HELPINFO()
	ON_BN_CLICKED(IDC_MORE, OnMore)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CAbout message handlers

void CAbout::OnContextMenu(CWnd* pWnd, CPoint point) 
{
    AfxGetApp()->WinHelp (HELP_CONTEXTMENU, (DWORD) (LPVOID) aContextIds) ;
}

BOOL CAbout::OnHelpInfo(HELPINFO* pHelpInfo) 
{
    ASSERT (HELPINFO_WINDOW == pHelpInfo->iContextType) ;

    if (HELPINFO_WINDOW == pHelpInfo->iContextType) {    // Must be for a control!

        int             nID ;
        int             nIndex ;

        // Get the control's window handle
        HWND hwndCtl = (HWND)pHelpInfo->hItemHandle ;

        ASSERT (NULL != hwndCtl) ;
        ASSERT (::IsWindow (hwndCtl)) ;

        // Get this control's ID
        nID = ::GetDlgCtrlID (hwndCtl) ;

        // Don't bother running WinHelp unless we have help for the control
        for (nIndex = 0 ; nIndex < DIM (aContextIds) - 2; nIndex += 2) {
            if (aContextIds [nIndex] == (DWORD) nID) {
                AfxGetApp()->WinHelp (HELP_WM_HELP, 
                                     (DWORD) (LPVOID) aContextIds) ;
                return TRUE ;
            }
        }
    }
        
        return CDialog::OnHelpInfo(pHelpInfo);
}

static const TCHAR szValueNameBase [] = TEXT("\\StringFileInfo\\040904E4\\") ;
static const TCHAR szProductName []   = TEXT("ProductName") ;

// Number of characters in the base portion of the value name string
#define BASECHARS    (DIM(szValueNameBase) - 1)

void CAbout::DisplayExecutableVersionInfo ()
{
    BOOL                bResult ;               // Result of Boolean functions
    DWORD               dwVerInfoSize ;         // Size of version information
    DWORD               dwHandle ;              // Extraneous but required parameter
    HMODULE             hmod ;                  // Application's module handle
    LPVOID              pVerInfo ;              // File version info pointer
    LPVOID              pValue ;                // Value from version info
    TCHAR               szFullPath [_MAX_PATH] ;// Application executable path
    TCHAR               szValueName [256] ;     // Name of value to retrieve
    UINT                uLength ;               // Length of retrieved value
    CWnd *              Ctl;                    // Control

    // Get the full path to this executable file
    hmod = ::GetModuleHandle (NULL) ;
    ::GetModuleFileName (hmod, szFullPath, DIM(szFullPath)) ;

    // Determine the size buffer needed to store the version information:
    dwVerInfoSize = ::GetFileVersionInfoSize (szFullPath, &dwHandle) ;
    if (0 == dwVerInfoSize)
        return ;

    // Allocate a buffer for the version info block
    pVerInfo = malloc (dwVerInfoSize) ;
    ASSERT (NULL != pVerInfo) ;
    if (NULL == pVerInfo)
        return ;

    // Read the version info block into the buffer
    VERIFY(::GetFileVersionInfo (szFullPath, dwHandle, dwVerInfoSize, pVerInfo)) ;

    // Build value name base string...
        lstrcpy (szValueName, szValueNameBase) ;
        
        // Build the \StringFileInfo\040904E4\ProductName value name
        lstrcpy (szValueName + BASECHARS, szProductName) ;

        // Retrieve the value
        bResult = ::VerQueryValue (pVerInfo, szValueName, &pValue, &uLength) ;

    // Format the output for the dialog caption
    // Get the current caption then append to it the ProductName value
        GetWindowText (szValueName, sizeof (szValueName) / sizeof(TCHAR)) ;
        lstrcat (szValueName, (LPCTSTR)pValue) ;

    // Change the dialog caption - normally "About <ProductName>"
        SetWindowText (szValueName) ;

        // For each control in the dialog...
    //  fetch the version info name from the control's initial window text.
    //  retrieve the value with that name,
    //  change the control's window text to the retrieved value.
    // Technique derived from GENERIC.C.

    
    Ctl = GetWindow (GW_CHILD) ;
    while (NULL != Ctl) 
       {
        // Build value name base string...
        lstrcpy (szValueName, szValueNameBase) ;
        
        // Build the \StringFileInfo\040904E4\<ControlText> value name
        // The Win32 API contains the following predefined version information strings:
        //     CompanyName              LegalCopyright     
        //     FileDescription          OriginalFilename   
        //     FileVersion              ProductName        
        //     InternalName             ProductVersion     
        
        // Get the control's text...
        Ctl->GetWindowText ( szValueName + BASECHARS,
                             DIM(szValueName) - BASECHARS) ;

        // Retrieve the value
        bResult = ::VerQueryValue (pVerInfo, szValueName, &pValue, &uLength) ;

        // If version information is available and the version information name exists...
        if (bResult)
            // If a value exists for the version information name...
            if (0 != uLength && NULL != pValue)
                // Change the control's text to the version information value
                Ctl->SetWindowText ((LPCTSTR)pValue) ;

        Ctl = Ctl->GetWindow (GW_HWNDNEXT) ;
    }

    // Free the memory for the version information block
    free (pVerInfo) ;
}

void CAbout::DisplayOperatingSystemVersionInfo ()
{
    BOOL      bResult ;
    NTTYPE    NtOsType ;
    TCHAR     OSVer [256] ;
    CString   FormatString ;

    // Get OS version information
    OSVERSIONINFO       osver ;
    osver.dwOSVersionInfoSize = sizeof (osver) ;    // Must initialize size member!

    bResult = ::GetVersionEx (&osver) ;       // Retrieve version info
    ASSERT (FALSE != bResult) ;
    if (FALSE == bResult)
        return ;

    switch (osver.dwPlatformId) 
       {
        case VER_PLATFORM_WIN32_NT:         // Windows NT
            NtOsType = GetNTVersion () ;
            FormatString.LoadString (IDS_PLATFORM_WIN32_NT + NtOsType);
            break ;

        case VER_PLATFORM_WIN32s:           // Win32s on Windows 3.1
            FormatString.LoadString (IDS_PLATFORM_WIN32s);
            break ;

        case VER_PLATFORM_WIN32_WINDOWS:     // Windows 95
            FormatString.LoadString(IDS_PLATFORM_WIN32_WINDOWS);
            // Windows 95 encodes extra info in HIWORD(dwBuildNumber)
            // Remove unwanted junk
            osver.dwBuildNumber = LOWORD (osver.dwBuildNumber) ;
            break ;

        default:                            // Unknown operating system
            FormatString.LoadString(IDS_PLATFORM_UNKNOWN);
            break ;
    }

    wsprintf (OSVer, FormatString,
              osver.dwMajorVersion,
              osver.dwMinorVersion,
              osver.dwBuildNumber) ;
    SetDlgItemText (IDC_ABOUT_OSVERSION, OSVer) ;
}

//
//  void CAbout::DisplayProcessorVersionInfo (DWORD dwPlatformId)
//
//  dwPlatformId    Hardware platform ID returned by GetVersionEx
//
//  PURPOSE:        Displays the processor's version
//
//  COMMENTS:

⌨️ 快捷键说明

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