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

金融证券系统

开发平台:

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 "GuiRadioButton.h"
  15. #include "GuiDrawLayer.h"
  16. #ifdef _DEBUG
  17. #define new DEBUG_NEW
  18. #undef THIS_FILE
  19. static char THIS_FILE[] = __FILE__;
  20. #endif
  21. /////////////////////////////////////////////////////////////////////////////
  22. // CGuiRadioButton
  23. IMPLEMENT_DYNAMIC(CGuiRadioButton,CButton);
  24. CGuiRadioButton::CGuiRadioButton()
  25. {
  26. m_SelectBtn=FALSE;
  27. m_bOldCheck=FALSE;
  28. m_bPressBtn=FALSE;
  29. m_rc=CRect(0,0,0,0);
  30. }
  31. CGuiRadioButton::~CGuiRadioButton()
  32. {
  33. }
  34. BEGIN_MESSAGE_MAP(CGuiRadioButton, CButton)
  35. //{{AFX_MSG_MAP(CGuiRadioButton)
  36. ON_WM_ERASEBKGND()
  37. ON_WM_TIMER()
  38. ON_WM_MOUSEMOVE()
  39. //ON_WM_LBUTTONDOWN()
  40. ON_WM_LBUTTONUP()
  41. ON_WM_CREATE()
  42. //ON_WM_KILLFOCUS()
  43. //}}AFX_MSG_MAP
  44. END_MESSAGE_MAP()
  45. /////////////////////////////////////////////////////////////////////////////
  46. // CGuiRadioButton message handlers
  47. void CGuiRadioButton::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct) 
  48. {
  49. // TODO: Add your code to draw the specified item
  50. CDC *pDC=CDC::FromHandle(lpDrawItemStruct->hDC);
  51. CRect m_rcClient=lpDrawItemStruct->rcItem;
  52. UINT m_State=lpDrawItemStruct->itemState;
  53. CBrush cb;
  54. CRect m_rcTemp=m_rcClient;
  55. CPoint pt;
  56. CSize  m_Csize;
  57. CString m_szCaption;
  58. COLORREF m_clrCheck=RGB(0,170,170);
  59. COLORREF m_Over=RGB(255,193,111);
  60. CPen cpOver(PS_SOLID,1,RGB(255,193,111));
  61. cb.CreateSolidBrush(GuiDrawLayer::GetRGBColorXP());
  62. pDC->FillRect(m_rcTemp,&cb);
  63. int iMode=pDC->SetBkMode(TRANSPARENT);
  64. int iExtile=GetButtonStyle(); //obtenemos orientaci髇 del texto
  65. CRect m_rcText=m_rcClient;
  66. GetWindowText(m_szCaption);
  67. //-------------------------------------------------------
  68. //Ajust text
  69. //-------------------------------------------------------
  70. if(m_szCaption.GetLength() > 1)
  71. m_Csize= pDC->GetTextExtent(m_szCaption);
  72. if (m_rcClient.Height() > 13)
  73. {
  74. int Dif=m_rcClient.Height()-13;
  75. Dif/=2;
  76. m_rcTemp.top=Dif;
  77. m_rcTemp.bottom=m_rcTemp.top+13;
  78. }
  79. if (iExtile & BS_LEFTTEXT)
  80. {
  81. m_rcTemp.left= m_rcTemp.right-13;
  82. pt=CPoint(m_rcTemp.left,m_rcTemp.top+1);
  83. }
  84. else
  85. {
  86. m_rcTemp.right= m_rcTemp.left+13;
  87. pt=CPoint(m_rcTemp.right+2,m_rcTemp.top+1);
  88. m_rcText.left=m_rcTemp.right+1;
  89. }
  90. m_rc=m_rcTemp;
  91. //-------------------------------------------------------------------
  92. //Draw Ellipse
  93. //-------------------------------------------------------------------
  94. DrawEllipse(pDC,m_rcTemp);
  95. int x=lpDrawItemStruct->itemState;
  96. if (lpDrawItemStruct->itemState & ODS_DISABLED)
  97.    pDC->DrawState(pt, m_Csize, m_szCaption, DSS_DISABLED, TRUE, 0, (HBRUSH)NULL);
  98. else 
  99. pDC->DrawText(m_szCaption,m_rcText,DT_SINGLELINE|DT_LEFT|DT_VCENTER);    
  100. if (m_bPressBtn && !m_SelectBtn)
  101. {
  102. CheckRadio(pDC,m_rc) ;
  103. }
  104. else if(m_SelectBtn && !m_bPressBtn)
  105. {
  106. DrawOrange(pDC,m_rc);
  107. }
  108. else if(m_SelectBtn && m_bPressBtn)
  109. {
  110. DrawOrange(pDC,m_rc);
  111. CheckRadio(pDC,m_rc) ;
  112. }
  113. }
  114. void CGuiRadioButton::SetCheck(int nCheck)
  115. {
  116. m_bPressBtn=nCheck;
  117. }
  118. void CGuiRadioButton::OnTimer(UINT nIDEvent) 
  119. {
  120. // TODO: Add your message handler code here and/or call default
  121. CRect m_rect;
  122. GetClientRect(&m_rect);
  123. CPoint pt(GetMessagePos());
  124. ScreenToClient(&pt);
  125. if (!m_rect.PtInRect(pt))
  126. {
  127. m_SelectBtn=FALSE;
  128. Invalidate();
  129. KillTimer(1);
  130. }
  131. CButton::OnTimer(nIDEvent);
  132. }
  133. void CGuiRadioButton::OnMouseMove(UINT nFlags, CPoint point) 
  134. {
  135. // TODO: Add your message handler code here and/or call default
  136. if (m_SelectBtn==TRUE) return;
  137. CRect m_rect;
  138. GetClientRect(&m_rect);
  139. if (m_rect.PtInRect(point))
  140. {
  141. m_SelectBtn =TRUE;
  142. Invalidate();
  143. UpdateWindow();
  144. SetTimer(1,100,NULL);
  145. }
  146. CButton::OnMouseMove(nFlags, point);
  147. }
  148. void CGuiRadioButton::OnLButtonDown(UINT nFlags, CPoint point) 
  149. {
  150. // TODO: Add your message handler code here and/or call default
  151. m_SelectBtn=TRUE;
  152. SetTimer(1,100,NULL);
  153. Invalidate();
  154. UpdateWindow();
  155. CButton::OnLButtonDown(nFlags, point);
  156. }
  157. void CGuiRadioButton::OnLButtonUp(UINT nFlags, CPoint point) 
  158. {
  159. // TODO: Add your message handler code here and/or call default
  160. CButton::OnLButtonUp(nFlags, point);
  161. CRect m_rect;
  162. GetClientRect(&m_rect);
  163. if (m_rect.PtInRect(point))
  164. {
  165. m_bPressBtn=TRUE;
  166. m_SelectBtn=FALSE;
  167. UnCheckRadio();
  168. Invalidate();
  169. KillTimer(1);
  170. }
  171. }
  172. //*******************************************************************
  173. int CGuiRadioButton::OnCreate(LPCREATESTRUCT lpCreateStruct) 
  174. {
  175. if (CButton::OnCreate(lpCreateStruct) == -1)
  176. return -1;
  177. // TODO: Add your specialized creation code here
  178. return 0;
  179. }
  180. //*******************************************************************
  181. void CGuiRadioButton::OnKillFocus(CWnd* pNewWnd) 
  182. {
  183. CButton::OnKillFocus(pNewWnd);
  184. // TODO: Add your message handler code here
  185. }
  186. //*******************************************************************
  187. void CGuiRadioButton::DrawEllipse(CDC* pDC,CRect m_rc)
  188. {
  189. //***************************************
  190. //pDC->SetPixel(CPoint(3,0),RGB(222,228,229));
  191. pDC->SetPixel(CPoint(4,0),RGB(164,184,198));
  192. pDC->SetPixel(CPoint(5,0),RGB(90,128,160));
  193. pDC->SetPixel(CPoint(6,0),RGB(133,158,175));
  194. pDC->SetPixel(CPoint(7,0),RGB(90,128,160));
  195. pDC->SetPixel(CPoint(8,0),RGB(164,184,198));
  196. //pDC->SetPixel(CPoint(9,0),RGB(223,228,229));
  197. pDC->SetPixel(CPoint(2,1),RGB(180,196,207));
  198. pDC->SetPixel(CPoint(3,1),RGB(133,158,175));
  199. pDC->SetPixel(CPoint(4,1),RGB(102,135,163));
  200. pDC->SetPixel(CPoint(5,1),RGB(171,186,197));
  201. pDC->SetPixel(CPoint(7,1),RGB(171,186,197));
  202. pDC->SetPixel(CPoint(8,1),RGB(102,135,163));
  203. pDC->SetPixel(CPoint(9,1),RGB(133,158,175));
  204. pDC->SetPixel(CPoint(10,1),RGB(180,196,207));
  205. pDC->SetPixel(CPoint(1,2),RGB(181,196,207));
  206. pDC->SetPixel(CPoint(2,2),RGB(87,124,156));
  207. pDC->SetPixel(CPoint(3,2),RGB(169,185,195));
  208. pDC->SetPixel(CPoint(9,2),RGB(169,185,195));
  209.     pDC->SetPixel(CPoint(10,2),RGB(87,124,156));
  210. pDC->SetPixel(CPoint(11,2),RGB(181,196,207));
  211. //pDC->SetPixel(CPoint(0,3),RGB(223,228,229));
  212. pDC->SetPixel(CPoint(1,3),RGB(133,158,175));
  213. pDC->SetPixel(CPoint(2,3),RGB(169,185,195));
  214. pDC->SetPixel(CPoint(10,3),RGB(169,185,195));
  215. pDC->SetPixel(CPoint(11,3),RGB(133,158,175));
  216. //pDC->SetPixel(CPoint(12,3),RGB(223,228,229));
  217. pDC->SetPixel(CPoint(0,4),RGB(164,183,198));
  218. pDC->SetPixel(CPoint(1,4),RGB(102,135,163));
  219. pDC->SetPixel(CPoint(11,4),RGB(102,135,163));
  220. pDC->SetPixel(CPoint(12,4),RGB(164,183,198));
  221. pDC->SetPixel(CPoint(0,5),RGB(102,135,163));
  222. pDC->SetPixel(CPoint(1,5),RGB(164,183,198));
  223. pDC->SetPixel(CPoint(11,5),RGB(164,183,198));
  224. pDC->SetPixel(CPoint(12,5),RGB(102,135,163));
  225. pDC->SetPixel(CPoint(0,6),RGB(133,158,175));
  226. pDC->SetPixel(CPoint(12,6),RGB(133,158,175));
  227. pDC->SetPixel(CPoint(0,7),RGB(102,135,163));
  228. pDC->SetPixel(CPoint(1,7),RGB(164,183,198));
  229. pDC->SetPixel(CPoint(11,7),RGB(164,183,198));
  230. pDC->SetPixel(CPoint(12,7),RGB(102,135,163));
  231. pDC->SetPixel(CPoint(0,8),RGB(164,183,198));
  232. pDC->SetPixel(CPoint(1,8),RGB(102,135,163));
  233. pDC->SetPixel(CPoint(11,8),RGB(102,135,163));
  234. pDC->SetPixel(CPoint(12,8),RGB(164,183,198));
  235. //pDC->SetPixel(CPoint(0,9),RGB(223,228,229));
  236. pDC->SetPixel(CPoint(1,9),RGB(133,158,175));
  237. pDC->SetPixel(CPoint(2,9),RGB(169,185,195));
  238. pDC->SetPixel(CPoint(10,9),RGB(169,185,195));
  239. pDC->SetPixel(CPoint(11,9),RGB(133,158,175));
  240. //pDC->SetPixel(CPoint(12,9),RGB(223,228,229));
  241. pDC->SetPixel(CPoint(1,10),RGB(181,196,207));
  242. pDC->SetPixel(CPoint(2,10),RGB(87,124,156));
  243. pDC->SetPixel(CPoint(3,10),RGB(169,185,195));
  244. pDC->SetPixel(CPoint(9,10),RGB(169,185,195));
  245.     pDC->SetPixel(CPoint(10,10),RGB(87,124,156));
  246. pDC->SetPixel(CPoint(11,10),RGB(181,196,207));
  247. pDC->SetPixel(CPoint(2,11),RGB(180,196,207));
  248. pDC->SetPixel(CPoint(3,11),RGB(133,158,175));
  249. pDC->SetPixel(CPoint(4,11),RGB(102,135,163));
  250. pDC->SetPixel(CPoint(5,11),RGB(171,186,197));
  251. pDC->SetPixel(CPoint(7,11),RGB(171,186,197));
  252. pDC->SetPixel(CPoint(8,11),RGB(102,135,163));
  253. pDC->SetPixel(CPoint(9,11),RGB(133,158,175));
  254. pDC->SetPixel(CPoint(10,11),RGB(180,196,207));
  255. //pDC->SetPixel(CPoint(3,12),RGB(222,228,229));
  256. pDC->SetPixel(CPoint(4,12),RGB(164,184,198));
  257. pDC->SetPixel(CPoint(5,12),RGB(90,128,160));
  258. pDC->SetPixel(CPoint(6,12),RGB(133,158,175));
  259. pDC->SetPixel(CPoint(7,12),RGB(90,128,160));
  260. pDC->SetPixel(CPoint(8,12),RGB(164,184,198));
  261. //pDC->SetPixel(CPoint(9,12),RGB(223,228,229));
  262. }
  263. //*******************************************************************
  264. void CGuiRadioButton::CheckRadio(CDC* pDC,CRect m_rc) 
  265. {
  266. CRect m_rcTemp=m_rc;
  267. m_rcTemp.DeflateRect(6,6);
  268. pDC->SetPixel(m_rc.left+6,3,RGB(242,237,215));
  269. pDC->SetPixel(m_rc.left+5,4,RGB(160,209,148));
  270. pDC->SetPixel(m_rc.left+6,4,RGB(77,191,72));
  271. pDC->SetPixel(m_rc.left+7,4,RGB(160,209,148));
  272. pDC->SetPixel(m_rc.left+4,5,RGB(172,222,160));
  273. pDC->SetPixel(m_rc.left+5,5,RGB(85,213,81));
  274. pDC->SetPixel(m_rc.left+6,5,RGB(67,195,63));
  275. pDC->SetPixel(m_rc.left+7,5,RGB(41,168,38));
  276. pDC->SetPixel(m_rc.left+8,5,RGB(172,222,160));
  277. pDC->SetPixel(m_rc.left+4,6,RGB(77,191,72));
  278. pDC->SetPixel(m_rc.left+5,6,RGB(66,195,63));
  279. pDC->SetPixel(m_rc.left+6,6,RGB(56,185,53));
  280. pDC->SetPixel(m_rc.left+7,6,RGB(33,161,33));
  281. pDC->SetPixel(m_rc.left+8,6,RGB(37,149,32));
  282. pDC->SetPixel(m_rc.left+4,7,RGB(172,222,160));
  283. pDC->SetPixel(m_rc.left+5,7,RGB(67,195,63));
  284. pDC->SetPixel(m_rc.left+6,7,RGB(34,162,32));
  285. pDC->SetPixel(m_rc.left+7,7,RGB(34,162,32));
  286. pDC->SetPixel(m_rc.left+8,7,RGB(172,222,160));
  287. pDC->SetPixel(m_rc.left+5,8,RGB(160,209,148));
  288. pDC->SetPixel(m_rc.left+6,8,RGB(35,149,33));
  289. pDC->SetPixel(m_rc.left+7,8,RGB(160,209,148));
  290. }
  291. void CGuiRadioButton::DrawOrange(CDC* pDC,CRect m_rc)
  292. {
  293. pDC->SetPixel(CPoint(6,1),RGB(244,212,140));
  294. pDC->SetPixel(CPoint(3,2),RGB(181,196,207));
  295. pDC->SetPixel(CPoint(4,2),RGB(181,196,207));
  296. pDC->SetPixel(CPoint(5,2),RGB(253,214,132));
  297. pDC->SetPixel(CPoint(6,2),RGB(253,214,132));
  298. pDC->SetPixel(CPoint(7,2),RGB(253,214,132));
  299.     pDC->SetPixel(CPoint(8,2),RGB(253,214,132));
  300. //pDC->SetPixel(CPoint(9,2),RGB(253,214,132));
  301. pDC->SetPixel(CPoint(3,3),RGB(252,220,152));
  302. pDC->SetPixel(CPoint(4,3),RGB(252,220,152));
  303. pDC->SetPixel(CPoint(5,3),RGB(247,227,179));
  304. pDC->SetPixel(CPoint(6,3),RGB(242,237,215));
  305. pDC->SetPixel(CPoint(7,3),RGB(247,227,179));
  306. pDC->SetPixel(CPoint(8,3),RGB(251,200,99));
  307. pDC->SetPixel(CPoint(9,3),RGB(251,200,99));
  308. pDC->SetPixel(CPoint(2,4),RGB(254,223,156));
  309. pDC->SetPixel(CPoint(3,4),RGB(254,220,152));
  310. pDC->SetPixel(CPoint(4,4),RGB(233,236,210));
  311. pDC->SetPixel(CPoint(8,4),RGB(233,236,210));
  312. pDC->SetPixel(CPoint(9,4),RGB(251,200,99));
  313. pDC->SetPixel(CPoint(10,4),RGB(251,200,99));
  314. pDC->SetPixel(CPoint(2,5),RGB(253,217,140));
  315. pDC->SetPixel(CPoint(3,5),RGB(247,227,179));
  316. pDC->SetPixel(CPoint(9,5),RGB(247,227,179));
  317. pDC->SetPixel(CPoint(10,5),RGB(251,200,99));
  318. pDC->SetPixel(CPoint(1,6),RGB(254,223,156));
  319. pDC->SetPixel(CPoint(2,6),RGB(254,220,152));
  320. pDC->SetPixel(CPoint(3,6),RGB(233,236,210));
  321. pDC->SetPixel(CPoint(9,6),RGB(233,236,210));
  322. pDC->SetPixel(CPoint(10,6),RGB(251,200,99));
  323. pDC->SetPixel(CPoint(11,6),RGB(251,200,99));
  324. pDC->SetPixel(CPoint(2,7),RGB(252,211,124));
  325. pDC->SetPixel(CPoint(3,7),RGB(246,224,172));
  326. pDC->SetPixel(CPoint(9,7),RGB(251,200,99));
  327. pDC->SetPixel(CPoint(10,7),RGB(251,200,99));
  328. pDC->SetPixel(CPoint(2,8),RGB(254,223,156));
  329. pDC->SetPixel(CPoint(3,8),RGB(254,220,152));
  330. pDC->SetPixel(CPoint(4,8),RGB(233,236,210));
  331. pDC->SetPixel(CPoint(8,8),RGB(233,236,210));
  332. pDC->SetPixel(CPoint(9,8),RGB(251,200,99));
  333. pDC->SetPixel(CPoint(10,8),RGB(251,200,99));
  334. pDC->SetPixel(CPoint(3,9),RGB(253,217,140));
  335. pDC->SetPixel(CPoint(4,9),RGB(253,217,140));
  336. pDC->SetPixel(CPoint(5,9),RGB(247,227,179));
  337. pDC->SetPixel(CPoint(7,9),RGB(247,227,179));
  338. pDC->SetPixel(CPoint(8,9),RGB(251,200,99));
  339. pDC->SetPixel(CPoint(9,9),RGB(251,200,99));
  340. pDC->SetPixel(CPoint(4,10),RGB(251,200,99));
  341. pDC->SetPixel(CPoint(5,10),RGB(251,200,99));
  342. pDC->SetPixel(CPoint(6,10),RGB(251,200,99));
  343. pDC->SetPixel(CPoint(7,10),RGB(251,200,99));
  344. pDC->SetPixel(CPoint(8,10),RGB(251,200,99));
  345. pDC->SetPixel(CPoint(6,11),RGB(251,200,99));
  346. }
  347. //*******************************************************************
  348. void CGuiRadioButton::UnCheckRadio()
  349. {
  350. CWnd *pParent = GetParent();
  351. ASSERT(pParent);
  352. CWnd *pWnd = pParent->GetNextDlgGroupItem((CWnd *)this);
  353. while (pWnd && (pWnd != this))
  354. {
  355. if ((((CButton*)pWnd)->GetButtonStyle() & BS_AUTORADIOBUTTON) && 
  356. pWnd->IsKindOf( RUNTIME_CLASS( CGuiRadioButton ) ))
  357. {
  358. ((CGuiRadioButton *)pWnd)->SetCheck(0);
  359. pWnd->Invalidate();
  360. }
  361. pWnd = pParent->GetNextDlgGroupItem(pWnd);
  362. }
  363. }
  364. //*******************************************************************
  365. BOOL CGuiRadioButton::PreTranslateMessage(MSG* pMsg) 
  366. {
  367. // TODO: Add your specialized code here and/or call the base class
  368. return CButton::PreTranslateMessage(pMsg);
  369. }
  370. //*******************************************************************
  371. void CGuiRadioButton::PreSubclassWindow() 
  372. {
  373. // TODO: Add your specialized code here and/or call the base class
  374. CButton::PreSubclassWindow();
  375. ModifyStyle(0,BS_OWNERDRAW);
  376. }
  377. BOOL CGuiRadioButton::OnEraseBkgnd(CDC* pDC) 
  378. {
  379. // TODO: Add your message handler code here and/or call default
  380. return FALSE;
  381. }