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 / client / init.c < prev    next >
C/C++ Source or Header  |  1997-10-05  |  5KB  |  128 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 <wsipx.h>              // IPX Sockets defs
  20. #include <wsnetbs.h>
  21. #include <nspapi.h>
  22. #include "globals.h"            // prototypes specific to this application
  23.  
  24. HINSTANCE hInst;                // current instance
  25.  
  26. char szAppName[9];              // The name of this application
  27. char szTitle[40];               // The title bar text
  28.  
  29. char szConnectName[16];
  30. char szConnectServer[16];
  31.  
  32. BOOL i_should_sleep = TRUE;
  33.  
  34. //
  35. //  FUNCTION: InitApplication(HINSTANCE, int)
  36. //
  37. //  PURPOSE: Initializes window data and registers window class.
  38. //
  39. //  PARAMETERS:
  40. //    hInstance - The handle to the instance of this application that
  41. //                is currently being executed.
  42. //    nCmdShow  - Specifies how the main window is to be displayed.
  43. //
  44. //  RETURN VALUE:
  45. //    TRUE  - Success
  46. //    FALSE - Initialization failed
  47. //
  48. //  COMMENTS:
  49. //
  50. //    This function is called at application initialization time.  It
  51. //    performs initialization tasks for the current application instance.
  52. //    Unlike Win16, in Win32, each instance of an application must register
  53. //    window classes.
  54. //
  55. //    In this function, we initialize a window class by filling out a data
  56. //    structure of type WNDCLASS and calling the Windows RegisterClass()
  57. //    function.  Then we create the main window and show it.
  58. //
  59. //
  60.  
  61. BOOL InitApplication(HINSTANCE hInstance, int nCmdShow)
  62. {
  63.     WNDCLASS  wc;
  64.     HWND      hwnd; // Main window handle.
  65.     WORD      wVersionRequested;
  66.     WSADATA   wsaData;
  67.  
  68.     // Load the application name and description strings.
  69.  
  70.     LoadString(hInstance, IDS_APPNAME, szAppName, sizeof(szAppName));
  71.     LoadString(hInstance, IDS_DESCRIPTION, szTitle, sizeof(szTitle));
  72.  
  73.     // Save the instance handle in static variable, which will be used in
  74.     // many subsequence calls from this application to Windows.
  75.  
  76.     hInst = hInstance; // Store instance handle in our global variable
  77.  
  78.     // Fill in window class structure with parameters that describe the
  79.     // main window.
  80.  
  81.     wc.style         = CS_HREDRAW | CS_VREDRAW; // Class style(s).
  82.     wc.lpfnWndProc   = (WNDPROC)WndProc;        // Window Procedure
  83.     wc.cbClsExtra    = 0;                       // No per-class extra data.
  84.     wc.cbWndExtra    = 0;                       // No per-window extra data.
  85.     wc.hInstance     = hInstance;               // Owner of this class
  86.     wc.hIcon         = LoadIcon (hInstance, szAppName); // Icon name from .RC
  87.     wc.hCursor       = LoadCursor(NULL, IDC_ARROW); // Cursor
  88.     wc.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1); // Default color
  89.     wc.lpszMenuName  = szAppName;               // Menu name from .RC
  90.     wc.lpszClassName = szAppName;               // Name to register as
  91.  
  92.     // Register the window class and return FALSE if unsuccesful.
  93.  
  94.     if (!RegisterClass(&wc))
  95.     {
  96.         return FALSE;
  97.     }
  98.  
  99.     // Create a main window for this application instance.
  100.     hwnd = CreateWindow(szAppName,           // See RegisterClass() call
  101.                         szTitle,             // Text for window title bar
  102.                         WS_OVERLAPPEDWINDOW, // Window style
  103.                         CW_USEDEFAULT, 0,    // Use default positioning
  104.                         CW_USEDEFAULT, 0,    // Use default size
  105.                         NULL,                // Overlapped has no parent
  106.                         NULL,                // Use the window class menu
  107.                         hInstance,           // This instance owns this window
  108.                         NULL                 // Don't need data in WM_CREATE
  109.     );
  110.  
  111.     // If window could not be created, return "failure"
  112.     if (!hwnd)
  113.         return FALSE;
  114.  
  115.     // Make the window visible; update its client area; and return "success"
  116.     ShowWindow(hwnd, nCmdShow);  // Show the window
  117.     UpdateWindow(hwnd);          // Sends WM_PAINT message
  118.  
  119.     // Link in Winsock DLL
  120.     wVersionRequested = MAKEWORD(1,1);
  121.     if (WSAStartup(wVersionRequested, &wsaData) != 0)
  122.     {
  123.         return FALSE;
  124.     }
  125.  
  126.     return TRUE;                 // We succeeded...
  127. }
  128.