home *** CD-ROM | disk | FTP | other *** search
/ PC Administrator / spravce.iso / RunModule / src / RadioButtonImage.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2001-08-31  |  4.6 KB  |  127 lines

  1. // RadioButtonImage.cpp: implementation of the CRadioButtonImage class.
  2. //
  3. /*
  4. Copyright 2001 Anish Mistry. All rights reserved.
  5.  
  6. Redistribution and use in source and binary forms, with or without modification,
  7. are permitted provided that the following conditions are met:
  8.  
  9.    1. Redistributions of source code must retain the above copyright notice, 
  10.    this list of conditions and the following disclaimer.
  11.    2. Redistributions in binary form must reproduce the above copyright notice,
  12.    this list of conditions and the following disclaimer in the documentation 
  13.    and/or other materials provided with the distribution.
  14.  
  15. THIS SOFTWARE IS PROVIDED BY ANISH MISTRY ``AS IS'' AND ANY EXPRESS OR IMPLIED 
  16. WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY 
  17. AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS 
  18. OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
  19. OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
  20. GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  21. CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
  22. TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  23. SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  24.  
  25. The views and conclusions contained in the software and documentation are those
  26. of the authors and should not be interpreted as representing official policies,
  27. either expressed or implied, of Anish Mistry or AM Productions.
  28.  
  29. * Variation of the FreeBSD License. http://www.freebsd.org/copyright/freebsd-license.html
  30. */
  31. //////////////////////////////////////////////////////////////////////
  32.  
  33. #include "stdafx.h"
  34. #include "RadioButtonImage.h"
  35.  
  36. //////////////////////////////////////////////////////////////////////
  37. // Construction/Destruction
  38. //////////////////////////////////////////////////////////////////////
  39.  
  40. CRadioButtonImage::CRadioButtonImage()
  41. {
  42.     CCheckBoxImage::CCheckBoxImage();
  43. }
  44.  
  45. CRadioButtonImage::~CRadioButtonImage()
  46. {
  47.     CCheckBoxImage::~CCheckBoxImage();
  48. }
  49. /*RECT CRadioButtonImage::DrawButtonText(const HDC buttonDC, POINT &textPos, const RECT buttonRect)
  50. {
  51.     return CCheckBoxImage::DrawButtonText(buttonDC,textPos,buttonRect);
  52. }*/
  53. bool CRadioButtonImage::Draw(HDC originalButtonDC)
  54. {// begin Draw
  55.  
  56.     // get button info
  57.     RECT buttonRect = {NULL};
  58.     GetClientRect(ctrlWnd,&buttonRect);
  59.  
  60.     if(imageTopLeft.x < 0)
  61.         imageTopLeft.x = 0;
  62.  
  63.     SIZE buttonSize = {buttonRect.right,buttonRect.bottom};
  64.  
  65.     HDC buttonDC = CreateCompatibleDC(originalButtonDC);
  66.     HBITMAP buttonBitmap = CreateCompatibleBitmap(originalButtonDC,buttonRect.right,buttonRect.bottom);
  67.     HGDIOBJ oldButtonBitmap = SelectObject(buttonDC,buttonBitmap);
  68.     if(buttonDC != NULL)
  69.     {// begin draw image
  70.         POINT tempPoint = imageTopLeft;
  71.  
  72.         unsigned long int tempStyles = 0;//buttonStyles;
  73.         tempStyles |= DFCS_BUTTONRADIO;    // set so it shows a check instead of a button
  74.  
  75.  
  76.         if((m_nStyles & BS_PUSHLIKE) == BS_PUSHLIKE)
  77.             tempStyles |= DFCS_BUTTONPUSH;
  78.         if(IsDown)
  79.             tempStyles |= DFCS_PUSHED;
  80.  
  81.         // select the default button color brush to draw area with
  82.         HBRUSH brush = CreateSolidBrush(buttonColor);
  83.         HGDIOBJ oldBrush = SelectObject(buttonDC,brush);
  84.         // select the default button color pen to draw area with
  85.         HPEN pen = CreatePen(PS_SOLID,1,buttonColor);
  86.         HGDIOBJ oldPen = SelectObject(buttonDC,pen);
  87.         // draw face
  88.         Rectangle(buttonDC,buttonRect.left,buttonRect.top,buttonRect.right+1,buttonRect.bottom+1);
  89.  
  90.         if(buttonState == BST_CHECKED)
  91.             tempStyles |= DFCS_CHECKED;
  92.  
  93.         DrawCheckBox(buttonDC,tempStyles,&tempPoint);
  94.         tempPoint.x += borderSize.cx;
  95.  
  96.         // draw image
  97.         tempPoint.x += borderSize.cx*2;
  98.         DrawButtonImage(buttonDC,tempPoint);
  99.         tempPoint.x += borderSize.cx*2;
  100.         buttonRect.left = tempPoint.x;
  101.         // draw the text
  102.         RECT buttonTextRect = DrawButtonText(buttonDC,tempPoint,buttonRect);
  103.         // draw focus rect if the button is active
  104.         if(GetFocus() == ctrlWnd)
  105.         {
  106.             RECT temp = buttonTextRect;
  107.             ExpandRectangle(1,&temp);
  108.             DrawFocusRect(buttonDC,&temp);
  109.         }
  110.         
  111.         // copy to originalButtonDC
  112.         BitBlt(originalButtonDC,buttonTopLeft.x,buttonTopLeft.y,buttonSize.cx,buttonSize.cy,buttonDC,buttonTopLeft.x,buttonTopLeft.y,SRCCOPY);
  113.  
  114.         // clean up
  115.         SelectObject(buttonDC,oldButtonBitmap);
  116.         SelectObject(buttonDC,oldBrush);
  117.         SelectObject(buttonDC,oldPen);
  118.         DeleteObject(pen);
  119.         DeleteObject(brush);
  120.         DeleteObject(buttonBitmap);
  121.         DeleteObject(oldButtonBitmap);
  122.         DeleteDC(buttonDC);
  123.  
  124.         return true;
  125.     }// end draw image
  126.     return false;
  127. }// end Draw