home *** CD-ROM | disk | FTP | other *** search
/ QBasic & Borland Pascal & C / Delphi5.iso / C / BC_502 / BLANDMDI.PAK / INIT.C < prev    next >
Encoding:
C/C++ Source or Header  |  1997-05-06  |  6.0 KB  |  179 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. //    InitInstance() - Saves instance handle and creates main window.
  15. //
  16. //  COMMENTS:
  17. //
  18.  
  19. #include <windows.h>            // required for all Windows applications
  20. #ifdef WIN16
  21. #include "win16ext.h"           // required only for win16 applications
  22. #endif
  23. #include "globals.h"            // prototypes specific to this application
  24. #include "resource.h"
  25.  
  26. HINSTANCE hInst;                // current instance
  27.  
  28. char szAppName[9];              // The name of this application
  29. char szTitle[40];               // The title bar text
  30.  
  31. //
  32. //  FUNCTION: InitApplication(HINSTANCE)
  33. //
  34. //  PURPOSE: Initializes window data and registers window class.
  35. //
  36. //  PARAMETERS:
  37. //    hInstance - The handle to the instance of this application that
  38. //          is currently being executed.
  39. //
  40. //  RETURN VALUE:
  41. //    TRUE - Success
  42. //    FALSE - Initialization failed
  43. //
  44. //  COMMENTS:
  45. //
  46. //    This function is called at initialization time only if no other
  47. //    instances of the application are running.  This function performs
  48. //    initialization tasks that can be done once for any number of running
  49. //    instances.
  50. //
  51. //    In this case, we initialize a window class by filling out a data
  52. //    structure of type WNDCLASS and calling the Windows RegisterClass()
  53. //    function.  Since all instances of this application use the same
  54. //    window class, we only need to do this when the first instance is
  55. //    initialized.
  56. //
  57.  
  58. BOOL InitApplication(HINSTANCE hInstance)
  59. {
  60.     #ifdef WIN16
  61.     WNDCLASS  wc;
  62.     #else
  63.     WNDCLASSEX wc;
  64.     #endif
  65.  
  66.     // Load the application name and description strings.
  67.  
  68.     LoadString(hInstance, IDS_APPNAME, szAppName, sizeof(szAppName));
  69.     LoadString(hInstance, IDS_DESCRIPTION, szTitle, sizeof(szTitle));
  70.  
  71.     // Fill in window class structure with parameters that describe the
  72.     // main window.
  73.  
  74.     #ifndef WIN16
  75.     wc.cbSize        = sizeof(WNDCLASSEX);
  76.     wc.hIconSm       = LoadImage(hInstance,        // Load small icon image
  77.                                  MAKEINTRESOURCE(IDI_APPICON),
  78.                                  IMAGE_ICON,
  79.                                  16, 16,
  80.                                  0);
  81.     #endif
  82.     wc.style         = CS_HREDRAW | CS_VREDRAW; // Class style(s).
  83.     wc.lpfnWndProc   = (WNDPROC)WndProc;        // Window Procedure
  84.     wc.cbClsExtra    = 0;                       // No per-class extra data.
  85.     wc.cbWndExtra    = 0;                       // No per-window extra data.
  86.     wc.hInstance     = hInstance;               // Owner of this class
  87.     wc.hIcon         = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_APPICON)); // Icon name from .RC
  88.     wc.hCursor       = LoadCursor(NULL, IDC_ARROW); // Cursor
  89.     wc.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1); // Default color
  90.     wc.lpszMenuName  = szAppName;               // Menu name from .RC
  91.     wc.lpszClassName = szAppName;               // Name to register as
  92.  
  93.     // Register the window class and return FALSE if unsuccesful.
  94.  
  95.     #ifdef WIN16
  96.     if (!RegisterClass(&wc))
  97.     {
  98.         return FALSE;
  99.     }
  100.     #else
  101.     if (!RegisterClassEx(&wc))
  102.     {
  103.         if (!RegisterClass((LPWNDCLASS)&wc.style))
  104.            return FALSE;
  105.     }
  106.     #endif
  107.     //
  108.     // **TODO** Call module specific application initialization functions here.
  109.     //
  110.  
  111.     // **BlandMDI** Initialize the Multiple Document Interface
  112.  
  113.     if (!InitMDIChild(hInstance))
  114.     {
  115.         return FALSE;
  116.     }
  117.  
  118.     return TRUE;
  119. }
  120.  
  121.  
  122. //
  123. //  FUNCTION:  InitInstance(HINSTANCE, int)
  124. //
  125. //  PURPOSE:  Saves instance handle and creates main window.
  126. //
  127. //  PARAMTERS:
  128. //    hInstance - The handle to the instance of this application that
  129. //          is currently being executed.
  130. //    nCmdShow - Specifies how the main window is to be diplayed.
  131. //
  132. //  RETURN VALUE:
  133. //    TRUE - Success
  134. //    FALSE - Initialization failed
  135. //
  136. //  COMMENTS:
  137. //    This function is called at initialization time for every instance of
  138. //    this application.  This function performs initialization tasks that
  139. //    cannot be shared by multiple instances.
  140. //
  141. //    In this case, we save the instance handle in a static variable and
  142. //    create and display the main program window.
  143. //
  144.  
  145. BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
  146. {
  147.     HWND    hwnd; // Main window handle.
  148.  
  149.     // Save the instance handle in static variable, which will be used in
  150.     // many subsequence calls from this application to Windows.
  151.  
  152.     hInst = hInstance; // Store instance handle in our global variable
  153.  
  154.     // Create a main window for this application instance.
  155.     hwnd = CreateWindow(szAppName,           // See RegisterClass() call.
  156.                         szTitle,             // Text for window title bar.
  157.                         WS_OVERLAPPEDWINDOW, // Window style.
  158.                         CW_USEDEFAULT, 0,    // Use default positioning
  159.                         CW_USEDEFAULT, 0,    // Use default size
  160.                         NULL,                // Overlapped has no parent.
  161.                         NULL,                // Use the window class menu.
  162.                         hInstance,           
  163.                         NULL);               
  164.  
  165.     // If window could not be created, return "failure"
  166.     if (!hwnd)
  167.         return FALSE;
  168.  
  169.     //
  170.     // **TODO** Call module specific instance initialization functions here.
  171.     //
  172.  
  173.     // Make the window visible; update its client area; and return "success"
  174.     ShowWindow(hwnd, nCmdShow); // Show the window
  175.     UpdateWindow(hwnd);         // Sends WM_PAINT message
  176.  
  177.     return TRUE;                // We succeeded...
  178. }
  179.