home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Windows Gam…ming Gurus (2nd Edition) / Disc2.iso / msdn_vcb / samples / vc98 / sdk / netds / winsock / globchat / server / init.c < prev    next >
Encoding:
C/C++ Source or Header  |  1997-10-05  |  4.2 KB  |  112 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. //
  15. //  COMMENTS:
  16. //
  17.  
  18. #include <windows.h>            // required for all Windows applications
  19. #include "globals.h"            // prototypes specific to this application
  20.  
  21. HINSTANCE hInst;                // current instance
  22.  
  23. char szAppName[9];              // The name of this application
  24. char szTitle[40];               // The title bar text
  25.  
  26.  
  27. //
  28. //  FUNCTION: InitApplication(HINSTANCE, int)
  29. //
  30. //  PURPOSE: Initializes window data and registers window class.
  31. //
  32. //  PARAMETERS:
  33. //    hInstance - The handle to the instance of this application that
  34. //                is currently being executed.
  35. //    nCmdShow  - Specifies how the main window is to be displayed.
  36. //
  37. //  RETURN VALUE:
  38. //    TRUE  - Success
  39. //    FALSE - Initialization failed
  40. //
  41. //  COMMENTS:
  42. //
  43. //    This function is called at application initialization time.  It
  44. //    performs initialization tasks for the current application instance.
  45. //    Unlike Win16, in Win32, each instance of an application must register
  46. //    window classes.
  47. //
  48. //    In this function, we initialize a window class by filling out a data
  49. //    structure of type WNDCLASS and calling the Windows RegisterClass()
  50. //    function.  Then we create the main window and show it.
  51. //
  52. //
  53.  
  54. BOOL InitApplication(HINSTANCE hInstance, int nCmdShow)
  55. {
  56.     WNDCLASS  wc;
  57.     HWND      hwnd; // Main window handle.
  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.     // Save the instance handle in static variable, which will be used in
  65.     // many subsequence calls from this application to Windows.
  66.  
  67.     hInst = hInstance; // Store instance handle in our global variable
  68.  
  69.     // Fill in window class structure with parameters that describe the
  70.     // main window.
  71.  
  72.     wc.style         = CS_HREDRAW | CS_VREDRAW; // Class style(s).
  73.     wc.lpfnWndProc   = (WNDPROC)WndProc;        // Window Procedure
  74.     wc.cbClsExtra    = 0;                       // No per-class extra data.
  75.     wc.cbWndExtra    = 0;                       // No per-window extra data.
  76.     wc.hInstance     = hInstance;               // Owner of this class
  77.     wc.hIcon         = LoadIcon (hInstance, szAppName); // Icon name from .RC
  78.     wc.hCursor       = LoadCursor(NULL, IDC_ARROW); // Cursor
  79.     wc.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1); // Default color
  80.     wc.lpszMenuName  = szAppName;               // Menu name from .RC
  81.     wc.lpszClassName = szAppName;               // Name to register as
  82.  
  83.     // Register the window class and return FALSE if unsuccesful.
  84.  
  85.     if (!RegisterClass(&wc))
  86.     {
  87.         return FALSE;
  88.     }
  89.  
  90.     // Create a main window for this application instance.
  91.     hwnd = CreateWindow(szAppName,           // See RegisterClass() call
  92.                         szTitle,             // Text for window title bar
  93.                         WS_OVERLAPPEDWINDOW, // Window style
  94.                         CW_USEDEFAULT, 0,    // Use default positioning
  95.                         CW_USEDEFAULT, 0,    // Use default size
  96.                         NULL,                // Overlapped has no parent
  97.                         NULL,                // Use the window class menu
  98.                         hInstance,           // This instance owns this window
  99.                         NULL                 // Don't need data in WM_CREATE
  100.     );
  101.  
  102.     // If window could not be created, return "failure"
  103.     if (!hwnd)
  104.         return FALSE;
  105.  
  106.     // Make the window visible; update its client area; and return "success"
  107.     ShowWindow(hwnd, nCmdShow);  // Show the window
  108.     UpdateWindow(hwnd);          // Sends WM_PAINT message
  109.  
  110.     return TRUE;                 // We succeeded...
  111. }
  112.