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 / ipxchat / init.c < prev    next >
C/C++ Source or Header  |  1997-10-05  |  5KB  |  119 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 "globals.h"            // prototypes specific to this application
  21.  
  22. HINSTANCE hInst;                // current instance
  23.  
  24. char szAppName[9];              // The name of this application
  25. char szTitle[40];               // The title bar text
  26.  
  27. char szConnectNetwork[] = "00000000";
  28. char szConnectNode[] = "000000000000";
  29. char szConnectSocket[] = "2FFF";
  30. char szListenSocket[] = "2FFF";
  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.  
  66.     // Load the application name and description strings.
  67.  
  68.     LoadString(hInstance, IDS_APPNAME, szAppName, sizeof(szAppName));
  69.     LoadString(hInstance, IDS_DESCRIPTION, szTitle, sizeof(szTitle));
  70.  
  71.     // Save the instance handle in static variable, which will be used in
  72.     // many subsequence calls from this application to Windows.
  73.  
  74.     hInst = hInstance; // Store instance handle in our global variable
  75.  
  76.     // Fill in window class structure with parameters that describe the
  77.     // main window.
  78.  
  79.     wc.style         = CS_HREDRAW | CS_VREDRAW; // Class style(s).
  80.     wc.lpfnWndProc   = (WNDPROC)WndProc;        // Window Procedure
  81.     wc.cbClsExtra    = 0;                       // No per-class extra data.
  82.     wc.cbWndExtra    = 0;                       // No per-window extra data.
  83.     wc.hInstance     = hInstance;               // Owner of this class
  84.     wc.hIcon         = LoadIcon (hInstance, szAppName); // Icon name from .RC
  85.     wc.hCursor       = LoadCursor(NULL, IDC_ARROW); // Cursor
  86.     wc.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1); // Default color
  87.     wc.lpszMenuName  = szAppName;               // Menu name from .RC
  88.     wc.lpszClassName = szAppName;               // Name to register as
  89.  
  90.     // Register the window class and return FALSE if unsuccesful.
  91.  
  92.     if (!RegisterClass(&wc))
  93.     {
  94.         return FALSE;
  95.     }
  96.  
  97.     // Create a main window for this application instance.
  98.     hwnd = CreateWindow(szAppName,           // See RegisterClass() call
  99.                         szTitle,             // Text for window title bar
  100.                         WS_OVERLAPPEDWINDOW, // Window style
  101.                         CW_USEDEFAULT, 0,    // Use default positioning
  102.                         CW_USEDEFAULT, 0,    // Use default size
  103.                         NULL,                // Overlapped has no parent
  104.                         NULL,                // Use the window class menu
  105.                         hInstance,           // This instance owns this window
  106.                         NULL                 // Don't need data in WM_CREATE
  107.     );
  108.  
  109.     // If window could not be created, return "failure"
  110.     if (!hwnd)
  111.         return FALSE;
  112.  
  113.     // Make the window visible; update its client area; and return "success"
  114.     ShowWindow(hwnd, nCmdShow);  // Show the window
  115.     UpdateWindow(hwnd);          // Sends WM_PAINT message
  116.  
  117.     return TRUE;                 // We succeeded...
  118. }
  119.