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