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

对话框与窗口

开发平台:

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