home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / wpobj.zip / CLRSAMPL.C < prev    next >
C/C++ Source or Header  |  1993-10-28  |  5KB  |  176 lines

  1. /******************************************************************************
  2.  * MODULE NAME: ClrSampl.C
  3.  *
  4.  * DESCRIPTION:
  5.  *     Source code for COLOR_SAMPLE_CLASS window class
  6. \****************************************************************************/
  7. #define INCL_WIN
  8. #define INCL_DOS
  9. #define INCL_GPI
  10. #define INCL_WINWORKPLACE
  11. #define INCL_WPFOLDER
  12. #include <os2.h>
  13. #include "clrsampl.h"
  14.  
  15. static CLASSINFO    vclsiStatic;
  16.  
  17. /*
  18.  * FUNCTION: RegisterColorSampleClass
  19.  *
  20.  * DESCRIPTION:
  21.  *   Register the color sample control window class name on this process.
  22.  *   Note that this function must be called before any instance of the
  23.  *   COLOR_SAMPLE_CLASS are used in your application's dialogs.
  24.  */
  25. BOOL EXPENTRY RegisterColorSampleClass()
  26. {
  27.     BOOL        rc;
  28.  
  29.     /* Register the color sample control class when requested to do so.
  30.      * Because we are incredibly lazy, we are using the WC_STATIC window
  31.      * procedure to perform most of our standard message processing - but
  32.      * why reinvent the wheel ?
  33.      */
  34.     rc    = WinQueryClassInfo(NULLHANDLE,
  35.                             WC_STATIC,
  36.                             &vclsiStatic);
  37.     if (rc)
  38.     {
  39.         vclsiStatic.flClassStyle    &= ~CS_PUBLIC;
  40.         WinRegisterClass(NULLHANDLE,
  41.                          COLOR_SAMPLE_CLASS,
  42.                          ClrSampleWndProc,
  43.                          vclsiStatic.flClassStyle | SS_FGNDFRAME,
  44.                          vclsiStatic.cbWindowData
  45.                         );
  46.     }
  47.     return rc;
  48. }
  49.  
  50. /*
  51.  * WINDOW PROCEDURE: ClrSampleWndProc
  52.  *
  53.  * DESCRIPTION:
  54.  *   Window procedure for the color sample window class.
  55.  */
  56. MRESULT EXPENTRY ClrSampleWndProc(
  57.     HWND    hwnd,
  58.     ULONG    msg,
  59.     MPARAM    mp1,
  60.     MPARAM    mp2)
  61. {
  62.     MRESULT        mr                    = 0;
  63.     CHAR        szSetup[CCHMAXPATH];
  64.     HPS            hps;
  65.     HOBJECT        hObject;
  66.     ULONG        ulRGB;
  67.     LONG          cxBorder, cyBorder;
  68.     RECTL        rclPaint;
  69.  
  70.     switch (msg)
  71.     {
  72.         /* Repaint this window as a square color swatch with a 3D border
  73.          */
  74.         case WM_PAINT:
  75.             hps     = WinBeginPaint(hwnd, NULLHANDLE, &rclPaint);
  76.             ulRGB    = WinQueryWindowULong(hwnd,QWL_USER);
  77.             if (hps)
  78.             {
  79.                 cxBorder    = WinQuerySysValue(HWND_DESKTOP,SV_CXBORDER),
  80.                 cyBorder    = WinQuerySysValue(HWND_DESKTOP,SV_CYBORDER);
  81.                 WinQueryWindowRect(hwnd,&rclPaint);
  82.                 GpiCreateLogColorTable(hps,0,LCOLF_RGB,0,0,NULL);
  83.                 MyDrawBorder(hps,
  84.                              &rclPaint,
  85.                              SYSCLR_BUTTONDARK,
  86.                              SYSCLR_BUTTONLIGHT,
  87.                              cxBorder,
  88.                              cyBorder);
  89.                 WinInflateRect(NULLHANDLE,&rclPaint,-cxBorder,-cyBorder);
  90.                 MyDrawBorder(hps,
  91.                              &rclPaint,
  92.                              SYSCLR_BUTTONLIGHT,
  93.                              SYSCLR_BUTTONDARK,
  94.                              WinQuerySysValue(HWND_DESKTOP,SV_CXBORDER),
  95.                              WinQuerySysValue(HWND_DESKTOP,SV_CYBORDER));
  96.                 WinInflateRect(NULLHANDLE,&rclPaint,-cxBorder,-cyBorder);
  97.                 WinFillRect(hps,&rclPaint,ulRGB);
  98.                 WinEndPaint(hps);
  99.             }
  100.             break;
  101.             
  102.         /* Use the QWL_USER window word to store the current RGB color value
  103.          */
  104.         case CSM_SETRGBCOLOR:
  105.             WinSetWindowULong(hwnd,QWL_USER,LONGFROMMP(mp1));        
  106.             WinInvalidateRect(hwnd,NULL,FALSE);
  107.             mr        = (MRESULT)TRUE;
  108.             break;
  109.  
  110.         /* Return the current RGB color value from our QWL_USER window word.
  111.          */
  112.         case CSM_QUERYRGBCOLOR:
  113.             mr        = (MRESULT)WinQueryWindowULong(hwnd,QWL_USER);
  114.             break;
  115.  
  116.         /* If the user double clicks on us, communicate with our color
  117.          * palette object !
  118.          */
  119.         case CSM_EDITRGBCOLOR:
  120.         case WM_OPEN:
  121.             sprintf(szSetup,"OPEN=DEFAULT;CTRLHDL=%lx",(ULONG)hwnd);
  122.  
  123.             /* Set the setup string through to our installed object
  124.              */
  125.             hObject = WinQueryObject("<CLRPALET>");
  126.             if (hObject)
  127.                 WinSetObjectData(hObject,szSetup);
  128.             break;        
  129.  
  130.         default:
  131.             mr    = (*vclsiStatic.pfnWindowProc)(hwnd,msg,mp1,mp2);
  132.             break;
  133.     }
  134.     return mr;
  135. }
  136.  
  137. /*
  138.  * FUNCTION: MyDrawBorder
  139.  *
  140.  * DESCRIPTION:
  141.  *   Draw a two color border of system defined thickness. WinDrawBorder does
  142.  *   this functionality too, but you have to use undocumented flags to get
  143.  *   the chiseled border effect !
  144.  */
  145. VOID MyDrawBorder(
  146.     HPS        hps,
  147.     RECTL    *prcl,
  148.     ULONG    TopLeftColor,
  149.     ULONG    BottomRightColor,
  150.     LONG    cxBorder,
  151.     LONG    cyBorder)
  152. {
  153.     RECTL    rcl;
  154.     ULONG    ulSave;
  155.  
  156.     /* Draw the horizontals
  157.      */
  158.     WinCopyRect(NULLHANDLE,&rcl,prcl);
  159.     ulSave        = rcl.yBottom;
  160.     rcl.yBottom    = rcl.yTop       - cyBorder;
  161.     WinFillRect(hps,&rcl,TopLeftColor);
  162.     rcl.yBottom    = ulSave;
  163.     rcl.yTop    = rcl.yBottom + cyBorder;
  164.     WinFillRect(hps,&rcl,BottomRightColor);
  165.  
  166.     /* Draw the verticals
  167.      */
  168.     WinCopyRect(NULLHANDLE,&rcl,prcl);
  169.     ulSave        = rcl.xRight;
  170.     rcl.xRight    = rcl.xLeft  + cxBorder;
  171.     WinFillRect(hps,&rcl,TopLeftColor);
  172.     rcl.xRight     = ulSave;
  173.     rcl.xLeft    = rcl.xRight - cxBorder;
  174.     WinFillRect(hps,&rcl,BottomRightColor);
  175. }
  176.