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

  1. /****************************************/
  2. /*    Developer Helper Object Set       */
  3. /*  (C) 1994-95 Thomas E. Bednarz, Jr.  */
  4. /*     All rights reserved              */
  5. /***************************************/
  6.  
  7. /* $Id: example8.cc 1.5 1995/09/03 00:48:27 teb Exp $ */
  8.  
  9. /*******************************************
  10.  *   Example8.cc 
  11.  * 
  12.  *******************************************/
  13.  
  14. #define INCL_WIN
  15. #include<os2.h>
  16.  
  17. //DHO application object header file
  18. #include<applicat.h>
  19. #include<framewin.h>
  20. #include<moddlog.h>
  21. #include<vset.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.  
  28.  
  29. class TColorSelectDlog : public TModalDialog
  30. {
  31.       TValueSet *fBkgndColors, *fShapeColors;
  32.       USHORT fBackground, fShape;
  33.    public:
  34.       TColorSelectDlog(ULONG resource, TWinBase *owner, void *buffer):
  35.          TModalDialog(resource, owner, buffer){;};
  36.       virtual~TColorSelectDlog()
  37.       {
  38.          if(fBkgndColors)
  39.             delete fBkgndColors;
  40.          if(fShapeColors)
  41.             delete fShapeColors;
  42.       }
  43.       virtual BOOL init()
  44.       {
  45.          ULONG index, i, j;
  46.          if (TModalDialog::init())
  47.          {
  48.             fBkgndColors=new TValueSet(201, this);
  49.             fShapeColors=new TValueSet(202, this);
  50.             index = 1;
  51.             j=1;
  52.             for (i=1; i<4; i++)
  53.             {
  54.                for (j=1; j<6; j++)
  55.                {
  56.                   fBkgndColors->setItem(i,j,(VOID*)index);
  57.                   fShapeColors->setItem(i,j,(VOID*)index);
  58.                   index++;                   
  59.               }
  60.             }
  61.             return TRUE;
  62.          }
  63.          return FALSE;
  64.       }
  65.       virtual void doControl(WinMsg wm)
  66.       { 
  67.          if (SHORT2FROMMP(wm.mp1) == VN_SELECT)
  68.          {
  69.             USHORT i,j;
  70.             fBkgndColors->getSelection(i,j);
  71.             fBackground=((i-1)*5)+j;
  72.             fShapeColors->getSelection(i,j);
  73.             fShape=((i-1)*5)+j;  
  74.          }
  75.          else
  76.             TModalDialog::doControl(wm);
  77.                
  78.       }
  79.       void getColors(ULONG &bgnd, ULONG &shape)
  80.       {
  81.          bgnd = fBackground;
  82.          shape = fShape;
  83.       }
  84. };
  85.  
  86.  
  87.  
  88.  
  89. class TExampleClientWin : public TWindow
  90. {
  91.       SHORT sPageX, sPageY;
  92.       ULONG fBkgColor, fShapeColor;
  93.    public:
  94.       TExampleClientWin(ULONG id, TWinBase *parent):TWindow(id, parent)
  95.       {
  96.         fBkgColor = CLR_BLUE;
  97.         fShapeColor = CLR_YELLOW;
  98.       };
  99.       virtual void doSize(WinMsg wm)
  100.       {
  101.          sPageX = SHORT1FROMMP(wm.mp2);
  102.          sPageY = SHORT2FROMMP(wm.mp2);
  103.       }
  104.       virtual void paintWindow(HPS ps, RECTL rcl)
  105.       {
  106.          POINTL ptl;
  107.          SHORT w;
  108.  
  109.          if ((sPageX == 0) && (sPageY == 0))         
  110.          {
  111.             sPageX = rcl.xRight - rcl.xLeft;
  112.             sPageY = rcl.yTop - rcl.yBottom; 
  113.          }
  114.  
  115.          if (sPageX > sPageY)
  116.             w = sPageY / 2;
  117.          else
  118.             w = sPageX / 2;         
  119.  
  120.          WinFillRect(ps, &rcl, fBkgColor);
  121.  
  122.          rcl.xLeft = (sPageX/2) -(w/2);
  123.          rcl.xRight = rcl.xLeft +w;
  124.          rcl.yBottom = (sPageY /2) -(w/2);
  125.          rcl.yTop = rcl.yBottom+w;
  126.  
  127.          WinFillRect(ps, &rcl, fShapeColor);
  128.       }
  129.       void setColors(ULONG bgnd, ULONG shape)
  130.       {
  131.           fBkgColor = bgnd;
  132.           fShapeColor = shape;
  133.       }
  134.       void getColors(ULONG &bgnd, ULONG &shape)
  135.       {
  136.           bgnd = fBkgColor;
  137.           shape = fShapeColor;
  138.       }
  139. };
  140.  
  141.  
  142.  
  143. class TExampleFrameWin : public TFrameWindow
  144. {
  145.      TExampleClientWin *client;
  146.    public:
  147.       TExampleFrameWin(ULONG id, char *title):TFrameWindow(id, title)
  148.       {   
  149.          fShellPos = TRUE;
  150.          fFrAttr.menu = TRUE;
  151.          fFrAttr.icon = TRUE;
  152.       };
  153.       virtual BOOL init()
  154.       {
  155.          if (TFrameWindow::init())
  156.          {   
  157.             client = new TExampleClientWin(FID_CLIENT, this);
  158.             return client->init();
  159.          }
  160.          return FALSE;
  161.       }
  162.       virtual void doCommand(WinMsg wm)
  163.       {
  164.          SHORT command = SHORT1FROMMP(wm.mp1);
  165.          if (command == 102)
  166.          {
  167.              TColorSelectDlog dlog(200, this, NULL);
  168.              dlog.init();
  169.              if (dlog.Execute() == MBID_OK)
  170.              {
  171.                 ULONG i,j;
  172.                 dlog.getColors(i,j);
  173.                 client->setColors(i,j);
  174.                 client->forceUpdate();
  175.              }
  176.          }
  177.          if (command == 103)
  178.          {
  179.             WinPostMsg(wm.hwnd, WM_QUIT, 0,0);
  180.          }
  181.          else if (command == 104)
  182.          {
  183.             WinMessageBox(HWND_DESKTOP, hwnd, (PSZ)aboutText, 
  184.                    (PSZ)"Product Information", 0, MB_MOVEABLE | MB_OK 
  185.                    | MB_ICONEXCLAMATION);
  186.          }
  187.       }
  188. };
  189.  
  190.  
  191. class TExampleApp : public TApplication
  192. {
  193.    public:
  194.       TExampleApp(ULONG res):TApplication(res){;};
  195.       virtual void CreateMainWindow()
  196.       {
  197.          MainWin=new TExampleFrameWin(fResource, "DHO Tutorial App");
  198.       }
  199. };
  200.  
  201.  
  202.  
  203. //=========================================
  204. //  program entry point
  205. INT main(void)
  206. {
  207.    TExampleApp app(kAppId);
  208.  
  209.    appinit();     // initialize object
  210.    app.run();      // begin event loop          
  211.  
  212.    return 0;
  213. }
  214.