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

对话框与窗口

开发平台:

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 "GuiGroupBox.h"
  24. #include "GuiDrawLayer.h"
  25. #ifdef _DEBUG
  26. #define new DEBUG_NEW
  27. #undef THIS_FILE
  28. static char THIS_FILE[] = __FILE__;
  29. #endif
  30. /////////////////////////////////////////////////////////////////////////////
  31. // CGuiGroupBox
  32. CGuiGroupBox::CGuiGroupBox()
  33. {
  34. m_clrface=GuiDrawLayer::GetRGBColorFace();
  35. m_clrShadow=GuiDrawLayer::GetRGBColorShadow();
  36. m_style=ALING_LEFT;
  37. m_Caption=_T("");
  38. }
  39. CGuiGroupBox::~CGuiGroupBox()
  40. {
  41. }
  42. BEGIN_MESSAGE_MAP(CGuiGroupBox, CButton)
  43. //{{AFX_MSG_MAP(CGuiGroupBox)
  44. ON_WM_PAINT()
  45. ON_WM_SYSCOLORCHANGE()
  46. //}}AFX_MSG_MAP
  47. END_MESSAGE_MAP()
  48. /////////////////////////////////////////////////////////////////////////////
  49. // CGuiGroupBox message handlers
  50. void CGuiGroupBox::PreSubclassWindow() 
  51. {
  52. CButton::PreSubclassWindow();
  53. GetWindowText(m_Caption);
  54. SetWindowText(_T(""));
  55. }
  56. void CGuiGroupBox::SetCaption(CString Caption)
  57. {
  58. m_Caption=Caption;
  59. SetWindowText(_T(""));
  60. }
  61. void CGuiGroupBox::OnPaint() 
  62. {
  63. CPaintDC dc(this); // device context for painting
  64. CRect rc;
  65. GetClientRect(rc);
  66. CBrush cb;
  67. CFont m_cfont;
  68. CString m_caption;
  69. CPen cpshadow(PS_SOLID,1,GuiDrawLayer::GetRGBColorShadow());
  70. cb.CreateSolidBrush(m_clrface);
  71. if ((m_style == ALING_LEFT) || (m_style == ALING_RIGHT))
  72. m_cfont.CreateFont( -11,0,0,0,400,0,0,0,0,1,2,1,34,_T("Verdana"));
  73. else
  74. m_cfont.CreateFont(-11,0,900,900,400,0,0,0,0,1,2,1,34,_T("Verdana"));
  75. //********************************************************
  76. CFont* m_fontOld=dc.SelectObject(&m_cfont);
  77. CSize SizeCad=dc.GetTextExtent(m_Caption);
  78. SizeCad.cx+=2;
  79. CRect rCText=rc;
  80. rc.DeflateRect(1,1);
  81. rc.top+=6;
  82. //orientar la cadena*************************************
  83. if (m_style == ALING_LEFT)
  84. {
  85. rCText.left+=6;
  86. rCText.bottom=rCText.top+SizeCad.cy+1;
  87. rCText.right=rCText.left+SizeCad.cx+1;
  88. }
  89. else if (m_style == ALING_RIGHT)
  90. {
  91. rCText.right-=6;
  92. rCText.left=rCText.right-SizeCad.cx+1;
  93. rCText.bottom=rCText.top+SizeCad.cy+1;
  94. }
  95. else if (m_style == ALING_DOWN)
  96. {
  97. rCText.bottom-=6;
  98. rCText.left=-7;
  99. rCText.top=rCText.bottom-SizeCad.cx;
  100. rCText.right=rCText.left+SizeCad.cy+1;
  101. }
  102. else if (m_style == ALING_UP)
  103. {
  104. rCText.top+=10;
  105. rCText.left=-7;
  106. rCText.right=rCText.left+SizeCad.cy+1;
  107. rCText.bottom=rCText.top+SizeCad.cx+7;
  108. }
  109. //********************************************************
  110. CPen* pOld=dc.SelectObject(&cpshadow);
  111. //linea superior
  112. dc.MoveTo(rc.left+2,rc.top);
  113. dc.LineTo(rc.right-2,rc.top);
  114. //linea vertical izquierda
  115. dc.MoveTo(rc.left,rc.top+2);
  116. dc.LineTo(rc.left,rc.bottom-2);
  117. //linea vertical derecha
  118. dc.MoveTo(rc.right,rc.top+2);
  119. dc.LineTo(rc.right,rc.bottom-2);
  120. //linea horizontal inferior
  121. dc.MoveTo(rc.left+2,rc.bottom);
  122. dc.LineTo(rc.right-2,rc.bottom);
  123. //ahora se dibujan los vertices
  124. //l,t
  125. dc.MoveTo(rc.left+2,rc.top);
  126. dc.LineTo(rc.left,rc.top+2);
  127. //r,t
  128. dc.MoveTo(rc.right-2,rc.top);
  129. dc.LineTo(rc.right,rc.top+2);
  130. //l,b
  131. dc.MoveTo(rc.left,rc.bottom-2);
  132. dc.LineTo(rc.left+2,rc.bottom);
  133. //r,b
  134. dc.MoveTo(rc.right-2,rc.bottom);
  135. dc.LineTo(rc.right,rc.bottom-2);
  136. //sentido del mensaje
  137. int nMode = dc.SetBkMode(TRANSPARENT);
  138. dc.FillRect(rCText,&cb);
  139. dc.SetTextColor(GuiDrawLayer::GetRGBCaptionXP());
  140. int cont=SizeCad.cx;
  141. if (m_style == ALING_DOWN || m_style == ALING_UP)
  142. dc.TextOut(rCText.left,rCText.bottom-2,m_Caption);
  143. else
  144. dc.TextOut(rCText.left,rCText.top,m_Caption);
  145.   dc.SetBkMode(nMode);
  146. dc.SelectObject(&m_fontOld);
  147. }
  148. void CGuiGroupBox::SetStyle(Aling style)
  149. {
  150. m_style=style;
  151. }
  152. void CGuiGroupBox::OnSysColorChange() 
  153. {
  154. m_clrface=GuiDrawLayer::GetRGBColorFace();
  155. m_clrShadow=GuiDrawLayer::GetRGBColorShadow();
  156. CButton::OnSysColorChange();
  157. }