home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / clrwhl.zip / COLOURS.C < prev    next >
Text File  |  1993-09-13  |  11KB  |  243 lines

  1.  
  2. /* Program name:   Colours.C  Title: A Color-Full Example:              */
  3. /*                                   Using Color In Control Design      */
  4. /* OS/2 Developer Magazine, Issue:  Sept '93, page 46                   */
  5. /* Author:  Chris Andrew WordPerfect Corp.                              */
  6. /*          Mark Benge   IBM Corp.                                      */
  7. /*          Matt Smith   Prominare Inc.                                 */
  8. /* Description:  Colour Wheel sample control with threading.            */
  9. /*                                                                      */
  10. /* Program Requirements:  OS/2 2.x                                      */
  11. /*                        IBM C Set/2                                   */
  12. /*                        WATCOM C 386/9.0                              */
  13. /*                        Borland C++ for OS/2                          */
  14. /*                        Zortech C++ for OS/2                          */
  15. /*                        OS/2 Toolkit                                  */
  16.  
  17. /************************************************************************/
  18. /************************************************************************/
  19. /*                     DISCLAIMER OF WARRANTIES.                        */
  20. /************************************************************************/
  21. /************************************************************************/
  22. /*     The following [enclosed] code is library code created by the     */
  23. /*     authors.  This source code is  provided to you solely            */
  24. /*     for the purpose of assisting you in the development of your      */
  25. /*     applications.  The code is provided "AS IS", without             */
  26. /*     warranty of any kind.  The authors shall not be liable           */
  27. /*     for any damages arising out of your use of the library code,     */
  28. /*     even if they have been advised of the possibility of such        */
  29. /*     damages.                                                         */
  30. /************************************************************************/
  31. /************************************************************************/
  32.  
  33. #define INCL_DOS                   /* Include OS/2 DOS Kernal           */
  34. #define INCL_GPI                   /* Include OS/2 PM Windows Interface */
  35. #define INCL_WIN                   /* Include OS/2 PM Windows Interface */
  36.  
  37. static char *PROGID = "@(#)colours.c:2.07";
  38.  
  39. #include <math.h>
  40. #include <os2.h>
  41. #include <string.h>
  42. #include <stdio.h>
  43.  
  44. #include "pdsctls.h"
  45.  
  46. /* Equivalent command line invocation of each module using the          */
  47. /* IBM C Set++ Compiler Version 2.0 is:                                 */
  48. /*                                                                      */
  49. /*     Icc -G3s- -O+ -C -W3 -Fofilename filename.C                      */
  50.  
  51. /* Filename:   Colours.C                                                */
  52.  
  53. /*  Version:   2.10                                                     */
  54. /*  Created:   1990-12-29                                               */
  55. /*  Revised:   1992-11-07                                               */
  56.  
  57.  
  58. /* -------------------------------------------------------------------- */
  59.  
  60. /* --- Module Definitions --------------------------------------------- */
  61.  
  62. PSZ pszDriverClassName = "Colours.Desktop";
  63.  
  64. HPOINTER hptrWait;
  65. HPOINTER hptrArrow;
  66. HWND     hwndDriver;               /* Program Window Handle             */
  67. HWND     hwndDriverFrame;          /* Program Frame Handle              */
  68. HAB      hAB;                      /* Program Anchor Block Handle       */
  69. HMQ      hmqDriver;                /* Program Message Queue Handle      */
  70.  
  71. /* --- Internal Structures -------------------------------------------- */
  72.  
  73. INT main(INT, CHAR *[ ]);
  74. MRESULT EXPENTRY ClrWheelWndProc(HWND hWnd, ULONG msg, MPARAM mp1, MPARAM mp2);
  75. MRESULT EXPENTRY DriverWndProc(HWND hWnd, ULONG msg, MPARAM mp1, MPARAM mp2);
  76.  
  77. #pragma subtitle("   Driver Client Window - Client Window Procedure")
  78. #pragma page( )
  79.  
  80. /* --- DriverWndProc ------------------------------------------------ */
  81. /*                                                                      */
  82. /*     This function is used to process the messages for the main       */
  83. /*     Client Window.                                                   */
  84. /*                                                                      */
  85. /*     Upon Entry:                                                      */
  86. /*                                                                      */
  87. /*     HWND   hWnd; = Window Handle                                     */
  88. /*     ULONG  msg;  = PM Message                                        */
  89. /*     MPARAM mp1;  = Message Parameter 1                               */
  90. /*     MPARAM mp2;  = Message Parameter 2                               */
  91. /*                                                                      */
  92. /*     Upon Exit:                                                       */
  93. /*                                                                      */
  94. /*     EditWndProc = Message Handling Result                            */
  95. /*                                                                      */
  96. /* -------------------------------------------------------------------- */
  97.  
  98. MRESULT EXPENTRY DriverWndProc(HWND hWnd, ULONG msg, MPARAM mp1, MPARAM mp2)
  99.  
  100. {
  101. CHAR        szStrBuf[64];          /* String Buffer                     */
  102. RGB2        rgb2;                  /* RGB2 Structure                    */
  103. HPS         hPS;                   /* Presentation Space Handle         */
  104. RECTL       rcl;                   /* Client Window Rectangle           */
  105. CLRWHLCDATA cwcd;                  /* Colour Wheel Data                 */
  106.  
  107. switch ( msg )
  108.    {
  109.                        /* Perform window initialization                 */
  110.    case WM_CREATE :
  111.        hptrArrow = WinQuerySysPointer(HWND_DESKTOP, SPTR_ARROW, FALSE);
  112.        WinSetPointer(HWND_DESKTOP, hptrWait = WinQuerySysPointer(HWND_DESKTOP, SPTR_WAIT, FALSE));
  113.        cwcd.cb = sizeof(CLRWHLCDATA);
  114.        cwcd.lAngle         = 5L;
  115.        cwcd.lSaturationInc = 5L;
  116.        cwcd.lRadius        = 150L;
  117.        WinCreateWindow(hWnd, "ClrWheel", "", WS_VISIBLE | CWS_AUTOSIZE | CWS_BITMAP | CWS_THREADED,
  118.                        50L, 50L, 400L, 400L, hWnd,
  119.                        HWND_TOP, 10L, (PVOID)&cwcd, (PVOID)NULL);
  120. #if 0
  121.        cwcd.cb = sizeof(CLRWHLCDATA);
  122.        cwcd.lAngle         = 5L;
  123.        cwcd.lSaturationInc = 5L;
  124.        cwcd.lRadius        = 150L;
  125.        WinCreateWindow(hWnd, "ClrWheel", "", WS_VISIBLE | CWS_AUTOSIZE,
  126.                        50L, 50L, 400L, 400L, hWnd,
  127.                        HWND_TOP, 10L, (PVOID)&cwcd, (PVOID)NULL);
  128. #endif
  129.        break;
  130.  
  131.    case WM_CONTROL :
  132.        switch ( SHORT2FROMMP(mp1) )
  133.            {
  134.            case CWN_RGBCLRSELECTED :
  135.                switch ( SHORT1FROMMP(mp1) )
  136.                    {
  137.                    case 10L :
  138.                        memmove(&rgb2, &mp2, sizeof(RGB2));
  139.                        sprintf(szStrBuf, "Red: %d  Green: %d  Blue: %d",
  140.                                rgb2.bRed, rgb2.bGreen, rgb2.bBlue);
  141.                        rcl.xLeft = rcl.yBottom = 10L;
  142.                        rcl.yTop = 30L;
  143.                        rcl.xRight = 300L;
  144.                        WinDrawText(hPS = WinGetPS(hWnd), -1, szStrBuf,
  145.                                    &rcl, CLR_BLACK, CLR_WHITE,
  146.                                    DT_LEFT | DT_BOTTOM | DT_ERASERECT);
  147.                        WinReleasePS(hPS);
  148.                        break;
  149.                    }
  150.                break;
  151.            }
  152.        break;
  153.                        /* Erase background                              */
  154.  
  155.    case WM_ERASEBACKGROUND :
  156.        WinQueryWindowRect(hWnd, &rcl);
  157.        WinFillRect((HPS)mp1, &rcl, SYSCLR_APPWORKSPACE);
  158.        break;
  159.                        /* Paint the main client window                  */
  160.    case WM_PAINT :
  161.        WinSetPointer(HWND_DESKTOP, hptrWait);
  162.  
  163.        WinFillRect(hPS = WinBeginPaint(hWnd, (HPS)NULL, &rcl), &rcl, SYSCLR_APPWORKSPACE);
  164.  
  165.        WinEndPaint(hPS);
  166.        WinSetPointer(HWND_DESKTOP, hptrArrow);
  167.        break;
  168.                        /* Close Down                                    */
  169.    case WM_CLOSE :
  170.  
  171.        WinPostMsg(hWnd, WM_QUIT, 0L, 0L);
  172.        break;
  173.  
  174.    case WM_DESTROY :
  175.        WinDestroyPointer(hptrArrow);
  176.        WinDestroyPointer(hptrWait);
  177.        break;
  178.                        /* Default message processing                    */
  179.    default:
  180.        return(WinDefWindowProc(hWnd, msg, mp1, mp2));
  181.    }
  182. return(0L);
  183. }
  184. #pragma subtitle("   Program Controller")
  185. #pragma page( )
  186.  
  187. /* --- Main Program Controller ---------------------------------------- */
  188.  
  189. INT main(INT argc, CHAR *argv[ ])
  190.  
  191. {
  192. QMSG       qmsg;                   /* PM Message Queue Holder           */
  193. ULONG      flCreateFlags;          /* Window Creation Flags             */
  194.  
  195.                        /* Initialize the program for PM and create the  */
  196.                        /* message queue                                 */
  197.  
  198. WinSetCp(hmqDriver = WinCreateMsgQueue(hAB = WinInitialize(0), 0), 850);
  199.  
  200.                        /* Register the main program window class        */
  201.  
  202. if ( !WinRegisterClass(hAB, pszDriverClassName, (PFNWP)DriverWndProc,
  203.                        CS_CLIPCHILDREN | CS_SYNCPAINT | CS_SIZEREDRAW, 0) )
  204.    {
  205.    return(1);
  206.    }
  207.  
  208.                        /* Register the main program window class        */
  209.  
  210. if ( !WinRegisterClass(hAB, "ClrWheel", (PFNWP)ClrWheelWndProc,
  211.                        CS_CLIPCHILDREN | CS_SYNCPAINT | CS_SIZEREDRAW, USER_RESERVED) )
  212.    {
  213.    return(1);
  214.    }
  215.  
  216.                        /* Create the main program window but do not     */
  217.                        /* show it yet                                   */
  218.  
  219. flCreateFlags = FCF_TITLEBAR | FCF_NOBYTEALIGN | FCF_SYSMENU | FCF_SIZEBORDER | FCF_SHELLPOSITION;
  220. if ( !(hwndDriverFrame = WinCreateStdWindow(HWND_DESKTOP, WS_VISIBLE,
  221.                                               &flCreateFlags,
  222.                                               pszDriverClassName, NULL, 0L,
  223.                                              (HMODULE)0L, 0L,
  224.                                               &hwndDriver)) )
  225.    {
  226.    return(1);
  227.    }
  228.                        /* Retrieve and then dispatch messages           */
  229.  
  230. while ( WinGetMsg(hAB, &qmsg, (HWND)NULL, 0, 0) )
  231.    WinDispatchMsg(hAB, &qmsg);
  232.  
  233. WinDestroyWindow(hwndDriverFrame);
  234.  
  235. WinDestroyMsgQueue(hmqDriver);
  236.  
  237.                        /* Notify PM that main program thread not needed */
  238.                        /* any longer                                    */
  239. WinTerminate(hAB);
  240.  
  241. return(0);
  242. }
  243.