ScrollXP.cpp 39 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227
  1. // ListXP.cpp: implementation of the CListXP class.
  2. //
  3. //////////////////////////////////////////////////////////////////////
  4. /**************以下设置必需包含在每个子类中**********************/
  5. //头部
  6. ////////////////////////////////////////////////////////////////////////////////////////////////////
  7. // 编译预处理
  8. #if _WIN32_WINNT < 0x0400
  9. #define _WIN32_WINNT 0x0400
  10. #endif
  11. // 强制使用 C 语言方式编译
  12. #ifdef __cplusplus
  13. extern "C"
  14. {
  15. #endif // __cplusplus
  16. #include "ScrollXP.h"
  17. //////////////////////////////////////////////////////////////////////////////////////////////////
  18. // 全局变量
  19. extern HHOOK g_hPrevHookXP ; // 窗口消息 HOOK 句柄
  20. extern PCLASSXP g_pClassXP ; // 窗口的 CLASSXP 结构指针
  21. extern COLORREF g_crDialogbkColor; // 窗口背景颜色
  22. //#define AREATOP 1
  23. //#define AREABOTTOM 2
  24. //#define AREALEFT 1
  25. //#define AREARIGHT 2
  26. //#define AREANONE 0
  27. #define SCROLLAREA 0 //滚动条区域
  28. #define SCROLLTOPARROW 1 //上箭头
  29. #define SCROLLBOTTOMARROW 2 //下箭头
  30. #define SCROLLLEFTARROW 3 //左箭头
  31. #define SCROLLRIGHTARROW 4 //右箭头
  32. #define SCROLLTHUMB 5 //移动块
  33. #define SCROLLAREANULL 6 //滚动条空区域
  34. #define SCROLLALL 7 //所有区域
  35. /*static COLORREF gScrolls_crGradientXP[][4] =
  36. {
  37. {0x00FFE7CE, 0x00FFE7CE, 0x00EE8269, 0xFFEE8269},
  38. {0x00C1CCD1, 0x00C1CCD1, 0x00EEF1F2, 0xFFEEF1F2},
  39. {0x00FFE7CE, 0x00EE8269, 0x00FFE7CE, 0xFFEE8269},
  40. {0x00C1CCD1, 0x00EEF1F2, 0x00C1CCD1, 0xFFEEF1F2},
  41. {0x00FFFFFF, 0x00FFFFFF, 0x00D6DFE2, 0xFFD6DFE2},
  42. };
  43. */
  44. /**************以下设置必需包含在每个子类中**********************/
  45. //////////////////////////////////////////////////////////////
  46. ////////////////////////////////////////////////////////////////////////////////////////////////////
  47. // 绘制 Thumb 块
  48. VOID WINAPI ScrollDrowThumbXP(HDC hDC, RECT Rect, LONG lState)
  49. {
  50. int i;
  51. // RECT Rect;
  52. HANDLE hHandle;
  53. static COLORREF s_crGradientXP[][4] =
  54. {
  55. {0x00EFF3F7, 0x00DEE7E7, 0x00DEE3E7, 0x00DEE3E7},
  56. {0x00DEAEA5, 0x00F7CBBD, 0x00DE8273, 0x00F7C7B5},
  57. {0x00EFC7B5, 0x00E7AE94, 0x00DEA284, 0x00DEA68C},
  58. {0x00FFE3D6, 0x00F7CBBD, 0x00F7C3AD, 0x00F7C7B5},
  59. {0x00F7F7F7, 0x00EFF3F7, 0x00EFF3F7, 0x00EFF3F7},
  60. {0x00DEC3BD, 0x00DEB6AD, 0x00FFE3DE, 0x00F7E3DE},
  61. {0x00EFDBCE, 0x00EFCFC6, 0x00E7CFC6, 0x00E7CBBD},
  62. {0x00FFEFE7, 0x00FFE7DE, 0x00FFE3DE, 0x00F7E3DE},
  63. {0x00F7F7F7, 0x00E7EFEF, 0x00E7EBEF, 0x00DEE7E7},
  64. {0x00F78E6B, 0x00F79684, 0x00EF9E8C, 0x00EFDFD6},
  65. {0x00FFFFFF, 0x00FFE3CE, 0x00FFDFC6, 0x00FFDBBD},
  66. {0x00FFEBE7, 0x00FFCFBD, 0x00FFCBB5, 0x00F7CBAD},
  67. {0x00EFF3F7, 0x00DEE7E7, 0x00EFF3F7, 0x00DEE3E7},//水平滚条
  68. {0x00DEAEA5, 0x00F7CBBD, 0x00DEAEA5, 0x00F7C7B5},
  69. {0x00EFC7B5, 0x00E7AE94, 0x00EFC7B5, 0x00DEA68C},
  70. {0x00FFE3D6, 0x00F7CBBD, 0x00FFE3D6, 0x00F7C7B5},
  71. {0x00DEE7E7, 0x00DEE7E7, 0x00DEE3E7, 0x00DEE3E7},//垂直滚条
  72. {0x00F7CBBD, 0x00F7CBBD, 0x00DE8273, 0x00F7C7B5},
  73. {0x00EFC7B5, 0x00EFC7B5, 0x00E7AE94, 0x00DEA68C},
  74. {0x00F7CBBD, 0x00F7CBBD, 0x00F7C3AD, 0x00F7C7B5},
  75. };
  76. // CopyRect(&Rect, pRect);
  77. if (lState & CXPH_HASFRAME) //画外框阴影
  78. {
  79. //InflateRect(&Rect, -1, -1);
  80. //Rect.top--;
  81. Rect.right--;Rect.bottom--;
  82. FrameRect(hDC, &Rect, (HBRUSH )GetStockObject(WHITE_BRUSH));
  83. hHandle = (HANDLE) SelectObject(hDC,
  84. CreatePen(PS_SOLID, 1, (lState & CXPS_DISABLED) ? 0x00BDCFCE : 0x00D6B69C));
  85. MoveToEx(hDC, Rect.right, Rect.top + 2, NULL);
  86. LineTo(hDC, Rect.right, Rect.bottom - 2);
  87. LineTo(hDC, Rect.right - 2, Rect.bottom);
  88. LineTo(hDC, Rect.left + 1, Rect.bottom);
  89. LineTo(hDC, Rect.left - 1, Rect.bottom - 2);
  90. DeleteObject(SelectObject(hDC, (HGDIOBJ) hHandle));
  91. InflateRect(&Rect, -1, -1);
  92. }
  93. // 绘制 Thumb 外框
  94. if (lState & CXPS_DISABLED)
  95. i = 0;
  96. else if (lState & CXPS_PRESSED)
  97. i = 1;
  98. else if (lState & CXPS_HOTLIGHT)
  99. i = 2;
  100. else
  101. i = 3;
  102. if(lState & CXPH_AREA) //只绘滚条内区
  103. {
  104. i += 12;
  105. if(lState & CXPS_HORIZON)
  106. {i += 4;
  107. GradientRectXP(hDC, &Rect, s_crGradientXP[i]);
  108. //InflateRect(&Rect, -1, -1);
  109. //GradientRectXP(hDC, &Rect, s_crGradientXP[i + 8]);
  110. }
  111. else
  112. {
  113. GradientRectXP(hDC, &Rect, s_crGradientXP[i]);
  114. }
  115. return;
  116. }
  117. else //画按钮
  118. {
  119. GradientRectXP(hDC, &Rect, s_crGradientXP[i]);
  120. // 绘制下拉外框拐角像素
  121. SetPixel(hDC, Rect.left, Rect.top, s_crGradientXP[i + 4][0]);
  122. SetPixel(hDC, Rect.right - 1, Rect.top, s_crGradientXP[i + 4][1]);
  123. SetPixel(hDC, Rect.left, Rect.bottom - 1, s_crGradientXP[i + 4][2]);
  124. SetPixel(hDC, Rect.right - 1, Rect.bottom - 1, s_crGradientXP[i + 4][3]);
  125. // 绘制 Thumb 内框
  126. InflateRect(&Rect, -1, -1);
  127. GradientRectXP(hDC, &Rect, s_crGradientXP[i + 8]);
  128. }
  129. // 绘制 Thumb 标志
  130. Rect.left += (Rect.right - Rect.left) / 2;
  131. Rect.top += (Rect.bottom - Rect.top) / 2;
  132. if (lState & CXPH_DROPHANDLE)
  133. {
  134. hHandle = (HANDLE) SelectObject(hDC, CreatePen(PS_SOLID, 1, 0x00FFF7EF));
  135. for (i = -4; i <= 2; i += 2)
  136. {
  137. if (lState & CXPS_HORIZON)
  138. {
  139. MoveToEx(hDC, Rect.left + i, Rect.top - 3, NULL);
  140. LineTo(hDC, Rect.left + i, Rect.top + 3);
  141. }
  142. else
  143. {
  144. MoveToEx(hDC, Rect.left - 3, Rect.top + i, NULL);
  145. LineTo(hDC, Rect.left + 3, Rect.top + i);
  146. }
  147. }
  148. DeleteObject(SelectObject(hDC, (HGDIOBJ) hHandle));
  149. hHandle = (HANDLE) SelectObject(hDC, CreatePen(PS_SOLID, 1, 0x00FFB28C));
  150. for (i = -3; i <= 3; i += 2)
  151. {
  152. if (lState & CXPS_HORIZON)
  153. {
  154. MoveToEx(hDC, Rect.left + i, Rect.top - 2, NULL);
  155. LineTo(hDC, Rect.left + i, Rect.top + 4);
  156. }
  157. else
  158. {
  159. MoveToEx(hDC, Rect.left - 2, Rect.top + i, NULL);
  160. LineTo(hDC, Rect.left + 4, Rect.top + i);
  161. }
  162. }
  163. DeleteObject(SelectObject(hDC, (HGDIOBJ) hHandle));
  164. }
  165. else
  166. {
  167. hHandle = (HANDLE) SelectObject(hDC,
  168. CreatePen(PS_SOLID, 1, (lState & CXPS_DISABLED) ? 0x00C6CBCE : 0x0084614A));
  169. if (lState & CXPH_SMALLARROW)
  170. {
  171. if (lState & CXPH_LEFTWARDS)
  172. {
  173. MoveToEx(hDC, Rect.left - 2, Rect.top, NULL);
  174. LineTo(hDC, Rect.left - 2, Rect.top + 1);
  175. MoveToEx(hDC, Rect.left - 1, Rect.top - 1, NULL);
  176. LineTo(hDC, Rect.left - 1, Rect.top + 2);
  177. MoveToEx(hDC, Rect.left, Rect.top - 2, NULL);
  178. LineTo(hDC, Rect.left, Rect.top + 3);
  179. MoveToEx(hDC, Rect.left + 1, Rect.top - 3, NULL);
  180. LineTo(hDC, Rect.left + 1, Rect.top);
  181. MoveToEx(hDC, Rect.left + 1, Rect.top + 1, NULL);
  182. LineTo(hDC, Rect.left + 1, Rect.top + 4);
  183. }
  184. else if (lState & CXPH_UPWARDS)
  185. {
  186. MoveToEx(hDC, Rect.left - 3, Rect.top + 1, NULL);
  187. LineTo(hDC, Rect.left, Rect.top + 1);
  188. MoveToEx(hDC, Rect.left + 1, Rect.top + 1, NULL);
  189. LineTo(hDC, Rect.left + 4, Rect.top + 1);
  190. MoveToEx(hDC, Rect.left - 2, Rect.top, NULL);
  191. LineTo(hDC, Rect.left + 3, Rect.top);
  192. MoveToEx(hDC, Rect.left - 1, Rect.top - 1, NULL);
  193. LineTo(hDC, Rect.left + 2, Rect.top - 1);
  194. MoveToEx(hDC, Rect.left, Rect.top - 2, NULL);
  195. LineTo(hDC, Rect.left + 1, Rect.top - 2);
  196. }
  197. else if (lState & CXPH_RIGHTWARDS)
  198. {
  199. MoveToEx(hDC, Rect.left + 2, Rect.top, NULL);
  200. LineTo(hDC, Rect.left + 2, Rect.top + 1);
  201. MoveToEx(hDC, Rect.left + 1, Rect.top - 1, NULL);
  202. LineTo(hDC, Rect.left + 1, Rect.top + 2);
  203. MoveToEx(hDC, Rect.left, Rect.top - 2, NULL);
  204. LineTo(hDC, Rect.left, Rect.top + 3);
  205. MoveToEx(hDC, Rect.left - 1, Rect.top - 3, NULL);
  206. LineTo(hDC, Rect.left - 1, Rect.top);
  207. MoveToEx(hDC, Rect.left - 1, Rect.top + 1, NULL);
  208. LineTo(hDC, Rect.left - 1, Rect.top + 4);
  209. }
  210. else if (lState & CXPH_DOWNWARDS)
  211. {
  212. MoveToEx(hDC, Rect.left - 3, Rect.top - 1, NULL);
  213. LineTo(hDC, Rect.left, Rect.top - 1);
  214. MoveToEx(hDC, Rect.left + 1, Rect.top - 1, NULL);
  215. LineTo(hDC, Rect.left + 4, Rect.top - 1);
  216. MoveToEx(hDC, Rect.left - 2, Rect.top, NULL);
  217. LineTo(hDC, Rect.left + 3, Rect.top);
  218. MoveToEx(hDC, Rect.left - 1, Rect.top + 1, NULL);
  219. LineTo(hDC, Rect.left + 2, Rect.top + 1);
  220. MoveToEx(hDC, Rect.left, Rect.top + 2, NULL);
  221. LineTo(hDC, Rect.left + 1, Rect.top + 2);
  222. }
  223. }
  224. else if (lState & CXPH_LARGEARROW)
  225. {
  226. if (lState & CXPH_LEFTWARDS)
  227. {
  228. MoveToEx(hDC, Rect.left + 1, Rect.top - 4, NULL);
  229. LineTo(hDC, Rect.left - 3, Rect.top);
  230. LineTo(hDC, Rect.left + 2, Rect.top + 5);
  231. MoveToEx(hDC, Rect.left + 1, Rect.top - 3, NULL);
  232. LineTo(hDC, Rect.left - 2, Rect.top);
  233. LineTo(hDC, Rect.left + 2, Rect.top + 4);
  234. MoveToEx(hDC, Rect.left + 2, Rect.top - 3, NULL);
  235. LineTo(hDC, Rect.left - 1, Rect.top);
  236. LineTo(hDC, Rect.left + 3, Rect.top + 4);
  237. }
  238. else if (lState & CXPH_UPWARDS)
  239. {
  240. MoveToEx(hDC, Rect.left - 4, Rect.top + 1, NULL);
  241. LineTo(hDC, Rect.left, Rect.top - 3);
  242. LineTo(hDC, Rect.left + 5, Rect.top + 2);
  243. MoveToEx(hDC, Rect.left - 3, Rect.top + 1, NULL);
  244. LineTo(hDC, Rect.left, Rect.top - 2);
  245. LineTo(hDC, Rect.left + 4, Rect.top + 2);
  246. MoveToEx(hDC, Rect.left - 3, Rect.top + 2, NULL);
  247. LineTo(hDC, Rect.left, Rect.top - 1);
  248. LineTo(hDC, Rect.left + 4, Rect.top + 3);
  249. }
  250. else if (lState & CXPH_RIGHTWARDS)
  251. {
  252. MoveToEx(hDC, Rect.left - 1, Rect.top - 4, NULL);
  253. LineTo(hDC, Rect.left + 3, Rect.top);
  254. LineTo(hDC, Rect.left - 2, Rect.top + 5);
  255. MoveToEx(hDC, Rect.left - 1, Rect.top - 3, NULL);
  256. LineTo(hDC, Rect.left + 2, Rect.top);
  257. LineTo(hDC, Rect.left - 2, Rect.top + 4);
  258. MoveToEx(hDC, Rect.left - 2, Rect.top - 3, NULL);
  259. LineTo(hDC, Rect.left + 1, Rect.top);
  260. LineTo(hDC, Rect.left - 3, Rect.top + 4);
  261. }
  262. else if (lState & CXPH_DOWNWARDS)
  263. {
  264. MoveToEx(hDC, Rect.left - 4, Rect.top - 2, NULL);
  265. LineTo(hDC, Rect.left, Rect.top + 2);
  266. LineTo(hDC, Rect.left + 5, Rect.top - 3);
  267. MoveToEx(hDC, Rect.left - 3, Rect.top - 2, NULL);
  268. LineTo(hDC, Rect.left, Rect.top + 1);
  269. LineTo(hDC, Rect.left + 4, Rect.top - 3);
  270. MoveToEx(hDC, Rect.left - 3, Rect.top - 3, NULL);
  271. LineTo(hDC, Rect.left, Rect.top);
  272. LineTo(hDC, Rect.left + 4, Rect.top - 4);
  273. }
  274. }
  275. DeleteObject(SelectObject(hDC, (HGDIOBJ) hHandle));
  276. }
  277. }
  278. //画按钮
  279. void ScrollDrawButton(PCLASSXP pCxp, HDC hDC, RECT Rect,
  280. DWORD dwStyle, int nType)
  281. {
  282. /*
  283. FrameRect FrameRect 画一个矩形框
  284. Lineto Lineto 画线到
  285. Moveto Moveto 移 到
  286. Pie Pie 画扇形
  287. Polygon Polygon 画多边形
  288. PolyLine PolyLine 画多根相连的线
  289. Rectangle Rectangle 画一个实心矩形
  290. RoundRect RoundRect 画一个圆角的矩形
  291. {0x00CEF3FF, 0x0063CBFF, 0x0063CBFF, 0x0031B2FF},
  292. */
  293. PSCROLLXP pXP;
  294. pXP = (PSCROLLXP)pCxp->pData;
  295. // HANDLE hPen, hBrush;
  296. // RECT rt;
  297. // POINT szPoint[3];
  298. // COLORREF crColor ;
  299. /* if(dwStyle == SBS_HORZ && pXP->m_bMouseDown)
  300. GradientRectXP(hDC, &Rect, gScrolls_crGradientXP[0]);
  301. else if(dwStyle == SBS_HORZ && !pXP->m_bMouseDown)
  302. GradientRectXP(hDC, &Rect, gScrolls_crGradientXP[1]);
  303. else if(dwStyle == SBS_VERT && pXP->m_bMouseDown)
  304. GradientRectXP(hDC, &Rect, gScrolls_crGradientXP[2]);
  305. else
  306. GradientRectXP(hDC, &Rect, gScrolls_crGradientXP[3]);
  307. */
  308. /* if(dwStyle == SBS_HORZ)
  309. GradientRectXP(hDC, &Rect, gScrolls_crGradientXP[1]);
  310. else
  311. GradientRectXP(hDC, &Rect, gScrolls_crGradientXP[3]);
  312. if(nType != SCROLLAREANULL)//无边框
  313. {
  314. hBrush = SelectObject(hDC, GetStockObject(NULL_BRUSH));
  315. RoundRect(hDC, Rect.left, Rect.top,
  316. Rect.right , Rect.bottom , 4,4);
  317. SelectObject(hDC, hBrush);
  318. }
  319. int nWidth = (Rect.right - Rect.left)/2;
  320. int nHeight = (Rect.bottom - Rect.top)/2;
  321. if(pXP->m_bMouseDownArrowForwad ||
  322. pXP->m_bMouseDownArrowForback)
  323. crColor = RGB(123,12,123);
  324. else
  325. crColor = RGB(0,0,0);
  326. switch (nType)
  327. {
  328. case SCROLLLEFTARROW: //左箭头
  329. hBrush = SelectObject(hDC, CreateSolidBrush(crColor));
  330. hPen = SelectObject(hDC, CreatePen(1,1,crColor));
  331. szPoint[0].x = Rect.left + 6; szPoint[0].y = Rect.top + nHeight;
  332. szPoint[1].x = szPoint[0].x + 3; szPoint[1].y = szPoint[0].y - 3;
  333. szPoint[2].x = szPoint[0].x + 3; szPoint[2].y = szPoint[0].y + 3;
  334. Polygon(hDC, szPoint, 3);
  335. DeleteObject(SelectObject(hDC, hBrush));
  336. DeleteObject(SelectObject(hDC, hPen));
  337. break;
  338. case SCROLLRIGHTARROW://右箭头
  339. hBrush = SelectObject(hDC, CreateSolidBrush(crColor));
  340. hPen = SelectObject(hDC, CreatePen(1,1,crColor));
  341. szPoint[0].x = Rect.right - 6; szPoint[0].y = Rect.top + nHeight;
  342. szPoint[1].x = szPoint[0].x - 3; szPoint[1].y = szPoint[0].y - 3;
  343. szPoint[2].x = szPoint[0].x - 3; szPoint[2].y = szPoint[0].y + 3;
  344. Polygon(hDC, szPoint, 3);
  345. DeleteObject(SelectObject(hDC, hBrush));
  346. DeleteObject(SelectObject(hDC, hPen));
  347. break;
  348. case SCROLLTOPARROW://上箭头
  349. hBrush = SelectObject(hDC, CreateSolidBrush(crColor));
  350. hPen = SelectObject(hDC, CreatePen(1,1,crColor));
  351. szPoint[0].x = Rect.left + nWidth; szPoint[0].y = Rect.top + 5;
  352. szPoint[1].x = szPoint[0].x - 3; szPoint[1].y = szPoint[0].y + 3;
  353. szPoint[2].x = szPoint[0].x + 3; szPoint[2].y = szPoint[0].y + 3;
  354. Polygon(hDC, szPoint, 3);
  355. DeleteObject(SelectObject(hDC, hBrush));
  356. DeleteObject(SelectObject(hDC, hPen));
  357. break;
  358. case SCROLLBOTTOMARROW://下箭头
  359. hBrush = SelectObject(hDC, CreateSolidBrush(crColor));
  360. hPen = SelectObject(hDC, CreatePen(1,1,crColor));
  361. szPoint[0].x = Rect.left + nWidth; szPoint[0].y = Rect.bottom - 7;
  362. szPoint[1].x = szPoint[0].x - 3; szPoint[1].y = szPoint[0].y - 3;
  363. szPoint[2].x = szPoint[0].x + 3; szPoint[2].y = szPoint[0].y - 3;
  364. Polygon(hDC, szPoint, 3);
  365. DeleteObject(SelectObject(hDC, hBrush));
  366. DeleteObject(SelectObject(hDC, hPen));
  367. break;
  368. case SCROLLAREA://活动区域
  369. break;
  370. case SCROLLTHUMB://移动块
  371. if (pXP->m_bDragging)
  372. hBrush = CreateSolidBrush(0x00CEF3FF);
  373. else
  374. hBrush = CreateSolidBrush(RGB(0,155,0));
  375. rt = Rect;
  376. if (dwStyle & SBS_VERT) //垂直
  377. { //上下两个边
  378. //hBrush = CreateSolidBrush(RGB(213,155,36));
  379. rt.left = Rect.left + 1; rt.top = Rect.top + 1;
  380. rt.right = Rect.right - 1; rt.bottom = Rect.top + nHeight/2;
  381. FillRect(hDC, &rt, (HBRUSH)hBrush);
  382. rt.left = Rect.left + 1; rt.top = Rect.bottom - nHeight/2;
  383. rt.right = Rect.right - 1; rt.bottom = Rect.bottom - 1;
  384. FillRect(hDC, &rt, (HBRUSH)hBrush);
  385. DeleteObject(hBrush);
  386. }
  387. else
  388. {//左右两个边
  389. //hBrush = CreateSolidBrush(RGB(213,155,36));
  390. rt.left = Rect.left + 1; rt.top = Rect.top + 1;
  391. rt.right = Rect.left + nWidth/2; rt.bottom = Rect.bottom - 1;
  392. FillRect(hDC, &rt, (HBRUSH)hBrush);
  393. rt.left = Rect.right - nWidth/2; rt.top = Rect.top + 1;
  394. rt.right = Rect.right - 1; rt.bottom = Rect.bottom - 1;
  395. FillRect(hDC, &rt, (HBRUSH)hBrush);
  396. DeleteObject(hBrush);
  397. }
  398. pXP->m_ThumbRectOld = pXP->m_ThumbRect;
  399. break;
  400. }
  401. // FillRect(hDC,&Rect,(HBRUSH)hHandle);
  402. */
  403. }
  404. //计算移动块大小
  405. void ScrollCalVertical(PCLASSXP pCxp, SCROLLINFO sif, RECT Rect)
  406. {
  407. PSCROLLXP pXP;
  408. pXP = (PSCROLLXP)pCxp->pData;
  409. if(pXP->m_bDragging)sif.nPos = pXP->m_nThumbTrackPos;
  410. int ThumbWidth = 30;
  411. if(ThumbWidth > pXP->m_AreaRect.bottom - pXP->m_AreaRect.top)
  412. ThumbWidth = (pXP->m_AreaRect.bottom - pXP->m_AreaRect.top)/2;
  413. double height = pXP->m_AreaRect.bottom - pXP->m_AreaRect.top - ThumbWidth;
  414. double range = sif.nMax - sif.nMin;
  415. double per = height / range;
  416. int pos = (int)(per * (sif.nPos - sif.nMin));
  417. if( range <= 0)
  418. return;
  419. pXP->m_ThumbRect.left = Rect.left;
  420. pXP->m_ThumbRect.top = pXP->m_AreaRect.top + pos;
  421. pXP->m_ThumbRect.right = Rect.right;
  422. pXP->m_ThumbRect.bottom = pXP->m_ThumbRect.top + ThumbWidth;
  423. InflateRect(&pXP->m_ThumbRect, -2, -1);
  424. }
  425. //画垂直动条
  426. void ScrollDrawVertical(PCLASSXP pCxp, long nType)
  427. {
  428. BOOL IsWindowEnable;
  429. RECT Rect;//, NewRect;
  430. HWND hWnd;
  431. PSCROLLXP pXP;
  432. HDC hDC;
  433. long lState;
  434. pXP = (PSCROLLXP)pCxp->pData;
  435. hWnd = pCxp->hWnd;
  436. GetWindowRect(hWnd, &Rect);
  437. Rect.right -= Rect.left;
  438. Rect.bottom -= Rect.top;
  439. Rect.left = Rect.top = 0;
  440. long lSmall = 0;
  441. IsWindowEnable = IsWindowEnabled(hWnd);
  442. //有效判断
  443. SCROLLINFO sif;
  444. ZeroMemory(&sif, sizeof(SCROLLINFO));
  445. sif.cbSize = sizeof(SCROLLINFO);
  446. sif.fMask = SIF_ALL;
  447. if(!GetScrollInfo(hWnd, SB_CTL, &sif))
  448. return;
  449. if(sif.nMin == sif.nMax)
  450. return;
  451. MEMDCXP Mdcxp;
  452. Mdcxp.hWnd = hWnd;
  453. Mdcxp.bTransfer = FALSE;
  454. Mdcxp.hBitmap = NULL;
  455. GetMemDCXP(&Mdcxp);
  456. hDC = Mdcxp.hDC;
  457. //小箭头
  458. if (Rect.bottom-Rect.left < 2*(Rect.right-Rect.left))
  459. lSmall = CXPH_SMALLARROW;
  460. //上箭头
  461. pXP->m_TopArrowRect = Rect;
  462. pXP->m_TopArrowRect.bottom = Rect.top+Rect.right-Rect.left;
  463. if (nType == SCROLLTOPARROW || nType == SCROLLALL)
  464. { if(pXP->m_bMouseDownArrowForback)
  465. ScrollDrowThumbXP(hDC, pXP->m_TopArrowRect, CXPH_LARGEARROW|CXPH_UPWARDS|CXPS_PRESSED|lSmall);
  466. else
  467. ScrollDrowThumbXP(hDC, pXP->m_TopArrowRect, CXPH_LARGEARROW|CXPH_UPWARDS|lSmall);
  468. }
  469. //下箭头
  470. pXP->m_BottomArrowRect = Rect;
  471. pXP->m_BottomArrowRect.top = Rect.bottom-(Rect.right-Rect.left);
  472. if (nType == SCROLLBOTTOMARROW || nType == SCROLLALL)
  473. { if(pXP->m_bMouseDownArrowForwad)
  474. ScrollDrowThumbXP(hDC, pXP->m_BottomArrowRect, CXPH_LARGEARROW|CXPH_DOWNWARDS|CXPS_PRESSED|lSmall);
  475. else
  476. ScrollDrowThumbXP(hDC, pXP->m_BottomArrowRect, CXPH_LARGEARROW|CXPH_DOWNWARDS|lSmall);
  477. }
  478. //空区域
  479. pXP->m_AreaRect = Rect;
  480. pXP->m_AreaRect.top = pXP->m_TopArrowRect.bottom;//+1;
  481. pXP->m_AreaRect.bottom = pXP->m_BottomArrowRect.top;// - 1;
  482. if (nType == SCROLLALL)
  483. ScrollDrowThumbXP(hDC, pXP->m_AreaRect, CXPH_HASFRAME|CXPH_AREA);
  484. else
  485. ScrollDrowThumbXP(hDC, pXP->m_ThumbRect, CXPH_AREA);
  486. //移动块
  487. ScrollCalVertical(pCxp,sif, Rect);
  488. lState = CXPH_LARGEARROW|CXPH_DROPHANDLE|CXPS_HOTLIGHT;
  489. if (pXP->m_bMouseDown)
  490. lState |= CXPS_PRESSED;
  491. if(!lSmall)
  492. ScrollDrowThumbXP(hDC, pXP->m_ThumbRect, lState);
  493. ReleaseMemDCXP(&Mdcxp);
  494. }
  495. //计算移动块大小
  496. void ScrollCalHorizontal(PCLASSXP pCxp, SCROLLINFO sif, RECT Rect)
  497. {
  498. PSCROLLXP pXP;
  499. pXP = (PSCROLLXP)pCxp->pData;
  500. if(pXP->m_bDragging)sif.nPos = pXP->m_nThumbTrackPos;
  501. int ThumbWidth = 30;
  502. if(ThumbWidth > (pXP->m_AreaRect.right-pXP->m_AreaRect.left))
  503. ThumbWidth = (pXP->m_AreaRect.right-pXP->m_AreaRect.left)/ 2;
  504. double width = (pXP->m_AreaRect.right-pXP->m_AreaRect.left) - ThumbWidth;
  505. double range = sif.nMax - sif.nMin;
  506. double per = width / range;
  507. int pos = (int)(per * (sif.nPos - sif.nMin));
  508. if(range <= 0)return;
  509. pXP->m_ThumbRect.left = pXP->m_AreaRect.left + pos;
  510. pXP->m_ThumbRect.top = Rect.top;
  511. pXP->m_ThumbRect.right = pXP->m_ThumbRect.left + ThumbWidth;
  512. pXP->m_ThumbRect.bottom = Rect.bottom;
  513. if(pXP->m_ThumbRect.right == pXP->m_ThumbRect.left)
  514. pXP->m_ThumbRect.right = pXP->m_ThumbRect.left + 3;
  515. InflateRect(&pXP->m_ThumbRect, -1, -3);
  516. }
  517. //画水平滚动条
  518. void ScrollDrawHorizontal(PCLASSXP pCxp, long nType)
  519. {
  520. BOOL IsWindowEnable;
  521. RECT Rect;
  522. HWND hWnd;
  523. PSCROLLXP pXP;
  524. HDC hDC;
  525. long lState;
  526. pXP = (PSCROLLXP)pCxp->pData;
  527. hWnd = pCxp->hWnd;
  528. GetWindowRect(hWnd, &Rect);
  529. Rect.right -= Rect.left;
  530. Rect.bottom -= Rect.top;
  531. Rect.left = Rect.top = 0;
  532. IsWindowEnable = IsWindowEnabled(hWnd);
  533. //有效判断
  534. SCROLLINFO sif;
  535. ZeroMemory(&sif, sizeof(SCROLLINFO));
  536. sif.cbSize = sizeof(SCROLLINFO);
  537. sif.fMask = SIF_ALL;
  538. if(!GetScrollInfo(hWnd, SB_CTL, &sif))
  539. return;
  540. if(sif.nMin == sif.nMax)
  541. return;
  542. MEMDCXP Mdcxp;
  543. Mdcxp.hWnd = hWnd;
  544. Mdcxp.bTransfer = FALSE;
  545. Mdcxp.hBitmap = NULL;
  546. GetMemDCXP(&Mdcxp);
  547. hDC = Mdcxp.hDC;
  548. //左箭头
  549. pXP->m_LeftArrowRect = Rect;
  550. pXP->m_LeftArrowRect.right = Rect.left+Rect.bottom-Rect.top;
  551. // if (nType == SCROLLLEFTARROW || nType == SCROLLALL)
  552. // ScrollDrawButton(pCxp,hDC,pXP->m_LeftArrowRect, SBS_HORZ,SCROLLLEFTARROW);
  553. if (nType == SCROLLLEFTARROW || nType == SCROLLALL)
  554. { if(pXP->m_bMouseDownArrowForback)
  555. ScrollDrowThumbXP(hDC, pXP->m_LeftArrowRect, CXPH_LARGEARROW|CXPH_LEFTWARDS|CXPS_PRESSED);
  556. else
  557. ScrollDrowThumbXP(hDC, pXP->m_LeftArrowRect, CXPH_LARGEARROW|CXPH_LEFTWARDS);
  558. }
  559. //右箭头
  560. pXP->m_RightArrowRect = Rect;
  561. pXP->m_RightArrowRect.left = Rect.right-(Rect.bottom-Rect.top);
  562. // if (nType == SCROLLRIGHTARROW || nType == SCROLLALL)
  563. // ScrollDrawButton(pCxp,hDC,pXP->m_RightArrowRect, SBS_HORZ,SCROLLRIGHTARROW);
  564. if (nType == SCROLLRIGHTARROW || nType == SCROLLALL)
  565. { if(pXP->m_bMouseDownArrowForwad)
  566. ScrollDrowThumbXP(hDC, pXP->m_RightArrowRect, CXPH_LARGEARROW|CXPH_RIGHTWARDS|CXPS_PRESSED);
  567. else
  568. ScrollDrowThumbXP(hDC, pXP->m_RightArrowRect, CXPH_LARGEARROW|CXPH_RIGHTWARDS);
  569. }
  570. //空区域
  571. pXP->m_AreaRect = Rect;
  572. pXP->m_AreaRect.left = pXP->m_LeftArrowRect.right;//+1;
  573. pXP->m_AreaRect.right = pXP->m_RightArrowRect.left;// - 1;
  574. // if (nType == SCROLLALL)
  575. // ScrollDrawButton(pCxp,hDC,pXP->m_AreaRect, SBS_HORZ,SCROLLAREA);
  576. // else
  577. // ScrollDrawButton(pCxp,hDC,pXP->m_ThumbRect, SBS_HORZ,SCROLLAREANULL);
  578. if (nType == SCROLLALL)
  579. ScrollDrowThumbXP(hDC, pXP->m_AreaRect, CXPS_HORIZON|CXPH_HASFRAME|CXPH_AREA);
  580. else
  581. ScrollDrowThumbXP(hDC, pXP->m_ThumbRect,CXPS_HORIZON|CXPH_AREA);
  582. //移动块
  583. ScrollCalHorizontal(pCxp,sif, Rect);
  584. // ScrollDrawButton(pCxp,hDC,pXP->m_ThumbRect,SBS_HORZ, SCROLLTHUMB);
  585. lState = CXPS_HOTLIGHT|CXPH_DROPHANDLE|CXPS_HORIZON;
  586. if (pXP->m_bMouseDown)
  587. lState |= CXPS_PRESSED;
  588. ScrollDrowThumbXP(hDC, pXP->m_ThumbRect, lState);
  589. /* if(!IsWindowEnable)
  590. CRTDraw::RTDrawBitmap(&memDC,&m_ThumbRect,m_ScrollBarHorizontalBitmap[BMP_DISABLE],m_ScrollBarHorizontalBitmapDrawMode[BMP_DISABLE]);
  591. else
  592. {
  593. if(m_bDragging)
  594. CRTDraw::RTDrawBitmap(&memDC,&m_ThumbRect,m_ScrollBarHorizontalBitmap[BMP_DOWN],m_ScrollBarHorizontalBitmapDrawMode[BMP_DOWN]);
  595. else
  596. CRTDraw::RTDrawBitmap(&memDC,&m_ThumbRect,m_ScrollBarHorizontalBitmap[BMP_NORMAL],m_ScrollBarHorizontalBitmapDrawMode[BMP_NORMAL]);
  597. }
  598. */
  599. ReleaseMemDCXP(&Mdcxp);
  600. }
  601. //压下左键
  602. void ScrollOnLButtonDown(PCLASSXP pCxp,WPARAM wParam,LPARAM lParam)
  603. //UINT nFlags, CPoint point
  604. {
  605. SCROLLINFO sif;
  606. POINT point;
  607. PSCROLLXP pXP;
  608. HWND hWnd, hParent;
  609. HDC hDC;
  610. DWORD dwStyle;
  611. pXP = (PSCROLLXP)pCxp->pData;
  612. // pXP->m_MouseDownTime = 0;
  613. hWnd = pCxp->hWnd;
  614. point.x = LOWORD(lParam);
  615. point.y = HIWORD(lParam);
  616. SetCapture(hWnd);
  617. // DWORD style = GetStyle();
  618. dwStyle = (DWORD)GetWindowLong(pCxp->hWnd, GWL_STYLE);
  619. hParent = GetParent(hWnd);
  620. if((dwStyle & SBS_VERT)==SBS_VERT)
  621. {
  622. if(PtInRect(&pXP->m_ThumbRect,point))
  623. {
  624. pXP->m_bMouseDown = true;
  625. pXP->m_MouseDownPoint.x = point.x - pXP->m_ThumbRect.left;
  626. pXP->m_MouseDownPoint.y = point.y - pXP->m_ThumbRect.top;
  627. hDC = GetDC(pCxp->hWnd); //强制刷亮移动块
  628. //pXP->m_bDragging = true;
  629. //ScrollDrawButton(pCxp,hDC,pXP->m_ThumbRect,SBS_VERT, SCROLLTHUMB);
  630. ScrollDrowThumbXP(hDC, pXP->m_ThumbRect,
  631. CXPH_LARGEARROW|CXPH_DROPHANDLE|CXPS_PRESSED);
  632. //pXP->m_bDragging = false;
  633. //ScrollDrawVertical(pCxp, SCROLLALL);
  634. ReleaseDC(hWnd,hDC);
  635. }
  636. else if(PtInRect(&pXP->m_BottomArrowRect,point))
  637. {
  638. // SetTimer(hWnd,2,100,NULL);
  639. pXP->m_bMouseDownArrowForwad = true;
  640. //hDC = GetDC(pCxp->hWnd);
  641. //ReleaseDC(hWnd,hDC);
  642. SendMessage(hWnd,WM_SETREDRAW,FALSE,0);
  643. SendMessage(hParent,WM_VSCROLL,MAKEWPARAM(SB_LINEDOWN,0),(LPARAM)hWnd);
  644. SendMessage(hWnd,WM_SETREDRAW,TRUE,0);
  645. ScrollDrawVertical(pCxp, SCROLLBOTTOMARROW);
  646. //CClientDC dc(this);
  647. //DrawVertical(&dc);
  648. }
  649. else if(PtInRect(&pXP->m_TopArrowRect,point))
  650. {
  651. // SetTimer(hWnd,2,100,NULL);
  652. pXP->m_bMouseDownArrowForback = true;
  653. //hDC = GetDC(pCxp->hWnd);
  654. //ReleaseDC(hWnd,hDC);
  655. SendMessage(hWnd,WM_SETREDRAW,FALSE,0);
  656. SendMessage(hParent,WM_VSCROLL,MAKEWPARAM(SB_LINEUP,0),(LPARAM)hWnd);
  657. SendMessage(hWnd,WM_SETREDRAW,TRUE,0);
  658. ScrollDrawVertical(pCxp, SCROLLTOPARROW);
  659. //CClientDC dc(this);
  660. //DrawVertical(&dc);
  661. //SetTimer(2,100,NULL);
  662. }
  663. else if(PtInRect(&pXP->m_AreaRect,point))
  664. {
  665. if(hParent != NULL)
  666. {
  667. ZeroMemory(&sif,sizeof(sif));
  668. sif.cbSize = sizeof(sif);
  669. sif.fMask = SIF_ALL;
  670. // GetScrollInfo(hWnd,SB_VERT, &sif);
  671. GetScrollInfo(hWnd, SB_CTL, &sif);
  672. if(point.y < pXP->m_ThumbRect.top)
  673. {
  674. pXP->m_bMouseDownArrowForback = TRUE;
  675. SendMessage(hWnd,WM_SETREDRAW,FALSE,0);
  676. SendMessage(hParent,WM_VSCROLL,MAKEWPARAM(SB_PAGEUP,0),(LPARAM)hWnd);
  677. SendMessage(hWnd,WM_SETREDRAW,TRUE,0);
  678. ScrollDrawVertical(pCxp, SCROLLAREANULL);
  679. }
  680. else
  681. {
  682. pXP->m_bMouseDownArrowForwad = TRUE;
  683. SendMessage(hWnd,WM_SETREDRAW,FALSE,0);
  684. SendMessage(hParent,WM_VSCROLL,MAKEWPARAM(SB_PAGEDOWN,0),(LPARAM)hWnd);
  685. SendMessage(hWnd,WM_SETREDRAW,TRUE,0);
  686. ScrollDrawVertical(pCxp, SCROLLAREANULL);
  687. }
  688. }
  689. // SetTimer(hWnd,1,100,NULL);
  690. //SetTimer(1,100,NULL);
  691. }
  692. }
  693. else
  694. {
  695. if(PtInRect(&pXP->m_ThumbRect,point))
  696. {
  697. pXP->m_bMouseDown = true;
  698. pXP->m_MouseDownPoint.x = point.x - pXP->m_ThumbRect.left;
  699. pXP->m_MouseDownPoint.y = point.y - pXP->m_ThumbRect.top;
  700. pXP->m_bDragging = true;
  701. hDC = GetDC(pCxp->hWnd); //强制刷亮移动块
  702. // pXP->m_bDragging = true;
  703. // ScrollDrawButton(pCxp,hDC,pXP->m_ThumbRect,SBS_HORZ, SCROLLTHUMB);
  704. // pXP->m_bDragging = false;
  705. ScrollDrowThumbXP(hDC, pXP->m_ThumbRect, CXPS_HORIZON|
  706. CXPH_LARGEARROW|CXPH_DROPHANDLE|CXPS_PRESSED);
  707. ReleaseDC(hWnd,hDC);
  708. }
  709. else if(PtInRect(&pXP->m_RightArrowRect,point))
  710. {
  711. pXP->m_bMouseDownArrowForwad = true;
  712. SendMessage(hWnd,WM_SETREDRAW,FALSE,0);
  713. SendMessage(hParent,WM_HSCROLL,MAKEWPARAM(SB_LINERIGHT,0),(LPARAM)hWnd);
  714. SendMessage(hWnd,WM_SETREDRAW,TRUE,0);
  715. // CClientDC dc(this);
  716. // DrawHorizontal(&dc);
  717. // hDC = GetDC(hWnd);
  718. ScrollDrawHorizontal(pCxp, SCROLLRIGHTARROW);
  719. // ReleaseDC(hWnd,hDC);
  720. // SetTimer(hWnd,2,100,NULL);
  721. //SetTimer(2,100,NULL);
  722. }
  723. else if(PtInRect(&pXP->m_LeftArrowRect,point))
  724. {
  725. pXP->m_bMouseDownArrowForback = true;
  726. SendMessage(hWnd,WM_SETREDRAW,FALSE,0);
  727. SendMessage(hParent,WM_HSCROLL,MAKEWPARAM(SB_LINELEFT,0),(LPARAM)hWnd);
  728. SendMessage(hWnd,WM_SETREDRAW,TRUE,0);
  729. // CClientDC dc(this);
  730. // DrawHorizontal(&dc);
  731. // hDC = GetDC(hWnd);
  732. ScrollDrawHorizontal(pCxp, SCROLLLEFTARROW);
  733. // ReleaseDC(hWnd,hDC);
  734. // SetTimer(hWnd,2,100,NULL);
  735. }
  736. else if(PtInRect(&pXP->m_AreaRect,point))
  737. {
  738. if(hParent != NULL)
  739. {
  740. ZeroMemory(&sif,sizeof(sif));
  741. sif.cbSize = sizeof(sif);
  742. sif.fMask = SIF_ALL;
  743. // GetScrollInfo(&sif,SIF_PAGE|SIF_RANGE|SIF_POS|SIF_TRACKPOS);
  744. GetScrollInfo(hWnd, SB_CTL, &sif);
  745. if(point.x < pXP->m_ThumbRect.left)
  746. {
  747. pXP->m_bMouseDownArrowForback = TRUE;
  748. SendMessage(hWnd,WM_SETREDRAW,FALSE,0);
  749. SendMessage(hParent,WM_HSCROLL,MAKEWPARAM(SB_PAGELEFT,0),(LPARAM)hWnd);
  750. SendMessage(hWnd,WM_SETREDRAW,TRUE,0);
  751. ScrollDrawHorizontal(pCxp, SCROLLAREANULL);
  752. }
  753. else
  754. {
  755. pXP->m_bMouseDownArrowForwad = TRUE;
  756. SendMessage(hWnd,WM_SETREDRAW,FALSE,0);
  757. SendMessage(hParent,WM_HSCROLL,MAKEWPARAM(SB_PAGERIGHT,0),(LPARAM)hWnd);
  758. SendMessage(hWnd,WM_SETREDRAW,TRUE,0);
  759. ScrollDrawHorizontal(pCxp, SCROLLAREANULL);
  760. }
  761. }
  762. // SetTimer(hWnd,1,100,NULL);
  763. }
  764. }
  765. }
  766. ////////////////////////////////////////////////////////////
  767. //松开左键
  768. void ScrollOnLButtonUp(PCLASSXP pCxp,WPARAM wParam,LPARAM lParam)
  769. //UINT nFlags, CPoint point
  770. {
  771. POINT point, mousePoint;
  772. PSCROLLXP pXP;
  773. HWND hWnd, hParent;
  774. HDC hDC;
  775. DWORD dwStyle;
  776. SCROLLINFO sif;
  777. pXP = (PSCROLLXP)pCxp->pData;
  778. pXP->m_MouseDownTime = 0;
  779. hWnd = pCxp->hWnd;
  780. point.x = LOWORD(lParam);
  781. point.y = HIWORD(lParam);
  782. ReleaseCapture();
  783. // DWORD style = GetStyle();
  784. // CWnd *pParent = GetParent();
  785. dwStyle = (DWORD)GetWindowLong(pCxp->hWnd, GWL_STYLE);
  786. hParent = GetParent(hWnd);
  787. if(pXP->m_bDragging)
  788. {
  789. pXP->m_bDragging = FALSE;
  790. pXP->m_bMouseDown = FALSE;
  791. mousePoint.x = pXP->m_ThumbRect.left + pXP->m_MouseDownPoint.x;
  792. mousePoint.y= pXP->m_ThumbRect.top + pXP->m_MouseDownPoint.y;
  793. if( (dwStyle & SBS_VERT) == SBS_VERT)
  794. {
  795. if(mousePoint.y != point.y)
  796. {
  797. int move = point.y - mousePoint.y;
  798. double pos = pXP->m_ThumbRect.top + move - pXP->m_AreaRect.top;
  799. double height = (pXP->m_AreaRect.bottom-pXP->m_AreaRect.top) -
  800. (pXP->m_ThumbRect.bottom-pXP->m_ThumbRect.top);
  801. double per = pos / height;
  802. //GetScrollInfo(&sif);
  803. ZeroMemory(&sif,sizeof(sif));
  804. sif.cbSize = sizeof(SCROLLINFO);
  805. sif.fMask = SIF_ALL;
  806. GetScrollInfo(hWnd, SB_CTL, &sif);
  807. int newpos = (int)((sif.nMax - sif.nMin) * per);
  808. if(newpos < sif.nMin)newpos = sif.nMin;
  809. if(newpos > sif.nMax)newpos = sif.nMax;
  810. if(hParent != NULL)
  811. {
  812. SendMessage(hWnd,WM_SETREDRAW,FALSE,0);
  813. SendMessage(hParent,WM_VSCROLL,MAKEWPARAM(SB_THUMBPOSITION,newpos),(LPARAM)hWnd);
  814. SendMessage(hWnd,WM_SETREDRAW,TRUE,0);
  815. }
  816. // ScrollDrawVertical(pCxp, SCROLLAREANULL);
  817. }
  818. ScrollDrawVertical(pCxp, SCROLLALL);
  819. }
  820. else
  821. {
  822. if(mousePoint.x != point.x)
  823. {
  824. int move = point.x - mousePoint.x;
  825. double pos = pXP->m_ThumbRect.left + move - pXP->m_AreaRect.left;
  826. double width = (pXP->m_AreaRect.right-pXP->m_AreaRect.left) -
  827. (pXP->m_ThumbRect.right-pXP->m_ThumbRect.left);
  828. double per = pos / width;
  829. ZeroMemory(&sif,sizeof(sif));
  830. sif.cbSize = sizeof(SCROLLINFO);
  831. // GetScrollInfo(&sif);
  832. sif.fMask = SIF_ALL;
  833. GetScrollInfo(hWnd, SB_CTL, &sif);
  834. int newpos = (int)((sif.nMax - sif.nMin) * per);
  835. if(newpos < sif.nMin)newpos = sif.nMin;
  836. if(newpos > sif.nMax)newpos = sif.nMax;
  837. if(hParent != NULL)
  838. {
  839. SendMessage(hWnd,WM_SETREDRAW,FALSE,0);
  840. SendMessage(hParent,WM_HSCROLL,MAKEWPARAM(SB_THUMBPOSITION,newpos),(LPARAM)hWnd);
  841. SendMessage(hWnd,WM_SETREDRAW,TRUE,0);
  842. }
  843. }
  844. ScrollDrawHorizontal(pCxp, SCROLLALL);
  845. }
  846. }
  847. else if (pXP->m_bMouseDown) //移动块
  848. {
  849. hDC = GetDC(pCxp->hWnd);
  850. pXP->m_bMouseDown = false;
  851. if ((dwStyle & SBS_VERT) == SBS_VERT) //
  852. ScrollDrowThumbXP(hDC, pXP->m_ThumbRect,CXPS_HOTLIGHT|CXPH_DROPHANDLE);
  853. else
  854. ScrollDrowThumbXP(hDC, pXP->m_ThumbRect,CXPS_HOTLIGHT|CXPH_DROPHANDLE|CXPS_HORIZON);
  855. ReleaseDC(hWnd,hDC);
  856. }
  857. else if (pXP->m_bMouseDownArrowForback&&
  858. (dwStyle & SBS_VERT) == SBS_VERT) //上键
  859. {
  860. hDC = GetDC(pCxp->hWnd);
  861. pXP->m_bMouseDownArrowForback = false;
  862. ScrollDrowThumbXP(hDC, pXP->m_TopArrowRect, CXPH_LARGEARROW|CXPH_UPWARDS);
  863. ReleaseDC(hWnd,hDC);
  864. }
  865. else if (pXP->m_bMouseDownArrowForwad &&
  866. (dwStyle & SBS_VERT) == SBS_VERT) //下键
  867. {
  868. hDC = GetDC(pCxp->hWnd);
  869. pXP->m_bMouseDownArrowForwad = false;
  870. ScrollDrowThumbXP(hDC, pXP->m_BottomArrowRect, CXPH_LARGEARROW|CXPH_DOWNWARDS);
  871. ReleaseDC(hWnd,hDC);
  872. // ScrollDrawHorizontal(pCxp, SCROLLRIGHTARROW);
  873. }
  874. else if (pXP->m_bMouseDownArrowForback&&
  875. (dwStyle & SBS_HORZ) == SBS_HORZ) //左键
  876. {
  877. hDC = GetDC(pCxp->hWnd);
  878. pXP->m_bMouseDownArrowForback = false;
  879. ScrollDrowThumbXP(hDC, pXP->m_LeftArrowRect, CXPH_LARGEARROW|CXPH_LEFTWARDS);
  880. ReleaseDC(hWnd,hDC);
  881. // ScrollDrawHorizontal(pCxp, SCROLLLEFTARROW);
  882. }
  883. else if (pXP->m_bMouseDownArrowForwad&&
  884. (dwStyle & SBS_HORZ) == SBS_HORZ) //右键
  885. {
  886. hDC = GetDC(pCxp->hWnd);
  887. pXP->m_bMouseDownArrowForwad = false;
  888. ScrollDrowThumbXP(hDC, pXP->m_RightArrowRect, CXPH_LARGEARROW|CXPH_RIGHTWARDS);
  889. ReleaseDC(hWnd,hDC);
  890. // ScrollDrawHorizontal(pCxp, SCROLLLEFTARROW);
  891. }
  892. if(pXP->m_bMouseDown ||
  893. pXP->m_bMouseDownArrowForback ||
  894. pXP->m_bMouseDownArrowForwad)
  895. {
  896. pXP->m_bMouseDown = FALSE;
  897. pXP->m_bMouseDownArrowForback = FALSE;
  898. pXP->m_bMouseDownArrowForwad = FALSE;
  899. // KillTimer(hWnd,2);
  900. // KillTimer(hWnd,1);
  901. //CClientDC dc(this);
  902. //if((style & SBS_VERT) == SBS_VERT)
  903. // DrawVertical(&dc);
  904. //else
  905. // DrawHorizontal(&dc);
  906. //ScrollOnPaint(pCxp);
  907. }
  908. }
  909. //////////////////////////////////////////////////////////////
  910. void ScrollOnMouseMove(PCLASSXP pCxp, WPARAM wParam, LPARAM lParam)
  911. // UINT nFlags, CPoint point
  912. {
  913. POINT point, mousePoint;
  914. PSCROLLXP pXP;
  915. HWND hWnd, hParent;
  916. RECT Rect;
  917. HDC hDC;
  918. DWORD dwStyle;
  919. SCROLLINFO sif;
  920. pXP = (PSCROLLXP)pCxp->pData;
  921. // pXP->m_MouseDownTime = 0;
  922. hWnd = pCxp->hWnd;
  923. point.x = LOWORD(lParam);
  924. point.y = HIWORD(lParam);
  925. dwStyle = (DWORD)GetWindowLong(pCxp->hWnd, GWL_STYLE);
  926. GetWindowRect(hWnd, &Rect);
  927. Rect.right -= Rect.left;
  928. Rect.bottom -= Rect.top;
  929. Rect.left = Rect.top = 0;
  930. hParent = GetParent(hWnd);
  931. // CWnd *pParent = GetParent();
  932. if(hParent == NULL)return;
  933. if(pXP->m_bMouseDown)pXP->m_bDragging = TRUE;
  934. if(!pXP->m_bDragging)return;
  935. mousePoint.x = pXP->m_ThumbRect.left + pXP->m_MouseDownPoint.x;
  936. mousePoint.y = pXP->m_ThumbRect.top + pXP->m_MouseDownPoint.y;
  937. // DWORD style = GetStyle();
  938. // dwStyle = (DWORD)GetWindowLong(pCxp->hWnd, GWL_STYLE);
  939. if( (dwStyle & SBS_VERT) == SBS_VERT)
  940. {
  941. if(mousePoint.y == point.y)return;
  942. // if(!PtInRect(&Rect,point))return;
  943. int move = point.y - mousePoint.y;
  944. double pos = pXP->m_ThumbRect.top + move - pXP->m_AreaRect.top;
  945. double height = (pXP->m_AreaRect.bottom-pXP->m_AreaRect.top) -
  946. (pXP->m_ThumbRect.bottom-pXP->m_ThumbRect.top);
  947. double per = pos / height;
  948. // GetScrollInfo(&sif);
  949. ZeroMemory(&sif,sizeof(sif));
  950. sif.cbSize = sizeof(SCROLLINFO);
  951. sif.fMask = SIF_ALL;
  952. GetScrollInfo(hWnd, SB_CTL, &sif);
  953. int newpos = (int)((sif.nMax - sif.nMin) * per);
  954. if(newpos < sif.nMin) newpos = sif.nMin;
  955. if(newpos > sif.nMax) newpos = sif.nMax;
  956. sif.nTrackPos = newpos;
  957. if(pXP->m_nThumbTrackPos != newpos)
  958. {
  959. /* hDC = GetDC(hWnd);
  960. ScrollDrawButton(pCxp,hDC,pXP->m_ThumbRect, SBS_VERT, SCROLLAREANULL);
  961. pXP->m_nThumbTrackPos = newpos;
  962. ScrollCalVertical(pCxp,sif,Rect);
  963. ScrollDrawButton(pCxp,hDC,pXP->m_ThumbRect, SBS_VERT, SCROLLTHUMB);
  964. ReleaseDC(hWnd,hDC);
  965. */
  966. SendMessage(hWnd,WM_SETREDRAW,FALSE,0);
  967. SendMessage(hParent,WM_VSCROLL,MAKEWPARAM(SB_THUMBTRACK,sif.nTrackPos),(LPARAM)hWnd);
  968. SendMessage(hWnd,WM_SETREDRAW,TRUE,0);
  969. hDC = GetDC(hWnd);
  970. ScrollDrowThumbXP(hDC, pXP->m_ThumbRect, CXPH_AREA);
  971. // ScrollDrowThumbXP(hDC, pXP->m_AreaRect, CXPH_LARGEARROW|CXPH_HASFRAME);
  972. pXP->m_nThumbTrackPos = newpos;
  973. ScrollCalVertical(pCxp,sif, Rect);
  974. ScrollDrowThumbXP(hDC, pXP->m_ThumbRect, CXPS_PRESSED|
  975. CXPH_LARGEARROW|CXPH_DROPHANDLE);
  976. ReleaseDC(hWnd,hDC);
  977. }
  978. }
  979. else
  980. {
  981. if(mousePoint.x == point.x)return;
  982. // if(!PtInRect(&Rect,point))return;
  983. int move = point.x - mousePoint.x;
  984. double pos = pXP->m_ThumbRect.left + move - pXP->m_AreaRect.left;
  985. double width = (pXP->m_AreaRect.right-pXP->m_AreaRect.left) -
  986. (pXP->m_ThumbRect.right-pXP->m_ThumbRect.left);
  987. double per = pos / width;
  988. // GetScrollInfo(&sif);
  989. ZeroMemory(&sif,sizeof(sif));
  990. sif.cbSize = sizeof(SCROLLINFO);
  991. sif.fMask = SIF_ALL;
  992. GetScrollInfo(hWnd, SB_CTL, &sif);
  993. int newpos = (int)((sif.nMax - sif.nMin) * per);
  994. if(newpos < sif.nMin) newpos = sif.nMin;
  995. if(newpos > sif.nMax) newpos = sif.nMax;
  996. sif.nTrackPos = newpos;
  997. if(pXP->m_nThumbTrackPos != newpos)
  998. {
  999. /* hDC = GetDC(hWnd);
  1000. ScrollDrawButton(pCxp,hDC,pXP->m_ThumbRect, SBS_HORZ, SCROLLAREANULL);
  1001. //GetScrollInfo(hWnd, SB_CTL, &sif);
  1002. pXP->m_nThumbTrackPos = newpos;
  1003. ScrollCalHorizontal(pCxp,sif,Rect);
  1004. ScrollDrawButton(pCxp,hDC,pXP->m_ThumbRect, SBS_HORZ, SCROLLTHUMB);
  1005. ReleaseDC(hWnd,hDC);
  1006. */
  1007. SendMessage(hWnd,WM_SETREDRAW,FALSE,0);
  1008. SendMessage(hParent,WM_HSCROLL,MAKEWPARAM(SB_THUMBTRACK,sif.nTrackPos),(LPARAM)hWnd);
  1009. SendMessage(hWnd,WM_SETREDRAW,TRUE,0);
  1010. hDC = GetDC(hWnd);
  1011. ScrollDrowThumbXP(hDC, pXP->m_ThumbRect, CXPS_HORIZON|CXPH_AREA);
  1012. pXP->m_nThumbTrackPos = newpos;
  1013. ScrollCalHorizontal(pCxp,sif, Rect);
  1014. ScrollDrowThumbXP(hDC, pXP->m_ThumbRect, CXPS_PRESSED|
  1015. CXPH_LARGEARROW|CXPH_DROPHANDLE|CXPS_HORIZON);
  1016. // ScrollDrawVertical(pCxp, SCROLLTHUMB);
  1017. ReleaseDC(hWnd,hDC);
  1018. }
  1019. }
  1020. }
  1021. ////////////////////////////////////////////////////////////
  1022. void CALLBACK ScrollOnTimer(PCLASSXP pCxp, UINT nIDEvent)
  1023. {
  1024. // if(!m_IsEnableSkin)return CScrollBar::OnTimer(nIDEvent);
  1025. /* POINT point;
  1026. SCROLLINFO sif;
  1027. PSCROLLXP pXP;
  1028. HWND hWnd, hParent;
  1029. HDC hDC;
  1030. DWORD dwStyle;
  1031. pXP = (PSCROLLXP)pCxp->pData;
  1032. // pXP->m_MouseDownTime = 0;
  1033. hWnd = pCxp->hWnd;
  1034. if(pXP->m_MouseDownTime < 3)
  1035. {
  1036. pXP->m_MouseDownTime++;
  1037. return;
  1038. }
  1039. // CWnd* pParent = GetParent();
  1040. // DWORD style = GetStyle();
  1041. dwStyle = (DWORD)GetWindowLong(pCxp->hWnd, GWL_STYLE);
  1042. hParent = GetParent(hWnd);
  1043. // GetScrollInfo(&sif);
  1044. // GetScrollInfo(hWnd,SB_VERT, &sif);
  1045. if( (dwStyle & SBS_VERT) == SBS_VERT)
  1046. {
  1047. if(nIDEvent == 2)
  1048. {
  1049. if(pXP->m_bMouseDownArrowForback)
  1050. {
  1051. SendMessage(hParent,WM_VSCROLL,MAKEWPARAM(SB_LINEUP,0),(LPARAM)hWnd);
  1052. }
  1053. else if(pXP->m_bMouseDownArrowForwad)
  1054. {
  1055. SendMessage(hParent,WM_VSCROLL,MAKEWPARAM(SB_LINEDOWN,0),(LPARAM)hWnd);
  1056. }
  1057. }
  1058. else if(nIDEvent == 1)
  1059. {
  1060. // CPoint point;
  1061. GetCursorPos(&point);
  1062. ScreenToClient(hWnd, &point);
  1063. if(!PtInRect(&pXP->m_ThumbRect,point))
  1064. {
  1065. if(pXP->m_bMouseDownArrowForback)
  1066. {
  1067. SendMessage(hParent,WM_VSCROLL,MAKEWPARAM(SB_PAGEUP,0),(LPARAM)hWnd);
  1068. }
  1069. else if(pXP->m_bMouseDownArrowForwad)
  1070. {
  1071. SendMessage(hParent,WM_VSCROLL,MAKEWPARAM(SB_PAGEDOWN,0),(LPARAM)hWnd);
  1072. }
  1073. }
  1074. }
  1075. }
  1076. else
  1077. {
  1078. if(nIDEvent == 2)
  1079. {
  1080. if(pXP->m_bMouseDownArrowForback)
  1081. {
  1082. SendMessage(hParent,WM_HSCROLL,MAKEWPARAM(SB_LINELEFT,0),(LPARAM)hWnd);
  1083. }
  1084. else if(pXP->m_bMouseDownArrowForwad)
  1085. {
  1086. SendMessage(hParent,WM_HSCROLL,MAKEWPARAM(SB_LINERIGHT,0),(LPARAM)hWnd);
  1087. }
  1088. }
  1089. else if(nIDEvent == 1)
  1090. {
  1091. //CPoint point;
  1092. GetCursorPos(&point);
  1093. ScreenToClient(hWnd, &point);
  1094. if(!PtInRect(&pXP->m_ThumbRect,point))
  1095. {
  1096. if(pXP->m_bMouseDownArrowForback)
  1097. {
  1098. SendMessage(hParent,WM_HSCROLL,MAKEWPARAM(SB_PAGELEFT,0),(LPARAM)hWnd);
  1099. }
  1100. else if(pXP->m_bMouseDownArrowForwad)
  1101. {
  1102. SendMessage(hParent,WM_HSCROLL,MAKEWPARAM(SB_PAGERIGHT,0),(LPARAM)hWnd);
  1103. }
  1104. }
  1105. }
  1106. }
  1107. */
  1108. }
  1109. void ScrollOnPaint(PCLASSXP pCxp)
  1110. {
  1111. //CPaintDC dc(this);
  1112. //HDC hDC = GetDC(pCxp->hWnd);
  1113. DWORD dwStyle = (DWORD)GetWindowLong(pCxp->hWnd, GWL_STYLE);
  1114. if( (dwStyle & SBS_VERT) == SBS_VERT)
  1115. {
  1116. ScrollDrawVertical(pCxp, SCROLLALL); //全部
  1117. }
  1118. else
  1119. {
  1120. ScrollDrawHorizontal(pCxp, SCROLLALL); //全部
  1121. }
  1122. //ReleaseDC(pCxp->hWnd,hDC);
  1123. }
  1124. /////////////////////////////////////////////////////////////
  1125. void ScrollOnLButtonDblClk(PCLASSXP pCxp,WPARAM wParam, LPARAM lParam)
  1126. //UINT nFlags, CPoint point
  1127. {
  1128. ScrollOnLButtonDown(pCxp,wParam,lParam);
  1129. ScrollOnLButtonUp(pCxp,wParam,lParam);
  1130. }
  1131. ////////////////////////////////////////////////////////////////////////////////////////////////////
  1132. LRESULT ScrollWindowProc(PCLASSXP pCxp, UINT message,WPARAM wParam, LPARAM lParam)
  1133. {
  1134. LONG lReturn;
  1135. HWND hWnd = pCxp->hWnd;
  1136. switch (message)
  1137. {
  1138. case WM_LBUTTONDBLCLK :
  1139. ScrollOnLButtonDblClk(pCxp, wParam,lParam);
  1140. return 0;
  1141. case WM_LBUTTONDOWN: //11
  1142. ScrollOnLButtonDown(pCxp, wParam,lParam);
  1143. return 0;
  1144. case WM_LBUTTONUP: //11
  1145. ScrollOnLButtonUp(pCxp, wParam,lParam);
  1146. return 0;
  1147. case WM_MOUSEMOVE: //12
  1148. ScrollOnMouseMove(pCxp, wParam,lParam);
  1149. return 0;
  1150. case WM_ERASEBKGND:
  1151. return TRUE;
  1152. case WM_TIMER:
  1153. ScrollOnTimer(pCxp, (UINT )wParam);
  1154. lReturn = DefWindowProc(hWnd, message, wParam, lParam);
  1155. return lReturn;
  1156. break;
  1157. case WM_NCPAINT:
  1158. return 0;
  1159. case WM_PAINT:
  1160. lReturn = DefWindowProc(hWnd, message, wParam, lParam);
  1161. ScrollOnPaint(pCxp);
  1162. return lReturn;
  1163. }
  1164. // 调用原来的回调函数
  1165. lReturn = (LONG) CallWindowProc(pCxp->wpPrev, hWnd, message, wParam, lParam);
  1166. if (message == WM_NCDESTROY) // 窗口销毁
  1167. DeleteClassXP(hWnd);
  1168. return lReturn;
  1169. }
  1170. //尾部
  1171. #ifdef __cplusplus
  1172. }
  1173. #endif // __cplusplus
  1174. /*****************************************************************/