home *** CD-ROM | disk | FTP | other *** search
/ QBasic & Borland Pascal & C / Delphi5.iso / C / BC_502 / MULTIPAD.PAK / WINMAIN.C < prev   
Encoding:
C/C++ Source or Header  |  1997-05-06  |  4.1 KB  |  123 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
  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. extern LRESULT OnIdle(VOID);
  26. extern HWND hwndMain;
  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 - This parameter is always NULL in Win32
  39. //          applications.
  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 initialization routine
  56. //    It then executes a message retrieval and dispatch loop that is the
  57. //    top-level control structure for the remainder of execution.  The
  58. //    loop is terminated when a WM_QUIT  message is received, at which
  59. //    time this function exits the application instance by returning the
  60. //    value passed by PostQuitMessage().
  61. //
  62. //    If this function must abort before entering the message loop, it
  63. //    returns the conventional value NULL.
  64. //
  65.  
  66. #pragma argsused
  67. int APIENTRY WinMain(HINSTANCE hInstance,
  68.                      HINSTANCE hPrevInstance,
  69.                      LPSTR     lpCmdLine,
  70.                      int       nCmdShow)
  71. {
  72.     MSG msg;
  73.     HANDLE hAccelTable;
  74.     BOOL bRet;
  75.  
  76.      // Initialize application by setting up the main window.
  77.     if (!InitApplication(hInstance, nCmdShow))
  78.     {
  79.         return FALSE;           // Exits if unable to initialize
  80.     }
  81.  
  82.     hAccelTable = LoadAccelerators(hInstance, szAppName);
  83.  
  84.     // In the true Microsoft Foundation Classes spirit, we implement
  85.     // OnIdle() processing.  The OnIdle() routine is used to update
  86.     // the toolbar so we can accurately reflect the active/inactive
  87.     // state of the Save, Cut, Copy and Paste buttons.
  88.     for (; ;)
  89.     {
  90.         while (!PeekMessage(&msg, 
  91.                                      NULL,
  92.                             (UINT)NULL, 
  93.                             (UINT)NULL, 
  94.                             PM_NOREMOVE) &&
  95.                OnIdle())
  96.         {
  97.             ;  // Do nothing; we either have a message to process, or
  98.                // have already called OnIdle() and can now call
  99.                // GetMessage() again.  GetMessage() will either retrieve
  100.                // the next message, or yield to another application
  101.         }
  102.  
  103.         // Acquire and dispatch the next message
  104.         // GetMessage() will return 0 when WM_QUIT is retreived
  105.           bRet=GetMessage(&msg, NULL, 0, 0);
  106.           if (bRet)
  107.         {
  108.             if (!TranslateMDISysAccel(hwndMDIClient, &msg))
  109.                 if (!IsFindReplaceMsg(&msg))
  110.                     if (!TranslateAccelerator(hwndMain, hAccelTable, &msg))
  111.                     {
  112.                         TranslateMessage(&msg);  // Translates virtual key codes
  113.                         DispatchMessage(&msg);   // Dispatches message to window
  114.                     }
  115.         }
  116.  
  117.         if (!bRet)
  118.            break;
  119.     }
  120.  
  121.      return msg.wParam;  // Returns the value from PostQuitMessage
  122. }
  123.