GuiNormalButton.cpp
上传用户:wlkj888
上传日期:2022-08-01
资源大小:806k
文件大小:4k
源码类别:

对话框与窗口

开发平台:

Visual C++

  1. /****************************************************************************
  2.  * *  
  3.  * GuiToolKit   *
  4.  *  (MFC extension) *  
  5.  * Created by Francisco Campos G. www.beyondata.com fcampos@beyondata.com *
  6.  *--------------------------------------------------------------------------*    
  7.  * *
  8.  * This program is free software;so you are free to use it any of your *
  9.  * applications (Freeware, Shareware, Commercial),but leave this header *
  10.  * intact. *
  11.  * *
  12.  * These files are provided "as is" without warranty of any kind. *
  13.  * *
  14.  *        GuiToolKit is forever FREE CODE !!!!! *
  15.  * *
  16.  *--------------------------------------------------------------------------*
  17.  * Created by: Francisco Campos G. *
  18.  * Bug Fixes and improvements : (Add your name) *
  19.  * -Francisco Campos *
  20.  * *
  21.  ****************************************************************************/
  22. #include "stdafx.h"
  23. #include "guinormalbutton.h"
  24. #include "GuiDrawLayer.h"
  25. #ifdef _DEBUG
  26. #undef THIS_FILE
  27. static char THIS_FILE[]=__FILE__;
  28. #define new DEBUG_NEW
  29. #endif
  30. CGuiNormalButton::CGuiNormalButton(void)
  31. {
  32. m_stlbtn=STL_NORMAL;
  33. m_clColor=GuiDrawLayer::GetRGBColorFace();
  34. }
  35. CGuiNormalButton::~CGuiNormalButton(void)
  36. {
  37. }
  38. void CGuiNormalButton::SetStyleButton(StyleBtn StlButton)
  39. {
  40. m_stlbtn=StlButton;
  41. }
  42. //STL_NORMAL=0,STL_FLAT=1,STL_SEMIFLAT=2,STL_XP=3
  43. void CGuiNormalButton::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct)
  44. {
  45. CDC*  pdc= CDC::FromHandle(lpDrawItemStruct->hDC);
  46. CRect rc=lpDrawItemStruct->rcItem;
  47. UINT  uState=lpDrawItemStruct->itemState;
  48. CBrush cb;
  49. cb.CreateSolidBrush(m_clColor);
  50. COLORREF clrTL =GuiDrawLayer::GetRGBColorBTNHigh();
  51. COLORREF clrBR =GuiDrawLayer::GetRGBColorShadow();
  52. pdc->FillRect(rc,&cb);
  53. if( uState & ODS_SELECTED) //the button is pressed
  54. {
  55. switch(m_stlbtn)
  56. {
  57. case STL_FLAT:
  58. case STL_NORMAL:
  59. case STL_SEMIFLAT:
  60. pdc->Draw3dRect(rc,clrBR,clrTL);
  61. rc.DeflateRect(1,1);
  62. break;
  63. }
  64. }
  65. else if(m_bMouserOver)
  66. {
  67. switch(m_stlbtn)
  68. {
  69. case STL_FLAT:
  70. case STL_NORMAL:
  71. case STL_SEMIFLAT:
  72. pdc->Draw3dRect(rc,clrTL,clrBR);
  73. rc.DeflateRect(1,1);
  74. break;
  75. }
  76. }else
  77. {
  78. switch(m_stlbtn)
  79. {
  80. case STL_NORMAL:
  81. pdc->Draw3dRect(rc,clrTL,clrBR);
  82. rc.DeflateRect(1,1);
  83. break;
  84. case STL_SEMIFLAT:
  85. pdc->Draw3dRect(rc,clrTL,clrBR);
  86. rc.DeflateRect(1,1);
  87. break;
  88. case STL_FLAT:
  89. break;
  90. }
  91. }
  92. int calculodify;
  93. calculodify=rc.Height()-(m_SizeImage.cy);
  94. calculodify/=2;
  95. int nHeigh=calculodify+(m_bShowDark?1:0);
  96. int nWidth=rc.Width()/2 ;
  97. CPoint m_point=CPoint(nWidth,nHeigh);
  98. if (m_SizeImage.cx > 2)
  99. {
  100. if(m_bMouserOver == 1 && !(uState & ODS_DISABLED) && !(uState & ODS_SELECTED) && m_bShowDark)
  101. {
  102. CPoint p(m_point.x+1,m_point.y+1);
  103. pdc->DrawState(p,m_SizeImage,m_Icon,DSS_MONO,CBrush (GuiDrawLayer::GetRGBColorShadow()));
  104. m_point.x-=1; m_point.y-=1;
  105. }
  106. pdc->DrawState (m_point, m_SizeImage,m_Icon,
  107. (uState==ODS_DISABLED?DSS_DISABLED:DSS_NORMAL),(CBrush*)NULL);
  108. }
  109. if (m_SizeText.cx > 2)
  110. {
  111. int nMode = pdc->SetBkMode(TRANSPARENT);
  112. CRect rectletra=rc;
  113. rectletra.left+=m_SizeImage.cx;
  114. CPoint pt=CSize(rectletra.top,rectletra.left);
  115. if (uState & ODS_DISABLED)
  116. pdc->DrawState(pt, m_SizeText, m_szText, DSS_DISABLED, TRUE, 0, (CBrush*)NULL);
  117. else
  118. pdc->DrawText(m_szText,rectletra,DT_SINGLELINE|DT_LEFT|DT_VCENTER);
  119. pdc->SetBkMode(nMode);
  120. }
  121. }