home *** CD-ROM | disk | FTP | other *** search
/ QBasic & Borland Pascal & C / Delphi5.iso / C / BC_502 / FILESYS.PAK / WINMAIN.C < prev   
Encoding:
C/C++ Source or Header  |  1997-05-06  |  3.8 KB  |  117 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:   winmain.c
  9. //
  10. //  PURPOSE:   Calls initialization functions and processes the message loop
  11. //
  12. //
  13. //  PLATFORMS: Windows 95, Windows NT, Win3.1
  14. //
  15. //  FUNCTIONS:
  16. //    WinMain() - calls initialization functions, processes message loop
  17. //
  18. //  COMMENTS:
  19. //
  20. //
  21.  
  22. #include <windows.h>            // required for all Windows applications
  23. #include "globals.h"            // prototypes specific to this application
  24.  
  25.  
  26. //
  27. //  FUNCTION: WinMain(HINSTANCE, HINSTANCE, LPSTR, int)
  28. //
  29. //  PURPOSE: calls initialization function, processes message loop
  30. //
  31. //  PARAMETERS:
  32. //
  33. //    hInstance - The handle to the instance of this application that
  34. //          is currently being executed.
  35. //
  36. //    hPrevInstance - The handle to the instance of this application
  37. //          that was last executed.  If this is the only instance
  38. //          of this application executing, hPrevInstance is NULL.
  39. //          In Win32 applications, this parameter is always NULL.
  40. //
  41. //    lpCmdLine - A pointer to a null terminated string specifying the
  42. //          command line of the application.
  43. //
  44. //    nCmdShow - Specifies how the main window is to be diplayed.
  45. //
  46. //  RETURN VALUE:
  47. //    If the function terminates before entering the message loop,
  48. //      return FALSE.
  49. //    Otherwise, return the WPARAM value sent by the WM_QUIT message.
  50. //
  51. //
  52. //  COMMENTS:
  53. //
  54. //    Windows recognizes this function by name as the initial entry point
  55. //    for the program.  This function calls the application initialization
  56. //    routine, if no other instance of the program is running, and always
  57. //    calls the instance initialization routine.  It then executes a
  58. //    message retrieval and dispatch loop that is the top-level control
  59. //    structure for the remainder of execution.  The loop is terminated
  60. //    when a WM_QUIT  message is received, at which time this function
  61. //    exits the application instance by returning the value passed by
  62. //    PostQuitMessage().
  63. //
  64. //    If this function must abort before entering the message loop, it
  65. //    returns the conventional value NULL.
  66. //
  67.  
  68. #pragma argsused
  69. int WINAPI   WinMain(HINSTANCE hInstance,
  70.                      HINSTANCE hPrevInstance, 
  71.                      LPSTR     lpCmdLine, 
  72.                      int       nCmdShow)
  73. {
  74.     MSG msg;
  75.     HANDLE hAccelTable;
  76.     
  77.     // Other instances of app running?
  78.     if (!hPrevInstance)
  79.     {
  80.         // Initialize shared things
  81.         if (!InitApplication(hInstance))
  82.         {
  83.             return FALSE;               // Exits if unable to initialize
  84.         }
  85.     }
  86.  
  87.     // Perform initializations that apply to a specific instance
  88.     if (!InitInstance(hInstance, nCmdShow))
  89.     {
  90.         return FALSE;
  91.     }
  92.  
  93.     hAccelTable = LoadAccelerators(hInstance, szAppName);
  94.  
  95.     // Acquire and dispatch messages until a WM_QUIT message is received.
  96.     while (GetMessage(&msg, NULL, 0, 0))
  97.     {
  98.         //
  99.         // **TODO** Add other Translation functions (for modeless dialogs
  100.         //  and/or MDI windows) here.
  101.         //
  102.               if (!TranslateAccelerator (msg.hwnd, hAccelTable, &msg))
  103.               {
  104.                   TranslateMessage(&msg);// Translates virtual key codes
  105.                   DispatchMessage(&msg); // Dispatches message to window
  106.               }
  107.     }
  108.  
  109.     //
  110.     // **TODO** Call module specific instance free/delete functions here.
  111.     //
  112.  
  113.     // Returns the value from PostQuitMessage
  114.     return msg.wParam;
  115. }
  116.  
  117.