home *** CD-ROM | disk | FTP | other *** search
/ Clickx 47 / Clickx 47.iso / assets / software / sswitchxp152.exe / source / SpeedswitchXP / ColorComboEx.cpp next >
Encoding:
C/C++ Source or Header  |  2006-06-14  |  3.5 KB  |  127 lines

  1. // ColorComboEx.cpp : implementation file
  2. //
  3. // Eric Zimmerman coolez@one.net
  4.  
  5. #define _UNICODE
  6.  
  7. #include "stdafx.h"
  8. #include "ColorComboEx.h"
  9.  
  10. #ifdef _DEBUG
  11. #define new DEBUG_NEW
  12. #undef THIS_FILE
  13. static char THIS_FILE[] = __FILE__;
  14. #endif
  15.  
  16. /////////////////////////////////////////////////////////////////////////////
  17. // CColorComboEx
  18.  
  19. CColorComboEx::CColorComboEx()
  20. {
  21.     // Add the colors to the array
  22.     
  23.     colors.Add(RGB(0, 0, 0));            // Black
  24.     colors.Add(RGB(128, 0, 0));            // Dark Red
  25.     colors.Add(RGB(0, 128, 0));            // Dark Green
  26.     colors.Add(RGB(128, 128, 0));        // Dark Yellow
  27.     colors.Add(RGB(0, 0, 128));            // Dark Blue
  28.     colors.Add(RGB(128, 0, 128));        // Dark Magenta
  29.     colors.Add(RGB(0, 128, 128));        // Dark Cyan    
  30.     colors.Add(RGB(192, 192, 192));        // Light Grey
  31.     colors.Add(RGB(128, 128, 128));        // Medium Grey
  32.     colors.Add(RGB(255, 0, 0));            // Red
  33.     colors.Add(RGB(0, 255, 0));            // Green
  34.     colors.Add(RGB(255, 255, 0));        // Yellow
  35.     colors.Add(RGB(0, 0, 255));            // Blue
  36.     colors.Add(RGB(255, 0, 255));        // Magenta
  37.     colors.Add(RGB(0, 255, 255));        // Cyan
  38.     colors.Add(RGB(255, 255, 255));        // White
  39. }
  40.  
  41. CColorComboEx::~CColorComboEx()
  42. {
  43. }
  44.  
  45.  
  46. BEGIN_MESSAGE_MAP(CColorComboEx, CComboBox)
  47.     //{{AFX_MSG_MAP(CColorComboEx)
  48.     //}}AFX_MSG_MAP
  49. END_MESSAGE_MAP()
  50.  
  51. /////////////////////////////////////////////////////////////////////////////
  52. // CColorComboEx message handlers
  53.  
  54. void CColorComboEx::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct) 
  55. {
  56.     // This function of course does all the work.
  57.         
  58.     CDC dc;
  59.     dc.Attach(lpDrawItemStruct->hDC);
  60.     CRect rect(&(lpDrawItemStruct->rcItem));
  61.     
  62.     // This switch statement draws the item in the combo box based on the itemID.
  63.     // The itemID corresponds to the index in the COLORREF array.
  64.     switch(lpDrawItemStruct->itemID)
  65.     {
  66.     // The automatic case
  67.     case 16:
  68.         {
  69.             // Create the brush
  70.             CBrush brush(colors.GetSize());
  71.             CRect rect(&(lpDrawItemStruct->rcItem));
  72.             rect.InflateRect(-2, -2);
  73.             // Color the area
  74.             dc.FillRect(rect, &brush);
  75.             // Draw teh focus rect if the mosue is either over the item, or if the item
  76.             // is selected
  77.             if (lpDrawItemStruct->itemState & ODS_SELECTED)
  78.                 dc.DrawFocusRect(rect);
  79.             
  80.             // Draw the text
  81.             CString strColor = _T("Automatic");
  82.             CSize textSize = dc.GetOutputTextExtent(strColor);
  83.             dc.SetBkMode(TRANSPARENT);
  84.             dc.SetTextColor(RGB(255, 255, 255));
  85.             dc.DrawText(strColor, rect, DT_SINGLELINE | DT_CENTER);
  86.             
  87.         }
  88.         break;
  89.     default:
  90.         // Drawing code for items accept the automatic color
  91.         
  92.         // Create the brush
  93.         CBrush brush(colors[lpDrawItemStruct->itemID]);
  94.         CRect rect(&(lpDrawItemStruct->rcItem));
  95.         rect.InflateRect(-2, -2);
  96.         // Color the area
  97.         dc.FillRect(rect, &brush);
  98.         // Draw the focus rect if the mouse is either over the item, or if the item
  99.         // is selected
  100.         if (lpDrawItemStruct->itemState & ODS_SELECTED)
  101.             dc.DrawFocusRect(rect);
  102.         
  103.     }
  104.     
  105.     // This draws the black frame around each of the colors so that they
  106.     // do not look like they are kind of blended together
  107.     CBrush frameBrush(RGB(0, 0, 0));
  108.     dc.FrameRect(rect, &frameBrush);
  109.     rect.InflateRect(-1, -1);
  110.     
  111.     dc.Detach();
  112.     
  113. }
  114.  
  115. void CColorComboEx::PreSubclassWindow() 
  116. {
  117.     for (int nColors = 0; nColors < colors.GetSize(); nColors++)
  118.         // Add a dummy string for every array item so that WM_DRAWITEM message is sent.
  119.         AddString(_T(""));
  120.     
  121.     // Select the first color when the control is created.
  122.     SetCurSel(0);
  123.     
  124.     CComboBox::PreSubclassWindow();
  125. }
  126.  
  127.