home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Windows Gam…ming Gurus (2nd Edition) / Disc2.iso / msdn_vcb / samples / vc98 / sdk / netds / ras / rasberry / init.c < prev    next >
C/C++ Source or Header  |  1997-10-05  |  5KB  |  151 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-1997  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.  
  25. HINSTANCE hInst;                // current instance
  26.  
  27. char szAppName[9];              // The name of this application
  28. char szTitle[40];               // The title bar text
  29.  
  30. //
  31. //  FUNCTION: InitApplication(HINSTANCE)
  32. //
  33. //  PURPOSE: Initializes window data and registers window class.
  34. //
  35. //  PARAMETERS:
  36. //    hInstance - The handle to the instance of this application that
  37. //          is currently being executed.
  38. //
  39. //  RETURN VALUE:
  40. //    TRUE - Success
  41. //    FALSE - Initialization failed
  42. //
  43. //  COMMENTS:
  44. //
  45. //    This function is called at initialization time only if no other
  46. //    instances of the application are running.  This function performs
  47. //    initialization tasks that can be done once for any number of running
  48. //    instances.
  49. //
  50. //    In this case, we initialize a window class by filling out a data
  51. //    structure of type WNDCLASS and calling the Windows RegisterClass()
  52. //    function.  Since all instances of this application use the same
  53. //    window class, we only need to do this when the first instance is
  54. //    initialized.
  55. //
  56.  
  57. BOOL InitApplication(HINSTANCE hInstance)
  58. {
  59.     WNDCLASS  wc;
  60.  
  61.     // Load the application name and description strings.
  62.  
  63.     LoadString(hInstance, IDS_APPNAME, szAppName, sizeof(szAppName));
  64.     LoadString(hInstance, IDS_DESCRIPTION, szTitle, sizeof(szTitle));
  65.  
  66.     // Fill in window class structure with parameters that describe the
  67.     // main window.
  68.  
  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, szAppName); // 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.  
  80.     // Register the window class and return FALSE if unsuccesful.
  81.  
  82.     if (!RegisterClass(&wc))
  83.     {
  84.         return FALSE;
  85.     }
  86.     //
  87.     // **TODO** Call module specific application initialization functions here.
  88.     //
  89.  
  90.     return TRUE;
  91. }
  92.  
  93.  
  94. //
  95. //  FUNCTION:  InitInstance(HINSTANCE, int)
  96. //
  97. //  PURPOSE:  Saves instance handle and creates main window.
  98. //
  99. //  PARAMTERS:
  100. //    hInstance - The handle to the instance of this application that
  101. //          is currently being executed.
  102. //    nCmdShow - Specifies how the main window is to be diplayed.
  103. //
  104. //  RETURN VALUE:
  105. //    TRUE - Success
  106. //    FALSE - Initialization failed
  107. //
  108. //  COMMENTS:
  109. //    This function is called at initialization time for every instance of
  110. //    this application.  This function performs initialization tasks that
  111. //    cannot be shared by multiple instances.
  112. //
  113. //    In this case, we save the instance handle in a static variable and
  114. //    create and display the main program window.
  115. //
  116.  
  117. BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
  118. {
  119.     HWND    hwnd; // Main window handle.
  120.  
  121.     // Save the instance handle in static variable, which will be used in
  122.     // many subsequence calls from this application to Windows.
  123.  
  124.     hInst = hInstance; // Store instance handle in our global variable
  125.  
  126.     // Create a main window for this application instance.
  127.     hwnd = CreateWindow(szAppName,           // See RegisterClass() call.
  128.                         szTitle,             // Text for window title bar.
  129.                         WS_OVERLAPPEDWINDOW, // Window style.
  130.                         CW_USEDEFAULT, 0,    // Use default positioning
  131.                         CW_USEDEFAULT, 0,    // Use default size
  132.                         NULL,                // Overlapped has no parent.
  133.                         NULL,                // Use the window class menu.
  134.                         hInstance,           
  135.                         NULL);               
  136.     
  137.     // If window could not be created, return "failure"
  138.     if (!hwnd)
  139.         return FALSE;
  140.  
  141.     //
  142.     // **TODO** Call module specific instance initialization functions here.
  143.     //
  144.  
  145.     // Make the window visible; update its client area; and return "success"
  146.     ShowWindow(hwnd, nCmdShow); // Show the window
  147.     UpdateWindow(hwnd);         // Sends WM_PAINT message
  148.  
  149.     return TRUE;                // We succeeded...
  150. }
  151.