home *** CD-ROM | disk | FTP | other *** search
/ QBasic & Borland Pascal & C / Delphi5.iso / C / BC_502 / LISTCTRL.PAK / INIT.C < prev    next >
Encoding:
C/C++ Source or Header  |  1997-05-06  |  5.8 KB  |  158 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. HWND      ghwnd;                // Main window handle.
  25.  
  26. char szAppName[9];              // The name of this application
  27. char szTitle[40];               // The title bar text
  28.  
  29. //
  30. //  FUNCTION: InitApplication(HINSTANCE)
  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. //
  38. //  RETURN VALUE:
  39. //    TRUE - Success
  40. //    FALSE - Initialization failed
  41. //
  42. //  COMMENTS:
  43. //
  44. //    This function is called at initialization time only if no other
  45. //    instances of the application are running.  This function performs
  46. //    initialization tasks that can be done once for any number of running
  47. //    instances.
  48. //
  49. //    In this case, we initialize a window class by filling out a data
  50. //    structure of type WNDCLASS and calling the Windows RegisterClass()
  51. //    function.  Since all instances of this application use the same
  52. //    window class, we only need to do this when the first instance is
  53. //    initialized.
  54. //
  55.  
  56. BOOL InitApplication(HINSTANCE hInstance)
  57. {
  58.     WNDCLASSEX wc;
  59.  
  60.     // Load the application name and description strings.
  61.  
  62.     LoadString(hInstance, IDS_APPNAME, szAppName, sizeof(szAppName));
  63.     LoadString(hInstance, IDS_DESCRIPTION, szTitle, sizeof(szTitle));
  64.  
  65.     // Fill in window class structure with parameters that describe the
  66.     // main window.
  67.  
  68.     wc.cbSize        = sizeof(WNDCLASSEX);
  69.     wc.style         = CS_HREDRAW | CS_VREDRAW; // Class style(s).
  70.     wc.lpfnWndProc   = (WNDPROC)WndProc;        // Window Procedure
  71.     wc.cbClsExtra    = 0;                       // No per-class extra data.
  72.     wc.cbWndExtra    = 0;                       // No per-window extra data.
  73.     wc.hInstance     = hInstance;               // Owner of this class
  74.     wc.hIcon         = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_APPICON)); // Icon name from .RC
  75.     wc.hCursor       = LoadCursor(NULL, IDC_ARROW); // Cursor
  76.     wc.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1); // Default color
  77.     wc.lpszMenuName  = szAppName;               // Menu name from .RC
  78.     wc.lpszClassName = szAppName;               // Name to register as
  79.     wc.hIconSm       = LoadImage(hInstance,        // Load small icon image
  80.                                  MAKEINTRESOURCE(IDI_APPICON),
  81.                                  IMAGE_ICON,
  82.                                  16, 16,
  83.                                  0);
  84.  
  85.     // Register the window class and return FALSE if unsuccesful.
  86.  
  87.     if (!RegisterClassEx(&wc))
  88.     {
  89.         //Assume we are running on NT where RegisterClassEx() is
  90.         //not implemented, so let's try calling RegisterClass().
  91.  
  92.         if (!RegisterClass((LPWNDCLASS)&wc.style))
  93.             return FALSE;
  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.     // Save the instance handle in static variable, which will be used in
  129.     // many subsequence calls from this application to Windows.
  130.  
  131.     hInst = hInstance; // Store instance handle in our global variable
  132.  
  133.     // Create a main window for this application instance.
  134.     ghwnd = CreateWindow(szAppName,           // See RegisterClass() call.
  135.                          szTitle,             // Text for window title bar.
  136.                          WS_OVERLAPPEDWINDOW, // Window style.
  137.                          CW_USEDEFAULT, 0,    // Use default positioning
  138.                          CW_USEDEFAULT, 0,    // Use default size
  139.                          NULL,                // Overlapped has no parent.
  140.                          NULL,                // Use the window class menu.
  141.                          hInstance,           
  142.                          NULL);               
  143.     
  144.     // If window could not be created, return "failure"
  145.     if (!ghwnd)
  146.         return FALSE;
  147.  
  148.     //
  149.     // **TODO** Call module specific instance initialization functions here.
  150.     //
  151.  
  152.     // Make the window visible; update its client area; and return "success"
  153.     ShowWindow(ghwnd, nCmdShow); // Show the window
  154.     UpdateWindow(ghwnd);         // Sends WM_PAINT message
  155.  
  156.     return TRUE;                 // We succeeded...
  157. }
  158.