home *** CD-ROM | disk | FTP | other *** search
/ Total Destruction / Total_Destruction.iso / addons / Lccwin32.exe / Lccwin32 / lccpub / demo / simple / INIT.C < prev    next >
Encoding:
C/C++ Source or Header  |  1996-12-28  |  4.1 KB  |  111 lines

  1. #include <windows.h>            // required for all Windows applications
  2. #include "globals.h"            // prototypes specific to this application
  3. #include "resource.h"
  4.  
  5. HINSTANCE hInst;                // current instance
  6.  
  7. char szAppName[9];              // The name of this application
  8. char szTitle[40];               // The title bar text
  9.  
  10. BOOL InitApplication(HINSTANCE hInstance)
  11. {
  12.     WNDCLASSEX wc;
  13.  
  14.     // Load the application name and description strings.
  15.  
  16.     LoadString(hInstance, IDS_APPNAME, szAppName, sizeof(szAppName));
  17.     LoadString(hInstance, IDS_DESCRIPTION, szTitle, sizeof(szTitle));
  18.  
  19.     // Fill in window class structure with parameters that describe the
  20.     // main window.
  21.  
  22.     wc.cbSize        = sizeof(WNDCLASSEX);
  23.     wc.hIconSm       = LoadImage(hInstance,        // Load small icon image
  24.                                  MAKEINTRESOURCE(IDI_APPICON),
  25.                                  IMAGE_ICON,
  26.                                  16, 16,
  27.                                  0);
  28.     wc.style         = CS_HREDRAW | CS_VREDRAW; // Class style(s).
  29.     wc.lpfnWndProc   = (WNDPROC)WndProc;        // Window Procedure
  30.     wc.cbClsExtra    = 0;                       // No per-class extra data.
  31.     wc.cbWndExtra    = 0;                       // No per-window extra data.
  32.     wc.hInstance     = hInstance;               // Owner of this class
  33.     wc.hIcon         = LoadIcon(hInstance, szAppName); // Icon name from .RC
  34.     wc.hCursor       = LoadCursor(NULL, IDC_ARROW); // Cursor
  35.     wc.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1); // Default color
  36.     wc.lpszMenuName  = szAppName;               // Menu name from .RC
  37.     wc.lpszClassName = szAppName;               // Name to register as
  38.  
  39.     // Register the window class and return FALSE if unsuccesful.
  40.  
  41.     if (!RegisterClassEx(&wc))
  42.     {
  43.         if (!RegisterClass((LPWNDCLASS)&wc.style))
  44.            return FALSE;
  45.     }
  46.     //
  47.     // **TODO** Call module specific application initialization functions here.
  48.     //
  49.  
  50.     return TRUE;
  51. }
  52.  
  53.  
  54. //
  55. //  FUNCTION:  InitInstance(HINSTANCE, int)
  56. //
  57. //  PURPOSE:  Saves instance handle and creates main window.
  58. //
  59. //  PARAMTERS:
  60. //    hInstance - The handle to the instance of this application that
  61. //          is currently being executed.
  62. //    nCmdShow - Specifies how the main window is to be diplayed.
  63. //
  64. //  RETURN VALUE:
  65. //    TRUE - Success
  66. //    FALSE - Initialization failed
  67. //
  68. //  COMMENTS:
  69. //    This function is called at initialization time for every instance of
  70. //    this application.  This function performs initialization tasks that
  71. //    cannot be shared by multiple instances.
  72. //
  73. //    In this case, we save the instance handle in a static variable and
  74. //    create and display the main program window.
  75. //
  76.  
  77. BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
  78. {
  79.     HWND    hwnd; // Main window handle.
  80.  
  81.     // Save the instance handle in static variable, which will be used in
  82.     // many subsequence calls from this application to Windows.
  83.  
  84.     hInst = hInstance; // Store instance handle in our global variable
  85.  
  86.     // Create a main window for this application instance.
  87.     hwnd = CreateWindow(szAppName,           // See RegisterClass() call.
  88.                         szTitle,             // Text for window title bar.
  89.                         WS_OVERLAPPEDWINDOW, // Window style.
  90.                         CW_USEDEFAULT, 0,    // Use default positioning
  91.                         CW_USEDEFAULT, 0,    // Use default size
  92.                         NULL,                // Overlapped has no parent.
  93.                         NULL,                // Use the window class menu.
  94.                         hInstance,           
  95.                         NULL);               
  96.     
  97.     // If window could not be created, return "failure"
  98.     if (!hwnd)
  99.         return FALSE;
  100.  
  101.     //
  102.     // **TODO** Call module specific instance initialization functions here.
  103.     //
  104.  
  105.     // Make the window visible; update its client area; and return "success"
  106.     ShowWindow(hwnd, nCmdShow); // Show the window
  107.     UpdateWindow(hwnd);         // Sends WM_PAINT message
  108.  
  109.     return TRUE;                // We succeeded...
  110. }
  111.