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

  1. /****************************************/
  2. /*    Developer Helper Object Set       */
  3. /*  (C) 1994-95 Thomas E. Bednarz, Jr.  */
  4. /*     All rights reserved              */
  5. /***************************************/
  6.  
  7. /* $Id: example5.cc 1.2 1995/09/03 00:22:49 teb Exp $ */
  8.  
  9. /*******************************************
  10.  *   Example5.cc 
  11.  * 
  12.  *   This example demonstrates how to add 
  13.  *   a menu to the frame window
  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.  
  25.  
  26. class TExampleClientWin : public TWindow
  27. {
  28.       SHORT sPageX, sPageY;
  29.    public:
  30.       TExampleClientWin(ULONG id, TWinBase *parent):TWindow(id, parent){;};
  31.       virtual void doSize(WinMsg wm)
  32.       {
  33.          sPageX = SHORT1FROMMP(wm.mp2);
  34.          sPageY = SHORT2FROMMP(wm.mp2);
  35.       }
  36.       virtual void paintWindow(HPS ps, RECTL rcl)
  37.       {
  38.          POINTL ptl;
  39.          SHORT w;
  40.  
  41.          if ((sPageX == 0) && (sPageY == 0))         
  42.          {
  43.             sPageX = rcl.xRight - rcl.xLeft;
  44.             sPageY = rcl.yTop - rcl.yBottom; 
  45.          }
  46.  
  47.          if (sPageX > sPageY)
  48.             w = sPageY / 2;
  49.          else
  50.             w = sPageX / 2;         
  51.  
  52.          WinFillRect(ps, &rcl, CLR_BLUE);
  53.  
  54.          rcl.xLeft = (sPageX/2) -(w/2);
  55.          rcl.xRight = rcl.xLeft +w;
  56.          rcl.yBottom = (sPageY /2) -(w/2);
  57.          rcl.yTop = rcl.yBottom+w;
  58.  
  59.          WinFillRect(ps, &rcl, CLR_YELLOW);
  60.          
  61.       }
  62. };
  63.  
  64.  
  65.  
  66. class TExampleFrameWin : public TFrameWindow
  67. {
  68.  
  69.    public:
  70.       TExampleFrameWin(ULONG id, char *title):TFrameWindow(id, title)
  71.       {   
  72.          fShellPos = TRUE;
  73.          fFrAttr.menu = TRUE;
  74.          fFrAttr.icon = TRUE;
  75.       };
  76.       virtual BOOL init()
  77.       {
  78.          if (TFrameWindow::init())
  79.          {
  80.             TExampleClientWin *client = new
  81.                 TExampleClientWin(FID_CLIENT, this);
  82.             return client->init();
  83.          }
  84.          return FALSE;
  85.       }
  86. };
  87.  
  88.  
  89. class TExampleApp : public TApplication
  90. {
  91.    public:
  92.       TExampleApp(ULONG res):TApplication(res){;};
  93.       virtual void CreateMainWindow()
  94.       {
  95.          MainWin=new TExampleFrameWin(fResource, "DHO Tutorial App");
  96.       }
  97. };
  98.  
  99.  
  100.  
  101. //=========================================
  102. //  program entry point
  103. INT main(void)
  104. {
  105.    TExampleApp app(kAppId);
  106.  
  107.    app.init();     // initialize object
  108.    app.run();      // begin event loop          
  109.  
  110.    return 0;
  111. }