home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / os2thred.zip / PMAPP.CPP < prev    next >
C/C++ Source or Header  |  1994-06-09  |  3KB  |  85 lines

  1. // Listing 12 -- PMApp.c   Presentation Manager sample program)
  2.  
  3. #define INCL_WIN
  4. #define INCL_DOS
  5.  
  6. #include <os2.h>
  7. #include "PMThread.h"
  8.  
  9. //----------------------------- Statics -------------------------------
  10.  
  11. static CHAR        szClientClass[]="PMApp";
  12. static HWND        hwndFrame, hwndClient;
  13. static ULONG    flFrameFlags = FCF_SYSMENU  | FCF_TITLEBAR | FCF_MINMAX
  14.                         | FCF_TASKLIST | FCF_SHELLPOSITION | FCF_SIZEBORDER;
  15.  
  16. //------------------------- Local Prototypes --------------------------
  17.  
  18. // client window procedure prototype
  19. MRESULT EXPENTRY ClientWinProc (HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2);
  20.  
  21. // procedure to setup and shutdown the pm thread -- passed to PMThread
  22. VOID setupProc (BOOL starting, ULONG ulArg, PMThread* pPMThrd);
  23.  
  24. //------------------------------- Code --------------------------------
  25.  
  26. void main (void)
  27. {
  28.     HEV    hevDone;
  29.     DosCreateEventSem(NULL, &hevDone, 0L, FALSE);
  30.  
  31.     // Create and start the PM Thread
  32.     PMThread pmThrd((PFNPROC)setupProc);
  33.     pmThrd.Start((ULONG)hevDone);
  34.  
  35.     // Wait for PM thread to finish
  36.     DosWaitEventSem(hevDone, SEM_INDEFINITE_WAIT);
  37.     DosExit (EXIT_PROCESS, 0L);
  38. }
  39.  
  40. VOID setupProc (BOOL starting, ULONG ulArg, PMThread* pPMThrd)
  41. {
  42.     // If the starting parameter is TRUE, then we are initializing the
  43.     // PM Thread, otherwise we are shutting it down.
  44.     if (starting) {
  45.         WinRegisterClass (pPMThrd->QueryHAB(),   // Anchor block
  46.                             szClientClass,    // Class Name
  47.                             ClientWinProc,    // Window procedure
  48.                             CS_SIZEREDRAW,    // Style bits
  49.                             0);               // Extra space to reserve
  50.  
  51.         hwndFrame=WinCreateStdWindow (
  52.                 HWND_DESKTOP,               // Parent window handle
  53.                 WS_VISIBLE,                 // Style of frame window
  54.                 &flFrameFlags,              // Pointer to control data
  55.                 szClientClass,              // Registered Class name
  56.                 "PM App based on PM Msg Thread",   // Title bar text
  57.                 0L,                         // Style of Client window
  58.                 (HMODULE)NULL,              // module resource id
  59.                 0L,                            // ID of resources (icons and menus)
  60.                 &hwndClient);               // pointer to client window handle
  61.  
  62.     } else { // not starting
  63.         WinDestroyWindow (hwndFrame);
  64.         DosPostEventSem((HEV)ulArg);  // signal main thread that we're done
  65.     }
  66. }
  67.  
  68. MRESULT EXPENTRY ClientWinProc (HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
  69. {
  70. HPS             hps;
  71. RECTL           rcl;
  72.  
  73.      switch (msg) {
  74.         case WM_PAINT:
  75.             hps = WinBeginPaint(hwnd, NULLHANDLE, &rcl);
  76.             WinFillRect (hps, &rcl, CLR_BACKGROUND);
  77.             WinQueryWindowRect (hwnd, &rcl);
  78.             WinDrawText (hps, 11, "Hello World", &rcl,
  79.                 CLR_BLUE, CLR_BACKGROUND, DT_CENTER | DT_VCENTER);
  80.             WinEndPaint (hps);
  81.             return 0;
  82.      }
  83.     return WinDefWindowProc (hwnd, msg, mp1, mp2);
  84. }
  85.