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

📄 initialization.c

📁 一个用vc
💻 C
📖 第 1 页 / 共 2 页
字号:
#include "StdSDK.h"         // Standard application includes
#include "Initialization.h" // For non-static function prototypes
#include "MainFrame.h"      // For non-static function prototypes
#include "DiskHandling.h"   // For non-static function prototypes
#include "resource.h"       // For resource identifiers

//
// Function prototypes for static functions
//

static BOOL registerWindowClasses (HINSTANCE hinst, UINT resPoolID) ;
static HWND createMainFrameWindow (HINSTANCE hinst, int nCmdShow) ;

static TCHAR DiskClass [] = TEXT ("Towers of Hanoi Disk Class") ;

//
// Function prototypes for callback functions
//

//
// Typedefs
//

typedef ATOM (WINAPI* REGISTERCLASSEXPROC)(const LPWNDCLASSEX lpwcex) ;

//
//  BOOL initApplication (HINSTANCE hinst, UINT resPoolID)
//
//  hinst           Application module (instance) handle
//  resPoolID       Resource identifier
//
//  PURPOSE:        Activates the previous instance of this
//                  application, if any, otherwise registers
//                  window class(es) used by the application. 
//
//  COMMENTS:
//
//      Activate a previous instance, if any, by searching for a window
//      created with the same window class name that this instance uses.
//      If found, restore the previous instance's window, if necessary,
//      and make that window the foreground window.
//
//      Register the window class(es) using a WNDCLASSEX structure.
//
//      The specified resPoolID parameter is the UINT resource identifier
//      used to locate the application's main frame window class name,
//      the menu used on the main frame window, the large and small icons
//      for the main frame window.

BOOL
initApplication (HINSTANCE hinst, UINT resPoolID)
{
    HWND       hwnd;
    TCHAR      ClassName [MAX_RESOURCESTRING + 1] ;
    WNDCLASSEX wcex ;

    VERIFY (LoadString (hinst, resPoolID, ClassName, DIM(ClassName))) ;

    // Constrain this application to run single instance
    hwnd = FindWindow (ClassName, NULL) ;
    if (hwnd) {

        // A previous instance of this application is running.

        // Activate the previous instance, tell it what the user
        // requested this instance to do, then abort initialization
        // of this instance.

        if (IsIconic (hwnd))
            ShowWindow (hwnd, SW_RESTORE) ;

        SetForegroundWindow (hwnd) ;

        // Send an application-defined message to the previous
        // instance (or use some other type of IPC mechanism)
        // to tell the previous instance what to do.

        // Determining what to do generally depends on how the
        // user started this instance.

        // Abort this instance's initialization
        return FALSE ;
    }

    /********************************************************************/
    /* Register one class for the main application window and a second  */
    /* for the disk windows.                                            */
    /********************************************************************/

    wcex.cbSize        = sizeof (WNDCLASSEX) ;
    wcex.style         = CS_HREDRAW | CS_VREDRAW | CS_OWNDC ;
    wcex.lpfnWndProc   = mainFrameWndProc ;
    wcex.cbClsExtra    = 0 ;
    wcex.cbWndExtra    = 0 ;
    wcex.hInstance     = hinst ;
    wcex.hIcon         = LoadIcon (hinst, MAKEINTRESOURCE (resPoolID)) ;
    wcex.hCursor       = LoadCursor (NULL, IDC_ARROW) ;
    wcex.hbrBackground = (HBRUSH) (COLOR_WINDOW+1) ;

    wcex.lpszMenuName  = MAKEINTRESOURCE (resPoolID) ;
    wcex.lpszClassName = ClassName ;
    wcex.hIconSm       = LoadImage (hinst,
                                    MAKEINTRESOURCE (resPoolID),
                                    IMAGE_ICON,
                                    GetSystemMetrics (SM_CXSMICON),
                                    GetSystemMetrics (SM_CYSMICON),
                                    LR_SHARED) ;

    // Register the window class and abort the initialization upon failure.
    if (!internalRegisterClass (&wcex))
        return FALSE ;

    /******************************/
    /* Now define the disk class. */
    /******************************/

    /********************************************/
    /* Fetch the name of the disk window class. */
    /********************************************/

    wcex.cbSize        = sizeof (WNDCLASSEX) ;
    wcex.style         = CS_HREDRAW | CS_VREDRAW | CS_SAVEBITS ;
    wcex.lpfnWndProc   = diskWndProc ;
    wcex.cbClsExtra    = 0 ;
    wcex.cbWndExtra    = UGW_DWMAXUSED ;
    wcex.hInstance     = hinst ;
    wcex.hIcon         = LoadIcon (hinst, MAKEINTRESOURCE (resPoolID)) ;
    wcex.hCursor       = LoadCursor (NULL, IDC_ARROW) ;
    wcex.hbrBackground = GetStockObject (NULL_BRUSH) ;

    wcex.lpszMenuName  = NULL ;
    wcex.lpszClassName = DiskClass ;
    wcex.hIconSm       = NULL ;

    // Register the window class and return success/failure status
    return internalRegisterClass (&wcex) ;
}

//
//  BOOL initInstance (HINSTANCE hinst, UINT resPoolID, int nCmdShow)
//
//  hinst           Application module (instance) handle
//  resPoolID       Resource identifier
//  nCmdShow        Initial show window state
//
//  PURPOSE:        Initialize the application
//
//  COMMENTS:
//      Activate a previous instance, if any, by searching for a window
//      created with the same window class name that this instance uses.
//      If found, restore the previous instance's window, if necessary,
//      and make that window the foreground window.
//
//      Register the window class(es) using a WNDCLASSEX structure.
//
//      The specified resPoolID parameter is the UINT resource identifier
//      used to locate the application's main frame window class name,
//      the menu used on the main frame window, the large and small icons
//      for the main frame window.
//

BOOL initInstance (HINSTANCE hinst, UINT resPoolID, int nCmdShow)
{
    HWND  hwnd;
    TCHAR ClassName [MAX_RESOURCESTRING + 1] ;
    int n;

    n = LoadString (hinst, resPoolID, ClassName, DIM(ClassName)) ;

#if defined(UNICODE)
    if(0 == n)
       { /* no Unicode */
        char msg[MAX_RESOURCESTRING + 1];
        char hdr[MAX_RESOURCESTRING + 1];
        LoadStringA(hinst, IDS_NO_UNICODE, msg, DIM(msg));
        LoadStringA(hinst, IDS_APP_TITLE, hdr, DIM(hdr));
        MessageBoxA(NULL, msg, hdr, MB_OK|MB_ICONERROR) ;
        return FALSE;
       } /* no Unicode */
#endif
    VERIFY(n != 0);

    // Constrain this application to run single instance
    hwnd = FindWindow (ClassName, NULL) ;
    if (hwnd) {

        // A previous instance of this application is running.

        // Activate the previous instance, tell it what the user
        // requested this instance to do, then abort initialization
        // of this instance.

        if (IsIconic (hwnd))
            ShowWindow (hwnd, SW_RESTORE) ;

        SetForegroundWindow (hwnd) ;

        // Send an application-defined message to the previous
        // instance (or use some other type of IPC mechanism)
        // to tell the previous instance what to do.

        // Determining what to do generally depends on how the
        // user started this instance.

               // ... <some application-specific code here>

        // Abort this instance's initialization
        return FALSE ;
    }

    // Register all application-specific window classes
    if (!registerWindowClasses (hinst, resPoolID))
        return FALSE ;

    // Initialize the Common Controls DLL
    // You must call this function before using any Common Control
    InitCommonControls () ;

    // Create the application's main frame window
    hwnd = createMainFrameWindow (hinst, nCmdShow);
    if (hwnd == NULL)
        return FALSE ;

    return TRUE;
}


//  int exitInstance (PMSG msg)
//
//  hinst           Pointer to MSG structure
//
//  PURPOSE:        Perform deinitialization and return exit code

⌨️ 快捷键说明

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