home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / opendc12.zip / od124os2.exe / od12osp1.exe / src / basecntr / os2plat.cpp < prev   
C/C++ Source or Header  |  1997-04-02  |  15KB  |  488 lines

  1. /* @(#) 1.6 os2/src/samples/basecntr/os2plat.cpp, odbasepart, od96os2, odos29712d 2/25/97 22:19:07 [3/21/97 17:42:03] */
  2.  
  3. //====START_GENERATED_PROLOG======================================
  4. //
  5. //
  6. //   COMPONENT_NAME: odsamples
  7. //
  8. //   CLASSES: none
  9. //
  10. //   ORIGINS: 82,27
  11. //
  12. //
  13. //   (C) COPYRIGHT International Business Machines Corp. 1995,1996
  14. //   All Rights Reserved
  15. //   Licensed Materials - Property of IBM
  16. //   US Government Users Restricted Rights - Use, duplication or
  17. //   disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
  18. //
  19. //   IBM DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
  20. //   ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  21. //   PURPOSE. IN NO EVENT SHALL IBM BE LIABLE FOR ANY SPECIAL, INDIRECT OR
  22. //   CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF
  23. //   USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
  24. //   OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE
  25. //   OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE
  26. //   OR PERFORMANCE OF THIS SOFTWARE.
  27. //
  28. //====END_GENERATED_PROLOG========================================
  29.  
  30. #define INCL_DOSMODULEMGR 
  31. #define INCL_GPILOGCOLORTABLE 
  32. #define INCL_WINDIALOGS 
  33. #define INCL_WINMENUS 
  34. #define INCL_WINSTDSLIDER 
  35. #define INCL_WINSTDSPIN 
  36. #define INCL_WINWINDOWMGR 
  37. #include <ODos2.h> 
  38. #include "iodbcres.h" 
  39.  
  40. extern "C" MRESULT EXPENTRY ColorProc( HWND hwndDlg, ULONG msg, MPARAM mp1, MPARAM mp2 ); 
  41. extern "C" MRESULT EXPENTRY fnwpColorSample( HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2 ); 
  42.  
  43. // Array of binary values for RGB value 
  44. SHORT RGBColors[3] = {0, 0, 0}; 
  45.  
  46. // Array of fill color for sliders 
  47. LONG RibbonColors[3] = {CLR_DARKRED, CLR_DARKGREEN, CLR_DARKBLUE}; 
  48. LONG ShaftColors[3]  = {CLR_RED,     CLR_GREEN,     CLR_BLUE    }; 
  49.  
  50. // Composite color value 
  51. LONG  Color = 0; 
  52.  
  53. const unsigned long ColorChoices = 9; 
  54. /* 
  55.  * Local method to display values of property in a modal window 
  56.  * returning a non-empty string if value selected.  Return value 
  57.  * is return value from WinDlgBox 
  58.  */ 
  59.  
  60. BOOL ColorWindow(HMODULE dllHandle, HWND ParentWindow, SHORT *BakColor) 
  61.  
  62.  
  63.     // take initial background color to start
  64.       RGBColors[RED]   = BakColor[RED];
  65.       RGBColors[GREEN] = BakColor[GREEN];
  66.       RGBColors[BLUE]  = BakColor[BLUE];
  67.  
  68.     // Register a window class to handle the user control 
  69.     WinRegisterClass(WinQueryAnchorBlock(ParentWindow), 
  70.                      "ColorMix", 
  71.                      fnwpColorSample, 
  72.                      0L, 
  73.                      0); 
  74.  
  75.     // Execute color dialog passing in the current color value 
  76.     ULONG rc = WinDlgBox(HWND_DESKTOP,
  77.                          ParentWindow,
  78.                          ColorProc,
  79.                          dllHandle,
  80.                          ID_COLORS,
  81.                          0); 
  82.  
  83.     // If user terminated with the OK button 
  84.     if (rc != DID_CANCEL) 
  85.     {
  86.      BakColor[RED] = RGBColors[RED];
  87.      BakColor[GREEN] = RGBColors[GREEN];
  88.      BakColor[BLUE] = RGBColors[BLUE]; 
  89.      return 0;
  90.     }
  91.  
  92.     // If canceled then don't change color
  93.     return 1; 
  94.  
  95.  
  96. MRESULT EXPENTRY ColorProc( HWND hwndDlg, ULONG msg, MPARAM mp1, MPARAM mp2 ) 
  97.  // This global variable prevents us from infinitely looping setting PM control 
  98.  // values.  The slider set the spin button and the spin button sets the 
  99.  // slider. 
  100.  static boolean Setting = FALSE; 
  101.  
  102.   // Switch on the PM message type 
  103.   switch (msg) 
  104.   { 
  105.     // case Initialize dialog 
  106.     case WM_INITDLG: 
  107.     { 
  108.       // We're setting values 
  109.       Setting = TRUE; 
  110.  
  111.       // For all three colors 
  112.       for (int Index = RED; 
  113.            Index <= BLUE; 
  114.            Index++) 
  115.       { 
  116.         // Set spin fields range from 0 to 255 
  117.         WinSendDlgItemMsg(hwndDlg, 
  118.                           ID_SPIN_RED + Index, 
  119.                           SPBM_SETLIMITS, 
  120.                           MPFROMLONG(255), 
  121.                           MPFROMLONG(0)); 
  122.  
  123.         // Initialize slider 
  124.         WinSendDlgItemMsg(hwndDlg, 
  125.                           ID_SLIDER_RED + Index, 
  126.                           SLM_SETSLIDERINFO, 
  127.                           MPFROM2SHORT(SMA_SLIDERARMPOSITION, 
  128.                                        SMA_INCREMENTVALUE), 
  129.                           MPFROMSHORT(RGBColors[Index])); 
  130.  
  131.         // Set spin field 
  132.         WinSendDlgItemMsg(hwndDlg, 
  133.                           ID_SPIN_RED + Index, 
  134.                           SPBM_SETCURRENTVALUE, 
  135.                           MPFROMLONG((long) RGBColors[Index]), 
  136.                           0); 
  137.       } 
  138.  
  139.       // Invalidate the mix window so it will repaint 
  140.       WinInvalidateRect(WinWindowFromID(hwndDlg, 
  141.                                         ID_MIX), 
  142.                         NULL, 
  143.                         FALSE); 
  144.  
  145.       // No longer setting values 
  146.       Setting = FALSE; 
  147.  
  148.       break; 
  149.     } 
  150.  
  151.     // Case draw item for owner drawn portion of sliders 
  152.     case WM_DRAWITEM: 
  153.     { 
  154.       // Get control identifier 
  155.       SHORT ID = SHORT1FROMMP(mp1); 
  156.  
  157.       // Switch on the control identifier 
  158.       switch (ID) 
  159.       { 
  160.         // case red, green or blue slider 
  161.         case ID_SLIDER_RED: 
  162.         case ID_SLIDER_GREEN: 
  163.         case ID_SLIDER_BLUE: 
  164.           { 
  165.             // Get owner item structure 
  166.             POWNERITEM POwnerItem = (POWNERITEM) PVOIDFROMMP(mp2); 
  167.  
  168.             // If drawing the ribbon strip 
  169.             if (POwnerItem->idItem == SDA_RIBBONSTRIP) 
  170.             { 
  171.               // Get color index 
  172.               int Index = ID - ID_SLIDER_RED; 
  173.  
  174.               // Fill in the ribbon strip with appropriate color 
  175.               WinFillRect(POwnerItem->hps, 
  176.                           &POwnerItem->rclItem, 
  177.                           RibbonColors[Index]); 
  178.  
  179.               // Return TRUE so the slider won't draw its own ribbon strip 
  180.               return (MRESULT) TRUE; 
  181.             } 
  182.             else 
  183.             { 
  184.               // If drawing the slider shaft 
  185.               if (POwnerItem->idItem == SDA_SLIDERSHAFT) 
  186.               { 
  187.                 // Get color index 
  188.                 int Index = ID - ID_SLIDER_RED; 
  189.  
  190.                 // Fill in the slider shaft with appropriate color 
  191.                 WinFillRect(POwnerItem->hps, 
  192.                             &POwnerItem->rclItem, 
  193.                             ShaftColors[Index]); 
  194.  
  195.                 // Return TRUE so the slider won't draw its own slider shaft 
  196.                 return (MRESULT) TRUE; 
  197.               } 
  198.             } 
  199.           } 
  200.  
  201.           break; 
  202.       } 
  203.  
  204.       break; 
  205.     } 
  206.  
  207.     // case Command 
  208.     case WM_COMMAND: 
  209.  
  210.       // switch on the dialog item 
  211.       switch (SHORT1FROMMP(mp1)) 
  212.       { 
  213.         // case OK 
  214.         // case Cancel 
  215.         case DID_OK: 
  216.         case DID_CANCEL: 
  217.  
  218.           // Dismiss the dialog 
  219.           WinDismissDlg(hwndDlg, (ULONG) SHORT1FROMMP(mp1)); 
  220.  
  221.           break; 
  222.  
  223.         // default case 
  224.         default: 
  225.  
  226.           // get PM's default procedure to handle the request 
  227.           return WinDefDlgProc(hwndDlg, 
  228.                                msg, 
  229.                                mp1, 
  230.                                mp2); 
  231.  
  232.           break; 
  233.       } 
  234.  
  235.       break; 
  236.  
  237.     // case Control 
  238.     case WM_CONTROL: 
  239.     { 
  240.       // Get control identifier 
  241.       SHORT ID = SHORT1FROMMP(mp1); 
  242.  
  243.       // switch on the dialog item 
  244.       switch (ID) 
  245.       { 
  246.         // case red, green or blue slider 
  247.         case ID_SLIDER_RED: 
  248.         case ID_SLIDER_GREEN: 
  249.         case ID_SLIDER_BLUE: 
  250.  
  251.           // switch on the PM action 
  252.           switch (SHORT2FROMMP(mp1)) 
  253.           { 
  254.             // case slider change 
  255.             case SLN_CHANGE: 
  256.             case SLN_SLIDERTRACK: 
  257.             { 
  258.               // If not already setting values 
  259.               if (Setting == FALSE) 
  260.               { 
  261.                 // Get index for red, green, blue 
  262.                 SHORT Index = ID - ID_SLIDER_RED; 
  263.  
  264.                 // get the new color value 
  265.                 RGBColors[Index] = SHORT1FROMMR(WinSendDlgItemMsg(hwndDlg, 
  266.                                                 ID, 
  267.                                                 SLM_QUERYSLIDERINFO, 
  268.                                                 MPFROM2SHORT(SMA_SLIDERARMPOSITION, 
  269.                                                              SMA_INCREMENTVALUE), 
  270.                                                 MPFROMLONG(0))); 
  271.  
  272.                 // We're setting values 
  273.                 Setting = TRUE; 
  274.  
  275.                 // Set corresponding spin button 
  276.                 WinSendDlgItemMsg(hwndDlg, 
  277.                                   ID_SPIN_RED + Index, 
  278.                                   SPBM_SETCURRENTVALUE, 
  279.                                   MPFROMLONG((long) RGBColors[Index]), 
  280.                                   0); 
  281.  
  282.                 // We're no longer setting values 
  283.                 Setting = FALSE; 
  284.  
  285.                 // invalidate the mix window so it will get redrawn 
  286.                 WinInvalidateRect(WinWindowFromID(hwndDlg, 
  287.                                                   ID_MIX), 
  288.                                   NULL, 
  289.                                   FALSE); 
  290.               } 
  291.  
  292.               break; 
  293.             } 
  294.  
  295.             // default case 
  296.             default: 
  297.  
  298.               // get PM's default procedure to handle the request 
  299.               return WinDefDlgProc(hwndDlg, 
  300.                                    msg, 
  301.                                    mp1, 
  302.                                    mp2); 
  303.  
  304.               break; 
  305.           } 
  306.           // endswitch - switch on the PM action 
  307.  
  308.           break; 
  309.  
  310.         // case red, green or blue spin button 
  311.         case ID_SPIN_RED: 
  312.         case ID_SPIN_GREEN: 
  313.         case ID_SPIN_BLUE: 
  314.  
  315.           // switch on the PM action 
  316.           switch (SHORT2FROMMP(mp1)) 
  317.           { 
  318.             // case value change 
  319.             case SPBN_CHANGE: 
  320.             { 
  321.               // If not already setting values 
  322.               if (Setting == FALSE) 
  323.               { 
  324.                 // Get index for red, green, blue 
  325.                 SHORT Index = ID - ID_SPIN_RED; 
  326.  
  327.                 // get the new color value 
  328.                 long NewValue; 
  329.                 WinSendDlgItemMsg(hwndDlg, 
  330.                                   ID, 
  331.                                   SPBM_QUERYVALUE, 
  332.                                   MRFROMP(&NewValue), 
  333.                                   MRFROM2SHORT(0, 
  334.                                                SPBQ_ALWAYSUPDATE)); 
  335.                 RGBColors[Index] = (SHORT) NewValue; 
  336.  
  337.                 // We're setting values 
  338.                 Setting = TRUE; 
  339.  
  340.                 // Set slider value 
  341.                 WinSendDlgItemMsg(hwndDlg, 
  342.                                   ID_SLIDER_RED + Index, 
  343.                                   SLM_SETSLIDERINFO, 
  344.                                   MPFROM2SHORT(SMA_SLIDERARMPOSITION, 
  345.                                                SMA_INCREMENTVALUE), 
  346.                                   MPFROMSHORT(RGBColors[Index])); 
  347.  
  348.                 // We're no longer setting values 
  349.                 Setting = FALSE; 
  350.  
  351.                 // invalidate the mix window so it will get redrawn 
  352.                 WinInvalidateRect(WinWindowFromID(hwndDlg, 
  353.                                                   ID_MIX), 
  354.                                   NULL, 
  355.                                   FALSE); 
  356.               } 
  357.               else 
  358.  
  359.               break; 
  360.             } 
  361.  
  362.             // default case 
  363.             default: 
  364.  
  365.               // get PM's default procedure to handle the request 
  366.               return WinDefDlgProc(hwndDlg, 
  367.                                    msg, 
  368.                                    mp1, 
  369.                                    mp2); 
  370.  
  371.               break; 
  372.           } 
  373.           // endswitch - switch on the PM action 
  374.  
  375.           break; 
  376.  
  377.         // default case 
  378.         default: 
  379.  
  380.           // get PM's default procedure to handle the request 
  381.           return WinDefDlgProc(hwndDlg, 
  382.                                msg, 
  383.                                mp1, 
  384.                                mp2); 
  385.  
  386.           break; 
  387.       } 
  388.       // endswitch - switch on the dialog item 
  389.       break; 
  390.     } 
  391.  
  392.     // default case 
  393.     default: 
  394.  
  395.       // get PM's default procedure to handle the request 
  396.       return WinDefDlgProc(hwndDlg, 
  397.                            msg, 
  398.                            mp1, 
  399.                            mp2); 
  400.  
  401.       break; 
  402.   } 
  403.  
  404.   return FALSE; 
  405.  
  406.  
  407. MRESULT EXPENTRY fnwpColorSample( HWND hwnd, ULONG msg, 
  408.                                   MPARAM mp1, MPARAM mp2 ) 
  409.   // If processing the paint message 
  410.   if (msg == WM_PAINT) 
  411.   { 
  412.     HPS    hps; 
  413.     RECTL  rcl,rcl1; 
  414.  
  415.     // Issue the begin paint 
  416.     hps = WinBeginPaint(hwnd, 
  417.                         NULL, 
  418.                         &rcl); 
  419.  
  420.     // Override the rectangle returned from WinBeginPaint with the 
  421.     // window's entire rectangle 
  422.     WinQueryWindowRect(hwnd, &rcl); 
  423.  
  424.     // Compose the color value needed by GpiCreateLogColorTable 
  425.     Color =                RGBColors[BLUE]   + 
  426.           (256L   * (LONG) RGBColors[GREEN]) + 
  427.           (65536L * (LONG) RGBColors[RED  ]); 
  428.  
  429.     // Create a color log table with one entry 
  430.     GpiCreateLogColorTable(hps, 
  431.                            LCOL_RESET, 
  432.                            LCOLF_RGB, 
  433.                            0L, 
  434.                            1L, 
  435.                            &Color); 
  436.  
  437.     // Issue four fills to outline the color in black 
  438.     rcl1.xLeft=rcl.xLeft; 
  439.     rcl1.xRight=rcl.xRight; 
  440.     rcl1.yTop=rcl.yTop; 
  441.     rcl1.yBottom=rcl.yTop - 4; 
  442.     WinFillRect(hps, &rcl1, CLR_BLACK); 
  443.  
  444.     rcl1.xLeft=rcl.xLeft; 
  445.     rcl1.xRight=rcl.xRight; 
  446.     rcl1.yTop=rcl.yBottom + 4; 
  447.     rcl1.yBottom=rcl.yBottom; 
  448.     WinFillRect(hps, &rcl1, CLR_BLACK); 
  449.  
  450.     rcl1.xLeft=rcl.xLeft; 
  451.     rcl1.xRight=rcl.xLeft + 4; 
  452.     rcl1.yTop=rcl.yTop - 4; 
  453.     rcl1.yBottom=rcl.yBottom + 4; 
  454.     WinFillRect(hps, &rcl1, CLR_BLACK); 
  455.  
  456.     rcl1.xLeft=rcl.xRight - 4; 
  457.     rcl1.xRight=rcl.xRight; 
  458.     rcl1.yTop=rcl.yTop - 4; 
  459.     rcl1.yBottom=rcl.yBottom + 4; 
  460.     WinFillRect(hps, &rcl1, CLR_BLACK); 
  461.  
  462.     // Fill the rest of the rectangle with the current color 
  463.     rcl.xLeft += 5; 
  464.     rcl.yBottom += 5; 
  465.     rcl.xRight -= 5; 
  466.     rcl.yTop -= 5; 
  467.     WinFillRect(hps, &rcl, Color); 
  468.  
  469.     // Issue the end paint 
  470.     WinEndPaint( hps ); 
  471.  
  472.     // Return value is unimportant 
  473.     return FALSE; 
  474.   } 
  475.   else 
  476.   { 
  477.     // Pass all other messages to the default window procedure 
  478.     return WinDefWindowProc(hwnd, msg, mp1, mp2); 
  479.   } 
  480.  
  481.  
  482.