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