home *** CD-ROM | disk | FTP | other *** search
/ QBasic & Borland Pascal & C / Delphi5.iso / C / BC_502 / WRITEPAD.PAK / WINMAIN.C < prev    next >
Encoding:
C/C++ Source or Header  |  1997-05-06  |  4.2 KB  |  133 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. HANDLE hRTFLib;
  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 - This parameter is always NULL in Win32
  41. //          applications.
  42. //
  43. //    lpCmdLine - A pointer to a null terminated string specifying the
  44. //          command line of the application.
  45. //
  46. //    nCmdShow - Specifies how the main window is to be diplayed.
  47. //
  48. //  RETURN VALUE:
  49. //    If the function terminates before entering the message loop,
  50. //    return FALSE.
  51. //    Otherwise, return the WPARAM value sent by the WM_QUIT message.
  52. //
  53. //
  54. //  COMMENTS:
  55. //
  56. //    Windows recognizes this function by name as the initial entry point
  57. //    for the program.  This function calls the initialization routine
  58. //    It then executes a message retrieval and dispatch loop that is the
  59. //    top-level control structure for the remainder of execution.  The
  60. //    loop is terminated when a WM_QUIT  message is received, at which
  61. //    time this function exits the application instance by returning the
  62. //    value passed by 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 APIENTRY WinMain(HINSTANCE hInstance,
  70.                             HINSTANCE hPrevInstance,
  71.                             LPSTR     lpCmdLine,
  72.                      int       nCmdShow)
  73. {
  74.     MSG msg;
  75.     HANDLE hAccelTable;
  76.     BOOL bRet;
  77.  
  78.     // Initialize application by setting up the main window.
  79.     if (!InitApplication(hInstance, nCmdShow))
  80.     {
  81.         return FALSE;           // Exits if unable to initialize
  82.     }
  83.  
  84.     hRTFLib = LoadLibrary("RICHED32.DLL");
  85.     if (!hRTFLib)
  86.     {
  87.         return FALSE;
  88.     }
  89.  
  90.     hAccelTable = LoadAccelerators(hInstance, szAppName);
  91.  
  92.     // In the true Microsoft Foundation Classes spirit, we implement
  93.     // OnIdle() processing.  The OnIdle() routine is used to update
  94.     // the toolbar so we can accurately reflect the active/inactive
  95.     // state of the Save, Cut, Copy and Paste buttons.
  96.     for (; ;)
  97.     {
  98.         while (!PeekMessage(&msg, 
  99.                             NULL, 
  100.                             (UINT)NULL, 
  101.                                      (UINT)NULL,
  102.                             PM_NOREMOVE) &&
  103.                OnIdle())
  104.         {
  105.             ;  // Do nothing; we either have a message to process, or
  106.                // have already called OnIdle() and can now call
  107.                // GetMessage() again.  GetMessage() will either retrieve
  108.                // the next message, or yield to another application
  109.         }
  110.  
  111.         // Acquire and dispatch the next message
  112.           // GetMessage() will return 0 when WM_QUIT is retreived
  113.           bRet=GetMessage(&msg, NULL, 0, 0);
  114.           if (bRet)
  115.           {
  116.                 if (!TranslateMDISysAccel(hwndMDIClient, &msg))
  117.                      if (!IsFindReplaceMsg(&msg))
  118.                           if (!TranslateAccelerator(hwndMain, hAccelTable, &msg))
  119.                           {
  120.                         TranslateMessage(&msg);  // Translates virtual key codes
  121.                         DispatchMessage(&msg);   // Dispatches message to window
  122.                     }
  123.         }
  124.  
  125.         if (!bRet)
  126.            break;
  127.     }
  128.  
  129.     if (hRTFLib) FreeLibrary (hRTFLib);
  130.  
  131.      return msg.wParam;  // Returns the value from PostQuitMessage
  132. }
  133.