GuiGroupBox.cpp
上传用户:zhanglf88
上传日期:2013-11-19
资源大小:6036k
文件大小:4k
源码类别:

金融证券系统

开发平台:

Visual C++

  1. //-----------------------------------------------------------------------//
  2. // This is a part of the GuiLib MFC Extention.  //
  3. // Autor  :  Francisco Campos  //
  4. // (C) 2002 Francisco Campos <www.beyondata.com> All rights reserved     //
  5. // This code is provided "as is", with absolutely no warranty expressed  //
  6. // or implied. Any use is at your own risk.  //
  7. // You must obtain the author's consent before you can include this code //
  8. // in a software library.  //
  9. // If the source code in  this file is used in any application  //
  10. // then acknowledgement must be made to the author of this program  //
  11. // fcampos@tutopia.com  //
  12. //-----------------------------------------------------------------------//
  13. #include "stdafx.h"
  14. #include "GuiGroupBox.h"
  15. #ifdef _DEBUG
  16. #define new DEBUG_NEW
  17. #undef THIS_FILE
  18. static char THIS_FILE[] = __FILE__;
  19. #endif
  20. /////////////////////////////////////////////////////////////////////////////
  21. // CGuiGroupBox
  22. #include "GuiDrawLayer.h"
  23. CGuiGroupBox::CGuiGroupBox()
  24. {
  25. m_clrface=GuiDrawLayer::GetRGBColorFace();
  26. m_clrShadow=GuiDrawLayer::GetRGBColorShadow();
  27. m_style=ALING_LEFT;
  28. }
  29. CGuiGroupBox::~CGuiGroupBox()
  30. {
  31. }
  32. BEGIN_MESSAGE_MAP(CGuiGroupBox, CButton)
  33. //{{AFX_MSG_MAP(CGuiGroupBox)
  34. ON_WM_PAINT()
  35. ON_WM_SYSCOLORCHANGE()
  36. //}}AFX_MSG_MAP
  37. END_MESSAGE_MAP()
  38. /////////////////////////////////////////////////////////////////////////////
  39. // CGuiGroupBox message handlers
  40. void CGuiGroupBox::PreSubclassWindow() 
  41. {
  42. CButton::PreSubclassWindow();
  43. }
  44. void CGuiGroupBox::OnPaint() 
  45. {
  46. CPaintDC dc(this); // device context for painting
  47. CRect rc;
  48. GetClientRect(rc);
  49. CBrush cb;
  50. CFont m_cfont;
  51. CString m_caption;
  52. CPen cpshadow(PS_SOLID,1,GuiDrawLayer::GetRGBColorShadow());
  53. cb.CreateSolidBrush(m_clrface);
  54. GetWindowText(m_caption);
  55. if ((m_style == ALING_LEFT) || (m_style == ALING_RIGHT))
  56. m_cfont.CreateFont( -11,0,0,0,400,0,0,0,0,1,2,1,34,"Verdana");
  57. else
  58. m_cfont.CreateFont(-11,0,900,900,400,0,0,0,0,1,2,1,34,"Verdana");
  59. //********************************************************
  60. CFont* m_fontOld=dc.SelectObject(&m_cfont);
  61. CSize SizeCad=dc.GetTextExtent(m_caption);
  62. SizeCad.cx+=2;
  63. CRect rCText=rc;
  64. rc.DeflateRect(1,1);
  65. rc.top+=6;
  66. //orientar la cadena*************************************
  67. if (m_style == ALING_LEFT)
  68. {
  69. rCText.left+=6;
  70. rCText.bottom=rCText.top+SizeCad.cy+1;
  71. rCText.right=rCText.left+SizeCad.cx+1;
  72. }
  73. else if (m_style == ALING_RIGHT)
  74. {
  75. rCText.right-=6;
  76. rCText.left=rCText.right-SizeCad.cx+1;
  77. rCText.bottom=rCText.top+SizeCad.cy+1;
  78. }
  79. else if (m_style == ALING_DOWN)
  80. {
  81. rCText.bottom-=6;
  82. rCText.left=-7;
  83. rCText.top=rCText.bottom-SizeCad.cx;
  84. rCText.right=rCText.left+SizeCad.cy+1;
  85. }
  86. else if (m_style == ALING_UP)
  87. {
  88. rCText.top+=10;
  89. rCText.left=-7;
  90. rCText.right=rCText.left+SizeCad.cy+1;
  91. rCText.bottom=rCText.top+SizeCad.cx+7;
  92. }
  93. //********************************************************
  94. CPen* pOld=dc.SelectObject(&cpshadow);
  95. //linea superior
  96. dc.MoveTo(rc.left+2,rc.top);
  97. dc.LineTo(rc.right-2,rc.top);
  98. //linea vertical izquierda
  99. dc.MoveTo(rc.left,rc.top+2);
  100. dc.LineTo(rc.left,rc.bottom-2);
  101. //linea vertical derecha
  102. dc.MoveTo(rc.right,rc.top+2);
  103. dc.LineTo(rc.right,rc.bottom-2);
  104. //linea horizontal inferior
  105. dc.MoveTo(rc.left+2,rc.bottom);
  106. dc.LineTo(rc.right-2,rc.bottom);
  107. //ahora se dibujan los vertices
  108. //l,t
  109. dc.MoveTo(rc.left+2,rc.top);
  110. dc.LineTo(rc.left,rc.top+2);
  111. //r,t
  112. dc.MoveTo(rc.right-2,rc.top);
  113. dc.LineTo(rc.right,rc.top+2);
  114. //l,b
  115. dc.MoveTo(rc.left,rc.bottom-2);
  116. dc.LineTo(rc.left+2,rc.bottom);
  117. //r,b
  118. dc.MoveTo(rc.right-2,rc.bottom);
  119. dc.LineTo(rc.right,rc.bottom-2);
  120. //sentido del mensaje
  121. int nMode = dc.SetBkMode(TRANSPARENT);
  122. dc.FillRect(rCText,&cb);
  123. dc.SetTextColor(GuiDrawLayer::GetRGBCaptionXP());
  124. int cont=SizeCad.cx;
  125. if (m_style == ALING_DOWN || m_style == ALING_UP)
  126. dc.TextOut(rCText.left,rCText.bottom-2,m_caption);
  127. else
  128. dc.TextOut(rCText.left,rCText.top,m_caption);
  129.   dc.SetBkMode(nMode);
  130. // Modified By SunZhenyu
  131. dc.SelectObject(m_fontOld);
  132. dc.SelectObject(pOld);
  133. }
  134. void CGuiGroupBox::SetStyle(Aling style)
  135. {
  136. m_style=style;
  137. }
  138. void CGuiGroupBox::OnSysColorChange() 
  139. {
  140. m_clrface=GuiDrawLayer::GetRGBColorFace();
  141. m_clrShadow=GuiDrawLayer::GetRGBColorShadow();
  142. CButton::OnSysColorChange();
  143. }