home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / dho.zip / DHO / TUTORIAL / EXAMPLE6.CC < prev    next >
C/C++ Source or Header  |  1995-09-03  |  3KB  |  126 lines

  1. /****************************************/
  2. /*    Developer Helper Object Set       */
  3. /*  (C) 1994-95 Thomas E. Bednarz, Jr.  */
  4. /*     All rights reserved              */
  5. /***************************************/
  6.  
  7. /* $Id: example6.cc 1.2 1995/09/03 00:22:49 teb Exp $ */
  8.  
  9. /*******************************************
  10.  *   Example6.cc 
  11.  * 
  12.  *   This example demonstrates how to 
  13.  *   respond to menu commands
  14.  *******************************************/
  15.  
  16. #define INCL_WIN
  17. #include<os2.h>
  18.  
  19. //DHO application object header file
  20. #include<applicat.h>
  21. #include<framewin.h>
  22.  
  23. #define kAppId 100
  24. #define aboutText "Developer Helper Sample App\n (c) 1994-95 Tom Bednarz\n     All Rights Reserved."
  25.  
  26.  
  27. class TExampleClientWin : public TWindow
  28. {
  29.       SHORT sPageX, sPageY;
  30.    public:
  31.       TExampleClientWin(ULONG id, TWinBase *parent):TWindow(id, parent){;};
  32.       virtual void doSize(WinMsg wm)
  33.       {
  34.          sPageX = SHORT1FROMMP(wm.mp2);
  35.          sPageY = SHORT2FROMMP(wm.mp2);
  36.       }
  37.       virtual void paintWindow(HPS ps, RECTL rcl)
  38.       {
  39.          POINTL ptl;
  40.          SHORT w;
  41.  
  42.          if ((sPageX == 0) && (sPageY == 0))         
  43.          {
  44.             sPageX = rcl.xRight - rcl.xLeft;
  45.             sPageY = rcl.yTop - rcl.yBottom; 
  46.          }
  47.  
  48.          if (sPageX > sPageY)
  49.             w = sPageY / 2;
  50.          else
  51.             w = sPageX / 2;         
  52.  
  53.          WinFillRect(ps, &rcl, CLR_BLUE);
  54.  
  55.          rcl.xLeft = (sPageX/2) -(w/2);
  56.          rcl.xRight = rcl.xLeft +w;
  57.          rcl.yBottom = (sPageY /2) -(w/2);
  58.          rcl.yTop = rcl.yBottom+w;
  59.  
  60.          WinFillRect(ps, &rcl, CLR_YELLOW);
  61.          
  62.       }
  63. };
  64.  
  65.  
  66.  
  67. class TExampleFrameWin : public TFrameWindow
  68. {
  69.  
  70.    public:
  71.       TExampleFrameWin(ULONG id, char *title):TFrameWindow(id, title)
  72.       {   
  73.          fShellPos = TRUE;
  74.          fFrAttr.menu = TRUE;
  75.          fFrAttr.icon = TRUE;
  76.       };
  77.       virtual BOOL init()
  78.       {
  79.          if (TFrameWindow::init())
  80.          {  
  81.             TExampleClientWin *client = new
  82.                 TExampleClientWin(FID_CLIENT, this);
  83.             return client->init();
  84.          }
  85.          return FALSE;
  86.       }
  87.       virtual void doCommand(WinMsg wm)
  88.       {
  89.          SHORT command = SHORT1FROMMP(wm.mp1);
  90.          if (command == 103)
  91.          {
  92.             WinPostMsg(wm.hwnd, WM_QUIT, 0,0);
  93.          }
  94.          else if (command == 104)
  95.          {
  96.             WinMessageBox(HWND_DESKTOP, hwnd, (PSZ)aboutText, 
  97.                    (PSZ)"Product Information", 0, MB_MOVEABLE | MB_OK 
  98.                    | MB_ICONEXCLAMATION);
  99.          }
  100.       }
  101. };
  102.  
  103.  
  104. class TExampleApp : public TApplication
  105. {
  106.    public:
  107.       TExampleApp(ULONG res):TApplication(res){;};
  108.       virtual void CreateMainWindow()
  109.       {
  110.          MainWin=new TExampleFrameWin(fResource, "DHO Tutorial App");
  111.       }
  112. };
  113.  
  114.  
  115.  
  116. //=========================================
  117. //  program entry point
  118. INT main(void)
  119. {
  120.    TExampleApp app(kAppId);
  121.  
  122.    app.init();     // initialize object
  123.    app.run();      // begin event loop          
  124.  
  125.    return 0;
  126. }