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