home *** CD-ROM | disk | FTP | other *** search
/ QBasic & Borland Pascal & C / Delphi5.iso / C / BC_502 / PVIEW95.PAK / INIT.C < prev    next >
Encoding:
C/C++ Source or Header  |  1997-05-06  |  5.3 KB  |  141 lines

  1. // THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
  2. // ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
  3. // THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
  4. // PARTICULAR PURPOSE.
  5. //
  6. // Copyright (C) 1993-1995  Microsoft Corporation.  All Rights Reserved.
  7. //
  8. //  MODULE:   init.c
  9. //
  10. //  PURPOSE:  Performs application and instance specific initialization.
  11. //
  12. //  FUNCTIONS:
  13. //    InitApplication() - Initializes window data and registers window.
  14. //
  15. //  COMMENTS:
  16. //
  17.  
  18. #include <windows.h>            // required for all Windows applications
  19. #include "globals.h"            // prototypes specific to this application
  20. #include "resource.h"
  21. #include "procthrd.h"
  22.  
  23. HINSTANCE hInst;                // current instance
  24.  
  25. char szAppName[9];              // The name of this application
  26. char szTitle[40];               // The title bar text
  27.  
  28.  
  29. //
  30. //  FUNCTION: InitApplication(HINSTANCE, int)
  31. //
  32. //  PURPOSE: Initializes window data and registers window class.
  33. //
  34. //  PARAMETERS:
  35. //    hInstance - The handle to the instance of this application that
  36. //                is currently being executed.
  37. //    nCmdShow  - Specifies how the main window is to be displayed.
  38. //
  39. //  RETURN VALUE:
  40. //    TRUE  - Success
  41. //    FALSE - Initialization failed
  42. //
  43. //  COMMENTS:
  44. //
  45. //    This function is called at application initialization time.  It
  46. //    performs initialization tasks for the current application instance.
  47. //    Unlike Win16, in Win32, each instance of an application must register
  48. //    window classes.
  49. //
  50. //    In this function, we initialize a window class by filling out a data
  51. //    structure of type WNDCLASS and calling the Windows RegisterClass()
  52. //    function.  Then we create the main window and show it.
  53. //
  54. //
  55.  
  56. BOOL InitApplication(HINSTANCE hInstance, int nCmdShow)
  57. {
  58.     WNDCLASSEX wc;
  59.     HWND       hwnd; // Main window handle.
  60.  
  61.  
  62.     // Dynamically initialize 32-bit Toolhelp functions.  These only exist
  63.     // in Windows 95.
  64.     if (!InitToolhelp32())
  65.     {
  66.         MessageBox(NULL, 
  67.                    "PView95 requires Windows 95\nPlease hit OK to exit.",
  68.                    "Incorrect Version",
  69.                    MB_OK);
  70.         return FALSE;
  71.     }
  72.  
  73.     // Load the application name and description strings.
  74.  
  75.     LoadString(hInstance, IDS_APPNAME, szAppName, sizeof(szAppName));
  76.     LoadString(hInstance, IDS_DESCRIPTION, szTitle, sizeof(szTitle));
  77.  
  78.     // Save the instance handle in static variable, which will be used in
  79.     // many subsequence calls from this application to Windows.
  80.  
  81.     hInst = hInstance; // Store instance handle in our global variable
  82.  
  83.     // Fill in window class structure with parameters that describe the
  84.     // main window.
  85.  
  86.     wc.cbSize        = sizeof(WNDCLASSEX);
  87.     wc.style         = CS_HREDRAW | CS_VREDRAW; // Class style(s).
  88.     wc.lpfnWndProc   = (WNDPROC)WndProc;        // Window Procedure
  89.     wc.cbClsExtra    = 0;                       // No per-class extra data.
  90.     wc.cbWndExtra    = 0;                       // No per-window extra data.
  91.     wc.hInstance     = hInstance;               // Owner of this class
  92.     wc.hIcon         = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_APPICON)); // Icon name from .RC
  93.     wc.hCursor       = LoadCursor(NULL, IDC_ARROW); // Cursor
  94.     wc.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1); // Default color
  95.     wc.lpszMenuName  = szAppName;               // Menu name from .RC
  96.     wc.lpszClassName = szAppName;               // Name to register as
  97.     wc.hIconSm       = LoadImage(hInstance,        // Load small icon image
  98.                                  MAKEINTRESOURCE(IDI_APPICON),
  99.                                  IMAGE_ICON,
  100.                                  GetSystemMetrics(SM_CXSMICON),
  101.                                  GetSystemMetrics(SM_CYSMICON),
  102.                                  0);
  103.  
  104.     // Register the window class and return FALSE if unsuccesful.
  105.  
  106.     if (!RegisterClassEx(&wc))
  107.     {
  108.         //Assume we are running on NT where RegisterClassEx() is
  109.         //not implemented, so let's try calling RegisterClass().
  110.  
  111.         if (!RegisterClass((LPWNDCLASS)&wc.style))
  112.             return FALSE;
  113.     }
  114.  
  115.     // Create a main window for this application instance.
  116.     hwnd = CreateWindow(szAppName,           // See RegisterClass() call
  117.                         szTitle,             // Text for window title bar
  118.                         WS_OVERLAPPEDWINDOW, // Window style
  119.                         CW_USEDEFAULT,       // Use default horizontal position
  120.                         CW_USEDEFAULT,       // Use default vertical position
  121.                         500, 300,            // Initial size
  122.                         NULL,                // Overlapped has no parent
  123.                         NULL,                // Use the window class menu
  124.                         hInstance,           // This instance owns this window
  125.                         NULL                 // Don't need data in WM_CREATE
  126.     );
  127.  
  128.     // If window could not be created, return "failure"
  129.     if (!hwnd)
  130.         return FALSE;
  131.  
  132.     // Make the window visible; update its client area; and return "success"
  133.     ShowWindow(hwnd, nCmdShow);  // Show the window
  134.     UpdateWindow(hwnd);          // Sends WM_PAINT message
  135.  
  136.     return TRUE;                 // We succeeded...
  137. }
  138.  
  139.  
  140.   
  141.