GameHighButton.cpp
上传用户:swkcbjrc
上传日期:2016-04-02
资源大小:45277k
文件大小:4k
源码类别:

游戏

开发平台:

Visual C++

  1. // JQButton.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "GameHighButton.h"
  5. #include "baseFunction.h"
  6. #include "resource.h"
  7. #ifdef _DEBUG
  8. #define new DEBUG_NEW
  9. #undef THIS_FILE
  10. static char THIS_FILE[] = __FILE__;
  11. #endif
  12. /////////////////////////////////////////////////////////////////////////////
  13. // CGameHighButton
  14. CGameHighButton::CGameHighButton()
  15. {
  16. _IsFocus =FALSE;
  17. _IsDown =FALSE;
  18. clrFocus =RGB(0, 0, 255);
  19. hCursor =NULL;
  20. clrBk =RGB(123, 178, 206);
  21. }
  22. CGameHighButton::~CGameHighButton()
  23. {
  24. if(NULL != hCursor)
  25. {
  26. ::DestroyCursor(hCursor);
  27. hCursor =NULL;
  28. }
  29. }
  30. BEGIN_MESSAGE_MAP(CGameHighButton, CButton)
  31. //{{AFX_MSG_MAP(CGameHighButton)
  32. ON_WM_LBUTTONUP()
  33. ON_WM_LBUTTONDOWN()
  34. ON_WM_MOUSEMOVE()
  35. ON_WM_SETCURSOR()
  36. //}}AFX_MSG_MAP
  37. END_MESSAGE_MAP()
  38. /////////////////////////////////////////////////////////////////////////////
  39. // CGameHighButton message handlers
  40. void CGameHighButton::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct) 
  41. {
  42. DrawHallStyleButton(lpDrawItemStruct);
  43. }
  44. void CGameHighButton::OnLButtonUp(UINT nFlags, CPoint point) 
  45. {
  46. if(!this->IsWindowEnabled())
  47. return;
  48. this->_IsDown =FALSE;
  49. Invalidate();
  50. CButton::OnLButtonUp(nFlags, point);
  51. }
  52. void CGameHighButton::OnLButtonDown(UINT nFlags, CPoint point) 
  53. {
  54. if(!this->IsWindowEnabled())
  55. return;
  56. this->_IsDown =TRUE;
  57. Invalidate();
  58. CButton::OnLButtonDown(nFlags, point);
  59. }
  60. void CGameHighButton::OnMouseMove(UINT nFlags, CPoint point) 
  61. {
  62. if(!this->IsWindowEnabled())
  63. return;
  64. POINT _point;
  65. ::GetCursorPos(&_point);
  66. RECT rect;
  67. this->GetWindowRect(&rect);
  68. if (::PtInRect( &rect, _point) &&
  69. ::WindowFromPoint(_point) == this ->GetSafeHwnd())
  70. {
  71. this->_IsFocus =TRUE;
  72. if(this->GetSafeHwnd() != ::GetCapture())
  73. {
  74. this->Invalidate();
  75. this->SetCapture();
  76. }
  77. }
  78. else
  79. {
  80. this->_IsFocus =FALSE;
  81. if(this->GetSafeHwnd() == ::GetCapture())
  82. {
  83. this->Invalidate();
  84. ReleaseCapture();
  85. }
  86. }
  87. CButton::OnMouseMove(nFlags, point);
  88. }
  89. void CGameHighButton::DrawHallStyleButton(LPDRAWITEMSTRUCT lpDrawItemStruct)
  90. {
  91. ASSERT(lpDrawItemStruct);
  92. if(NULL == lpDrawItemStruct)
  93. {
  94. return ;
  95. }
  96. // this->ModifyStyleEx(NULL, WS_EX_TRANSPARENT, 0);
  97. RECT rect;
  98. memset(&rect, 0, sizeof(RECT));
  99. ::CopyRect(&rect, &(lpDrawItemStruct->rcItem));
  100. HDC hDC =lpDrawItemStruct->hDC;
  101. if(NULL == hDC)
  102. return;
  103. CDC* pDC =NULL;
  104. pDC =pDC->FromHandle(hDC);
  105. if(NULL == pDC ||
  106. NULL == pDC->GetSafeHdc())
  107. {
  108. return ;
  109. }
  110. CBrush m_Brush;
  111. m_Brush.CreateSolidBrush(clrBk);
  112. if(NULL != m_Brush.GetSafeHandle())
  113. {
  114. pDC->FillRect(&rect, &m_Brush);
  115. }
  116. m_Brush.DeleteObject();
  117. CString strTitle;
  118. strTitle.Empty();
  119. this->GetWindowText(strTitle);
  120. if(!strTitle.IsEmpty())
  121. {
  122. ::SetBkMode(hDC, TRANSPARENT);
  123. if(this->IsWindowEnabled())
  124. {
  125. HFONT hFont =NULL;
  126. HFONT hOldFont =NULL;
  127. LOGFONT lgFont;
  128. memset(&lgFont, 0, sizeof(LOGFONT));
  129. if(IsWin9x())
  130. {
  131. lgFont.lfHeight =15;
  132. }
  133. else
  134. {
  135. lgFont.lfHeight =14;
  136. }
  137. if(_IsFocus)
  138. {
  139. lgFont.lfUnderline =TRUE;
  140. }
  141. if(_IsFocus)
  142. {
  143. ::SetTextColor(hDC, clrFocus);
  144. }
  145. hFont=::CreateFontIndirect(&lgFont);
  146. hOldFont =(HFONT)::SelectObject(hDC, hFont);
  147. ::DrawText(hDC, strTitle, strTitle.GetLength(), &rect, DT_VCENTER | DT_SINGLELINE | DT_CENTER);
  148. if(NULL != hFont && NULL != hOldFont)
  149. {
  150. ::SelectObject(hDC, hOldFont);
  151. ::DeleteObject(hFont);
  152. }
  153. }
  154. else
  155. {
  156. rect.left +=1;
  157. rect.right +=1;
  158. rect.top +=1;
  159. rect.bottom +=1;
  160. ::SetTextColor(hDC, GetSysColor(COLOR_3DHILIGHT));
  161. ::DrawText(hDC, strTitle, strTitle.GetLength(), &rect, DT_VCENTER | DT_SINGLELINE | DT_CENTER);
  162. rect.left -=1;
  163. rect.right -=1;
  164. rect.top -=1;
  165. rect.bottom -=1;
  166. ::SetTextColor(hDC, GetSysColor(COLOR_GRAYTEXT));
  167. ::DrawText(hDC, strTitle, strTitle.GetLength(), &rect, DT_VCENTER | DT_SINGLELINE);
  168. }
  169. }
  170. }
  171. BOOL CGameHighButton::OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message) 
  172. {
  173. if( NULL == hCursor)
  174. hCursor=::LoadCursor(::AfxGetInstanceHandle(),MAKEINTRESOURCE(IDC_MYHAND));
  175. if(hCursor)
  176. ::SetCursor(hCursor);
  177. return 1;
  178. }
  179. void CGameHighButton::SetBkColor(COLORREF clr)
  180. {
  181. clrBk =clr;
  182. }