RTScrollBar.cpp
上传用户:qhonly
上传日期:2013-06-10
资源大小:487k
文件大小:19k
源码类别:

界面编程

开发平台:

Visual C++

  1. // RTScrollBar.cpp : 实现文件
  2. //
  3. #include "stdafx.h"
  4. #include "RTScrollBar.h"
  5. #include "RTDraw.h"
  6. // CRTScrollBar
  7. IMPLEMENT_DYNAMIC(CRTScrollBar, CScrollBar)
  8. CRTScrollBar::CRTScrollBar()
  9. {
  10. m_bMouseDown = FALSE;
  11. m_bMouseDownArrowForback = FALSE;
  12. m_bMouseDownArrowForwad = FALSE;
  13. m_bDragging = FALSE;
  14. m_nThumbStart = 0;
  15. m_dbThumbRemainder = 0.0f;
  16. m_dbThumbInterval = 0.0f;
  17. }
  18. CRTScrollBar::~CRTScrollBar()
  19. {
  20. }
  21. CBitmap* CRTScrollBar::m_ScrollBarUpArrowBitmap[5] = {NULL,NULL,NULL,NULL,NULL};
  22. CBitmap* CRTScrollBar::m_ScrollBarLeftArrowBitmap[5] = {NULL,NULL,NULL,NULL,NULL};
  23. CBitmap* CRTScrollBar::m_ScrollBarDownArrowBitmap[5] = {NULL,NULL,NULL,NULL,NULL};
  24. CBitmap* CRTScrollBar::m_ScrollBarRightArrowBitmap[5] = {NULL,NULL,NULL,NULL,NULL};
  25. UINT     CRTScrollBar::m_ScrollBarUpArrowBitmapDrawMode[5] = {0,0,0,0,0};
  26. UINT     CRTScrollBar::m_ScrollBarLeftArrowBitmapDrawMode[5] = {0,0,0,0,0};
  27. UINT     CRTScrollBar::m_ScrollBarDownArrowBitmapDrawMode[5] = {0,0,0,0,0};
  28. UINT     CRTScrollBar::m_ScrollBarRightArrowBitmapDrawMode[5] = {0,0,0,0,0};
  29. CBitmap* CRTScrollBar::m_ScrollBarHorizontalBitmap[5] = {NULL,NULL,NULL,NULL,NULL};
  30. CBitmap* CRTScrollBar::m_ScrollBarVerticalBitmap[5] = {NULL,NULL,NULL,NULL,NULL};
  31. UINT     CRTScrollBar::m_ScrollBarHorizontalBitmapDrawMode[5] = {0,0,0,0,0};
  32. UINT     CRTScrollBar::m_ScrollBarVerticalBitmapDrawMode[5] = {0,0,0,0,0};
  33. BOOL     CRTScrollBar::m_IsEnableSkin = TRUE;
  34. BEGIN_MESSAGE_MAP(CRTScrollBar, CScrollBar)
  35. ON_WM_PAINT()
  36. ON_WM_LBUTTONDOWN()
  37. ON_WM_LBUTTONUP()
  38. ON_WM_MOUSEMOVE()
  39. ON_WM_TIMER()
  40. ON_WM_ERASEBKGND()
  41. ON_WM_LBUTTONDBLCLK()
  42. END_MESSAGE_MAP()
  43. // CRTScrollBar 消息处理程序
  44. void CRTScrollBar::OnPaint()
  45. {
  46. if(!m_IsEnableSkin)return CScrollBar::OnPaint();
  47. CPaintDC dc(this); 
  48. DWORD style = GetStyle();
  49. if( (style & SBS_VERT) == SBS_VERT)
  50. {
  51. DrawVertical(&dc);
  52. }
  53. else
  54. {
  55. DrawHorizontal(&dc);
  56. }
  57. }
  58. void CRTScrollBar::OnLButtonDown(UINT nFlags, CPoint point)
  59. {
  60. if(!m_IsEnableSkin)return CScrollBar::OnLButtonDown(nFlags, point);
  61. m_MouseDownTime = 0;
  62. SetCapture();
  63. DWORD style = GetStyle();
  64. CWnd *pParent = GetParent();
  65. if((style & SBS_VERT)==SBS_VERT)
  66. {
  67. if(m_ThumbRect.PtInRect(point))
  68. {
  69. m_bMouseDown = true;
  70. m_MouseDownPoint.SetPoint(point.x - m_ThumbRect.left,point.y - m_ThumbRect.top);
  71. CClientDC dc(this);
  72. DrawVertical(&dc);
  73. }
  74. else if(m_BottomArrowRect.PtInRect(point))
  75. {
  76. m_bMouseDownArrowForwad = true;
  77. pParent->SendMessage(WM_VSCROLL,MAKEWPARAM(SB_LINEDOWN,0),(LPARAM)m_hWnd);
  78. CClientDC dc(this);
  79. DrawVertical(&dc);
  80. SetTimer(2,100,NULL);
  81. }
  82. else if(m_TopArrowRect.PtInRect(point))
  83. {
  84. m_bMouseDownArrowForback = true;
  85. pParent->SendMessage(WM_VSCROLL,MAKEWPARAM(SB_LINEUP,0),(LPARAM)m_hWnd);
  86. CClientDC dc(this);
  87. DrawVertical(&dc);
  88. SetTimer(2,100,NULL);
  89. }
  90. else if(m_AreaRect.PtInRect(point))
  91. {
  92. if(pParent != NULL)
  93. {
  94. SCROLLINFO sif;
  95. sif.cbSize = sizeof(sif);
  96. GetScrollInfo(&sif);
  97. if(point.y < m_ThumbRect.top)
  98. {
  99. m_bMouseDownArrowForback = TRUE;
  100. pParent->SendMessage(WM_VSCROLL,MAKEWPARAM(SB_PAGEUP,0),(LPARAM)m_hWnd);
  101. }
  102. else
  103. {
  104. m_bMouseDownArrowForwad = TRUE;
  105. pParent->SendMessage(WM_VSCROLL,MAKEWPARAM(SB_PAGEDOWN,0),(LPARAM)m_hWnd);
  106. }
  107. }
  108. SetTimer(1,100,NULL);
  109. }
  110. }
  111. else
  112. {
  113. if(m_ThumbRect.PtInRect(point))
  114. {
  115. m_bMouseDown = true;
  116. m_MouseDownPoint.SetPoint(point.x - m_ThumbRect.left,point.y - m_ThumbRect.top);
  117. CClientDC dc(this);
  118. DrawHorizontal(&dc);
  119. }
  120. else if(m_RightArrowRect.PtInRect(point))
  121. {
  122. m_bMouseDownArrowForwad = true;
  123. pParent->SendMessage(WM_HSCROLL,MAKEWPARAM(SB_LINERIGHT,0),(LPARAM)m_hWnd);
  124. CClientDC dc(this);
  125. DrawHorizontal(&dc);
  126. SetTimer(2,100,NULL);
  127. }
  128. else if(m_LeftArrowRect.PtInRect(point))
  129. {
  130. m_bMouseDownArrowForback = true;
  131. pParent->SendMessage(WM_HSCROLL,MAKEWPARAM(SB_LINELEFT,0),(LPARAM)m_hWnd);
  132. CClientDC dc(this);
  133. DrawHorizontal(&dc);
  134. SetTimer(2,100,NULL);
  135. }
  136. else if(m_AreaRect.PtInRect(point))
  137. {
  138. if(pParent != NULL)
  139. {
  140. SCROLLINFO sif;
  141. ZeroMemory(&sif,sizeof(sif));
  142. sif.cbSize = sizeof(sif);
  143. GetScrollInfo(&sif,SIF_PAGE|SIF_RANGE|SIF_POS|SIF_TRACKPOS);
  144. if(point.x < m_ThumbRect.left)
  145. {
  146. m_bMouseDownArrowForback = TRUE;
  147. pParent->SendMessage(WM_HSCROLL,MAKEWPARAM(SB_PAGELEFT,0),(LPARAM)m_hWnd);
  148. }
  149. else
  150. {
  151. m_bMouseDownArrowForwad = TRUE;
  152. pParent->SendMessage(WM_HSCROLL,MAKEWPARAM(SB_PAGERIGHT,0),(LPARAM)m_hWnd);
  153. }
  154. }
  155. SetTimer(1,100,NULL);
  156. }
  157. }
  158. }
  159. void CRTScrollBar::OnLButtonUp(UINT nFlags, CPoint point)
  160. {
  161. if(!m_IsEnableSkin)return CScrollBar::OnLButtonUp(nFlags, point);
  162. ReleaseCapture();
  163. DWORD style = GetStyle();
  164. CWnd *pParent = GetParent();
  165. if(m_bDragging)
  166. {
  167. m_bDragging = FALSE;
  168. CPoint mousePoint(m_ThumbRect.left + m_MouseDownPoint.x,m_ThumbRect.top + m_MouseDownPoint.y);
  169. if( (style & SBS_VERT) == SBS_VERT)
  170. {
  171. if(mousePoint.y != point.y)
  172. {
  173. int move = point.y - mousePoint.y;
  174. double pos = m_ThumbRect.top + move - m_AreaRect.top;
  175. double height = m_AreaRect.Height() - m_ThumbRect.Height();
  176. double per = pos / height;
  177. SCROLLINFO sif;
  178. GetScrollInfo(&sif);
  179. int newpos = (int)((sif.nMax - sif.nMin) * per);
  180. if(newpos < sif.nMin)newpos = sif.nMin;
  181. if(newpos > sif.nMax)newpos = sif.nMax;
  182. if(pParent != NULL)
  183. {
  184. pParent->SendMessage(WM_VSCROLL,MAKEWPARAM(SB_THUMBPOSITION,newpos),(LPARAM)m_hWnd);
  185. }
  186. }
  187. }
  188. else
  189. {
  190. if(mousePoint.x == point.x)
  191. {
  192. int move = point.x - mousePoint.x;
  193. double pos = m_ThumbRect.left + move - m_AreaRect.left;
  194. double width = m_AreaRect.Width() - m_ThumbRect.Width();
  195. double per = pos / width;
  196. SCROLLINFO sif;
  197. GetScrollInfo(&sif);
  198. int newpos = (int)((sif.nMax - sif.nMin) * per);
  199. if(newpos < sif.nMin)newpos = sif.nMin;
  200. if(newpos > sif.nMax)newpos = sif.nMax;
  201. if(pParent != NULL)
  202. {
  203. pParent->SendMessage(WM_HSCROLL,MAKEWPARAM(SB_THUMBPOSITION,newpos),(LPARAM)m_hWnd);
  204. }
  205. }
  206. }
  207. }
  208. if(m_bMouseDown || m_bMouseDownArrowForback || m_bMouseDownArrowForwad)
  209. {
  210. m_bMouseDown = FALSE;
  211. m_bMouseDownArrowForback = FALSE;
  212. m_bMouseDownArrowForwad = FALSE;
  213.         KillTimer(2);
  214. KillTimer(1);
  215. CClientDC dc(this);
  216. if((style & SBS_VERT) == SBS_VERT)
  217. DrawVertical(&dc);
  218. else
  219. DrawHorizontal(&dc);
  220. }
  221. }
  222. void CRTScrollBar::OnMouseMove(UINT nFlags, CPoint point)
  223. {
  224. if(!m_IsEnableSkin)return CScrollBar::OnMouseMove(nFlags, point);
  225.     
  226. CWnd *pParent = GetParent();
  227. if(pParent == NULL)return;
  228. if(m_bMouseDown)m_bDragging = TRUE;
  229. if(!m_bDragging)return;
  230. CPoint mousePoint(m_ThumbRect.left + m_MouseDownPoint.x,m_ThumbRect.top + m_MouseDownPoint.y);
  231. DWORD style = GetStyle();
  232. if( (style & SBS_VERT) == SBS_VERT)
  233. {
  234. if(mousePoint.y == point.y)return;
  235. int move = point.y - mousePoint.y;
  236. double pos = m_ThumbRect.top + move - m_AreaRect.top;
  237. double height = m_AreaRect.Height() - m_ThumbRect.Height();
  238. double per = pos / height;
  239. SCROLLINFO sif;
  240. GetScrollInfo(&sif);
  241. int newpos = (int)((sif.nMax - sif.nMin) * per);
  242. if(newpos < sif.nMin) newpos = sif.nMin;
  243. if(newpos > sif.nMax) newpos = sif.nMax;
  244. sif.nTrackPos = newpos;
  245. if(m_nThumbTrackPos != newpos)
  246. {
  247. m_nThumbTrackPos = newpos;
  248. CClientDC dc(this);
  249. DrawVertical(&dc);
  250. pParent->SendMessage(WM_VSCROLL,MAKEWPARAM(SB_THUMBTRACK,sif.nTrackPos),(LPARAM)m_hWnd);
  251. }
  252. }
  253. else
  254. {
  255. if(mousePoint.x == point.x)return;
  256. int move = point.x - mousePoint.x;
  257. double pos = m_ThumbRect.left + move - m_AreaRect.left;
  258. double width = m_AreaRect.Width() - m_ThumbRect.Width();
  259. double per = pos / width;
  260. SCROLLINFO sif;
  261. GetScrollInfo(&sif);
  262. int newpos = (int)((sif.nMax - sif.nMin) * per);
  263. if(newpos < sif.nMin) newpos = sif.nMin;
  264. if(newpos > sif.nMax) newpos = sif.nMax;
  265. sif.nTrackPos = newpos;
  266. if(m_nThumbTrackPos != newpos)
  267. {
  268. m_nThumbTrackPos = newpos;
  269. CClientDC dc(this);
  270. DrawHorizontal(&dc);
  271. pParent->SendMessage(WM_HSCROLL,MAKEWPARAM(SB_THUMBTRACK,sif.nTrackPos),(LPARAM)m_hWnd);
  272. }
  273. }
  274. }
  275. void CRTScrollBar::OnTimer(UINT nIDEvent)
  276. {
  277. if(!m_IsEnableSkin)return CScrollBar::OnTimer(nIDEvent);
  278. if(m_MouseDownTime < 3)
  279. {
  280. m_MouseDownTime++;
  281. return;
  282. }
  283. CWnd* pParent = GetParent();
  284. DWORD style = GetStyle();
  285. SCROLLINFO sif;
  286. GetScrollInfo(&sif);
  287. if( (style & SBS_VERT) == SBS_VERT)
  288. {
  289. if(nIDEvent == 2)
  290. {
  291. if(m_bMouseDownArrowForback)
  292. {
  293. pParent->SendMessage(WM_VSCROLL,MAKEWPARAM(SB_LINEUP,0),(LPARAM)m_hWnd);
  294. }
  295. else if(m_bMouseDownArrowForwad)
  296. {
  297. pParent->SendMessage(WM_VSCROLL,MAKEWPARAM(SB_LINEDOWN,0),(LPARAM)m_hWnd);
  298. }
  299. }
  300. else if(nIDEvent == 1)
  301. {
  302. CPoint point;
  303. GetCursorPos(&point);
  304. ScreenToClient(&point);
  305. if(!m_ThumbRect.PtInRect(point))
  306. {
  307. if(m_bMouseDownArrowForback)
  308. {
  309. pParent->SendMessage(WM_VSCROLL,MAKEWPARAM(SB_PAGEUP,0),(LPARAM)m_hWnd);
  310. }
  311. else if(m_bMouseDownArrowForwad)
  312. {
  313. pParent->SendMessage(WM_VSCROLL,MAKEWPARAM(SB_PAGEDOWN,0),(LPARAM)m_hWnd);
  314. }
  315. }
  316. }
  317. }
  318. else
  319. {
  320. if(nIDEvent == 2)
  321. {
  322. if(m_bMouseDownArrowForback)
  323. {
  324. pParent->SendMessage(WM_HSCROLL,MAKEWPARAM(SB_LINELEFT,0),(LPARAM)m_hWnd);
  325. }
  326. else if(m_bMouseDownArrowForwad)
  327. {
  328. pParent->SendMessage(WM_HSCROLL,MAKEWPARAM(SB_LINERIGHT,0),(LPARAM)m_hWnd);
  329. }
  330. }
  331. else if(nIDEvent == 1)
  332. {
  333. CPoint point;
  334. GetCursorPos(&point);
  335. ScreenToClient(&point);
  336. if(!m_ThumbRect.PtInRect(point))
  337. {
  338. if(m_bMouseDownArrowForback)
  339. {
  340. pParent->SendMessage(WM_HSCROLL,MAKEWPARAM(SB_PAGELEFT,0),(LPARAM)m_hWnd);
  341. }
  342. else if(m_bMouseDownArrowForwad)
  343. {
  344. pParent->SendMessage(WM_HSCROLL,MAKEWPARAM(SB_PAGERIGHT,0),(LPARAM)m_hWnd);
  345. }
  346. }
  347. }
  348. }
  349. }
  350. void CRTScrollBar::DrawHorizontal(CDC *pDC)
  351. {
  352. CRect clientRect;
  353. GetClientRect(&clientRect);
  354. CMemDC memDC(pDC, &clientRect);
  355. BOOL IsWindowEnable = IsWindowEnabled();
  356. //draw left arrow of scrollbar
  357. m_LeftArrowRect.SetRect(clientRect.left,clientRect.top,clientRect.left + clientRect.Height(),clientRect.bottom);
  358. if(m_SizeArea == AreaLeft)
  359. {
  360. CRTDraw::RTDrawBitmap(&memDC,&m_LeftArrowRect,m_ScrollBarHorizontalBitmap[BMP_BACK],m_ScrollBarHorizontalBitmapDrawMode[BMP_BACK]);
  361. m_LeftArrowRect.OffsetRect(clientRect.Height() + 1,0);
  362. }
  363. if(!IsWindowEnable)
  364. CRTDraw::RTDrawBitmap(&memDC,&m_LeftArrowRect,m_ScrollBarLeftArrowBitmap[BMP_DISABLE],m_ScrollBarLeftArrowBitmapDrawMode[BMP_DISABLE]);
  365. else
  366. {
  367. if(m_bMouseDownArrowForback)
  368. CRTDraw::RTDrawBitmap(&memDC,&m_LeftArrowRect,m_ScrollBarLeftArrowBitmap[BMP_DOWN],m_ScrollBarLeftArrowBitmapDrawMode[BMP_DOWN]);
  369. else
  370. CRTDraw::RTDrawBitmap(&memDC,&m_LeftArrowRect,m_ScrollBarLeftArrowBitmap[BMP_NORMAL],m_ScrollBarLeftArrowBitmapDrawMode[BMP_NORMAL]);
  371. }
  372. //draw right arrow
  373. m_RightArrowRect.SetRect(clientRect.right - clientRect.Height(),clientRect.top,clientRect.right,clientRect.bottom);
  374. if(m_SizeArea == AreaRight)
  375. {
  376. CRTDraw::RTDrawBitmap(&memDC,&m_RightArrowRect,m_ScrollBarHorizontalBitmap[BMP_BACK],m_ScrollBarHorizontalBitmapDrawMode[BMP_BACK]);
  377. m_RightArrowRect.OffsetRect(0-clientRect.Height()  - 1,0);
  378. }
  379. if(!IsWindowEnable)
  380. CRTDraw::RTDrawBitmap(&memDC,&m_RightArrowRect,m_ScrollBarRightArrowBitmap[BMP_DISABLE],m_ScrollBarRightArrowBitmapDrawMode[BMP_DISABLE]);
  381. else
  382. {
  383. if(m_bMouseDownArrowForwad)
  384. CRTDraw::RTDrawBitmap(&memDC,&m_RightArrowRect,m_ScrollBarRightArrowBitmap[BMP_DOWN],m_ScrollBarRightArrowBitmapDrawMode[BMP_DOWN]);
  385. else
  386. CRTDraw::RTDrawBitmap(&memDC,&m_RightArrowRect,m_ScrollBarRightArrowBitmap[BMP_NORMAL],m_ScrollBarRightArrowBitmapDrawMode[BMP_NORMAL]);
  387. }
  388. //draw back
  389. m_AreaRect.SetRect(m_LeftArrowRect.right + 1,clientRect.top,m_RightArrowRect.left - 1,clientRect.bottom);
  390. CRTDraw::RTDrawBitmap(&memDC,&m_AreaRect,m_ScrollBarHorizontalBitmap[BMP_BACK],m_ScrollBarHorizontalBitmapDrawMode[BMP_BACK]);
  391. SCROLLINFO sif;
  392. GetScrollInfo(&sif);
  393. if(m_bDragging)sif.nPos = m_nThumbTrackPos;
  394. int ThumbWidth = 30;
  395. if(ThumbWidth > m_AreaRect.Width())ThumbWidth = m_AreaRect.Width() / 2;
  396. double width = m_AreaRect.Width() - ThumbWidth;
  397. double range = sif.nMax - sif.nMin;
  398. double per = width / range;
  399. int pos = (int)(per * (sif.nPos - sif.nMin));
  400. if(range <= 0)return;
  401. m_ThumbRect.left =  m_AreaRect.left + pos;
  402. m_ThumbRect.top = clientRect.top;
  403. m_ThumbRect.right = m_ThumbRect.left + ThumbWidth;
  404. m_ThumbRect.bottom = clientRect.bottom;
  405. if(m_ThumbRect.right == m_ThumbRect.left)m_ThumbRect.right = m_ThumbRect.left + 3;
  406. if(!IsWindowEnable)
  407. CRTDraw::RTDrawBitmap(&memDC,&m_ThumbRect,m_ScrollBarHorizontalBitmap[BMP_DISABLE],m_ScrollBarHorizontalBitmapDrawMode[BMP_DISABLE]);
  408. else
  409. {
  410. if(m_bDragging)
  411. CRTDraw::RTDrawBitmap(&memDC,&m_ThumbRect,m_ScrollBarHorizontalBitmap[BMP_DOWN],m_ScrollBarHorizontalBitmapDrawMode[BMP_DOWN]);
  412. else
  413. CRTDraw::RTDrawBitmap(&memDC,&m_ThumbRect,m_ScrollBarHorizontalBitmap[BMP_NORMAL],m_ScrollBarHorizontalBitmapDrawMode[BMP_NORMAL]);
  414. }
  415. }
  416. void CRTScrollBar::DrawVertical(CDC* pDC)
  417. {
  418. CRect clientRect;
  419. GetClientRect(&clientRect);
  420. CMemDC memDC(pDC, &clientRect);
  421. BOOL IsWindowEnable = IsWindowEnabled();
  422. //draw up arrow of scrollbar
  423. m_TopArrowRect.SetRect(clientRect.left,clientRect.top,clientRect.right,clientRect.top + clientRect.Width());
  424. if(m_SizeArea == AreaTop)
  425. {
  426. CRTDraw::RTDrawBitmap(&memDC,&m_TopArrowRect,m_ScrollBarVerticalBitmap[BMP_BACK],m_ScrollBarVerticalBitmapDrawMode[BMP_BACK]);
  427. m_TopArrowRect.OffsetRect(0,clientRect.Width() + 1);
  428. }
  429. if(!IsWindowEnable)
  430. CRTDraw::RTDrawBitmap(&memDC,&m_TopArrowRect,m_ScrollBarUpArrowBitmap[BMP_DISABLE],m_ScrollBarUpArrowBitmapDrawMode[BMP_DISABLE]);
  431. else
  432. {
  433. if(m_bMouseDownArrowForback)
  434. CRTDraw::RTDrawBitmap(&memDC,&m_TopArrowRect,m_ScrollBarUpArrowBitmap[BMP_DOWN],m_ScrollBarUpArrowBitmapDrawMode[BMP_DOWN]);
  435. else
  436. CRTDraw::RTDrawBitmap(&memDC,&m_TopArrowRect,m_ScrollBarUpArrowBitmap[BMP_NORMAL],m_ScrollBarUpArrowBitmapDrawMode[BMP_NORMAL]);
  437. }
  438. //draw right arrow
  439. m_BottomArrowRect.SetRect(clientRect.left,clientRect.bottom - clientRect.Width(),clientRect.right,clientRect.bottom);
  440. if(m_SizeArea == AreaBottom)
  441. {
  442. CRTDraw::RTDrawBitmap(&memDC,&m_BottomArrowRect,m_ScrollBarVerticalBitmap[BMP_BACK],m_ScrollBarVerticalBitmapDrawMode[BMP_BACK]);
  443. m_BottomArrowRect.OffsetRect(0,0-clientRect.Width() + 1);
  444. }
  445. if(!IsWindowEnable)
  446. CRTDraw::RTDrawBitmap(&memDC,&m_BottomArrowRect,m_ScrollBarDownArrowBitmap[BMP_DISABLE],m_ScrollBarDownArrowBitmapDrawMode[BMP_DISABLE]);
  447. else
  448. {
  449. if(m_bMouseDownArrowForwad)
  450. CRTDraw::RTDrawBitmap(&memDC,&m_BottomArrowRect,m_ScrollBarDownArrowBitmap[BMP_DOWN],m_ScrollBarDownArrowBitmapDrawMode[BMP_DOWN]);
  451. else
  452. CRTDraw::RTDrawBitmap(&memDC,&m_BottomArrowRect,m_ScrollBarDownArrowBitmap[BMP_NORMAL],m_ScrollBarDownArrowBitmapDrawMode[BMP_NORMAL]);
  453. }
  454. //draw back
  455. m_AreaRect.SetRect(clientRect.left,m_TopArrowRect.bottom + 1,clientRect.right,m_BottomArrowRect.top - 1);
  456. CRTDraw::RTDrawBitmap(&memDC,&m_AreaRect,m_ScrollBarVerticalBitmap[BMP_BACK],m_ScrollBarVerticalBitmapDrawMode[BMP_BACK]);
  457. SCROLLINFO sif;
  458. GetScrollInfo(&sif);
  459. if(m_bDragging)sif.nPos = m_nThumbTrackPos;
  460. int ThumbWidth = 30;
  461. if(ThumbWidth > m_AreaRect.Height())ThumbWidth = m_AreaRect.Height()/2;
  462. double height = m_AreaRect.Height() - ThumbWidth;
  463. double range = sif.nMax - sif.nMin;
  464. double per = height / range;
  465. int pos = (int)(per * (sif.nPos - sif.nMin));
  466. if( range <= 0)return;
  467. m_ThumbRect.left = clientRect.left;
  468. m_ThumbRect.top = m_AreaRect.top + pos;
  469. m_ThumbRect.right = clientRect.right;
  470. m_ThumbRect.bottom = m_ThumbRect.top + ThumbWidth;
  471. if(!IsWindowEnable)
  472. CRTDraw::RTDrawBitmap(&memDC,&m_ThumbRect,m_ScrollBarVerticalBitmap[BMP_DISABLE],m_ScrollBarVerticalBitmapDrawMode[BMP_DISABLE]);
  473. else
  474. {
  475. if(m_bDragging)
  476. CRTDraw::RTDrawBitmap(&memDC,&m_ThumbRect,m_ScrollBarVerticalBitmap[BMP_DOWN],m_ScrollBarVerticalBitmapDrawMode[BMP_DOWN]);
  477. else
  478. CRTDraw::RTDrawBitmap(&memDC,&m_ThumbRect,m_ScrollBarVerticalBitmap[BMP_NORMAL],m_ScrollBarVerticalBitmapDrawMode[BMP_NORMAL]);
  479. }
  480. }
  481. void CRTScrollBar::EnableSkin(BOOL IsEnable)
  482. {
  483. m_IsEnableSkin = IsEnable;
  484. }
  485. void CRTScrollBar::SetHorizontalBitmap(CBitmap* pHorizontal[],UINT DrawMode[])
  486. {
  487. for(int i = 0; i < 5; i ++)
  488. {
  489. m_ScrollBarHorizontalBitmap[i] = pHorizontal[i];
  490. m_ScrollBarHorizontalBitmapDrawMode[i] = DrawMode[i];
  491. }
  492. }
  493. void CRTScrollBar::SetVerticalBitmap(CBitmap* pVertical[],UINT DrawMode[])
  494. {
  495. for(int i = 0; i < 5; i ++)
  496. {
  497. m_ScrollBarVerticalBitmap[i] = pVertical[i];
  498. m_ScrollBarVerticalBitmapDrawMode[i] = DrawMode[i];
  499. }
  500. }
  501. void CRTScrollBar::SetVerticalUpArrowBitmap(CBitmap* pVertical[],UINT DrawMode[])
  502. {
  503. for(int i = 0; i < 5; i ++)
  504. {
  505. m_ScrollBarUpArrowBitmap[i] = pVertical[i];
  506. m_ScrollBarUpArrowBitmapDrawMode[i] = DrawMode[i];
  507. }
  508. }
  509. void CRTScrollBar::SetVerticalDownArrowBitmap(CBitmap* pVertical[],UINT DrawMode[])
  510. {
  511. for(int i = 0; i < 5; i ++)
  512. {
  513. m_ScrollBarDownArrowBitmap[i] = pVertical[i];
  514. m_ScrollBarDownArrowBitmapDrawMode[i] = DrawMode[i];
  515. }
  516. }
  517. void CRTScrollBar::SetHorizontalLeftArrowBitmap(CBitmap* pHorizontal[],UINT DrawMode[])
  518. {
  519. for(int i = 0; i < 5; i ++)
  520. {
  521. m_ScrollBarLeftArrowBitmap[i] = pHorizontal[i];
  522. m_ScrollBarLeftArrowBitmapDrawMode[i] = DrawMode[i];
  523. }
  524. }
  525. void CRTScrollBar::SetHorizontalRightArrowBitmap(CBitmap* pHorizontal[],UINT DrawMode[])
  526. {
  527. for(int i = 0; i < 5; i ++)
  528. {
  529. m_ScrollBarRightArrowBitmap[i] = pHorizontal[i];
  530. m_ScrollBarRightArrowBitmapDrawMode[i] = DrawMode[i];
  531. }
  532. }
  533. BOOL CRTScrollBar::OnEraseBkgnd(CDC* pDC)
  534. {
  535. if(!m_IsEnableSkin)
  536. return CScrollBar::OnEraseBkgnd(pDC);
  537. else
  538. return FALSE;
  539. }
  540. void CRTScrollBar::SetSizeArea(ScrollBarSizeArea Area)
  541. {
  542. m_SizeArea = Area;
  543. if(IsWindow(m_hWnd))Invalidate();
  544. }
  545. void CRTScrollBar::OnLButtonDblClk(UINT nFlags, CPoint point)
  546. {
  547. if(!m_IsEnableSkin)return CScrollBar::OnLButtonDblClk(nFlags, point);
  548. OnLButtonDown(nFlags,point);
  549. OnLButtonUp(nFlags,point);
  550. }
  551. void CRTScrollBar::SetRange(int nmin, int nmax,BOOL bRedraw)
  552. {
  553. int nMax,nMin;
  554. GetScrollRange(&nMin,&nMax);
  555. if(nmin != nMax || nmax != nMax)
  556. {
  557. if(m_IsEnableSkin)
  558. {
  559. SetScrollRange(nmin,nmax,FALSE);
  560. RedrawWindow();
  561. }
  562. else
  563. {
  564. SetScrollRange(nmin,nmax,bRedraw);
  565. }
  566. }
  567. }
  568. void CRTScrollBar::SetPos(int pos, BOOL redraw)
  569. {
  570. int nPos = GetScrollPos();
  571. if(pos == nPos)return;
  572. if(!m_IsEnableSkin)
  573. {
  574. SetScrollPos(pos,redraw);
  575. }
  576. else
  577. {
  578. SetScrollPos(pos,FALSE);
  579. RedrawWindow();
  580. }
  581. }