library.cpp 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805
  1. /*
  2. * IRS Skin Library
  3. * Designed by Kilo(110i@110i.net)
  4. * (C)CopyRight, 2003-2004, IRS, All Right Reserved
  5. * iRacer.Studio - HttP://wWw.110i.nEt
  6. */
  7. #include "stdafx.h"
  8. #include "library.h"
  9. #include "YLGL.h"
  10. #include "BitmapEx.h"
  11. #include "DialogExt.h"
  12. #include "CheckBoxExt.h"
  13. #include "RadioExt.h"
  14. #include "ComboBoxExt.h"
  15. #include "ScrollBarExt.h"
  16. #include "ButtonExt.h"
  17. #include "EditExt.h"
  18. #include "GroupBoxExt.h"
  19. #include ".\scrollbar\coolscroll.h"
  20. #include ".\scrollbar\coolsb_detours.h"
  21. #pragma comment(lib, "Msimg32.lib")
  22. HHOOK globalWndHookEx;
  23. BOOL g_bDrawBk=0;
  24. CMapPtrToPtr g_ctrlMap;//保存对话框状态 DrawScrollBars
  25. CArray<DWORD,DWORD>g_wndstatelist;//窗口状态
  26. COLORREF g_crDialogbkColor=0 ; // 窗口背景颜色
  27. HBRUSH g_frameedgebrush=NULL; //窗口边框颜色画刷
  28. HPEN g_frameedgepen=NULL; //窗口边框颜色画笔
  29. BOOL bReg=0;
  30. HINSTANCE g_dllinst;
  31. HINSTANCE g_maininst;
  32. #define SCROLLAREA 0 //滚动条区域
  33. #define SCROLLTOPARROW 1 //上箭头
  34. #define SCROLLBOTTOMARROW 2 //下箭头
  35. #define SCROLLLEFTARROW 3 //左箭头
  36. #define SCROLLRIGHTARROW 4 //右箭头
  37. #define SCROLLTHUMB 5 //移动块
  38. #define SCROLLAREANULL 6 //滚动条空区域
  39. #define SCROLLALL 7 //所有区域
  40. // SCROLLXP 结构,所有的代码都是围绕这个结构而编写的 DrawScrollBars
  41. typedef struct tagSCROLLXP
  42. {
  43. RECT m_ThumbRect;
  44. RECT m_ThumbRectOld;
  45. RECT m_BottomArrowRect;
  46. RECT m_TopArrowRect;
  47. RECT m_LeftArrowRect;
  48. RECT m_RightArrowRect;
  49. RECT m_SizeArea;
  50. RECT m_AreaRect ;
  51. BOOL m_bMouseDownArrowForback; //上移
  52. BOOL m_bMouseDownArrowForwad; //下移
  53. BOOL m_bMouseDown;
  54. POINT m_MouseDownPoint;
  55. UINT m_MouseDownTime;
  56. BOOL m_bDragging; //正在拖动
  57. UINT m_nThumbTrackPos;
  58. }SCROLLXP, * PSCROLLXP;
  59. COLORREF gChecks_crGradientXP[][4] =
  60. {
  61. {0x00A5B2B5, 0x00CED7D6, 0x00CED7D6, 0x00DEEFF7},
  62. {0x00CEF3FF, 0x0063CBFF, 0x0063CBFF, 0x0031B2FF},
  63. {0x00D6DFDE, 0x00EFF3F7, 0x00EFF3F7, 0x00FFFFFF},
  64. {0x0021A221, 0x0021A221, 0x00187A18, 0x00187A18},
  65. };
  66. int FindPos(DWORD str, CArray<DWORD,DWORD> &array)
  67. {
  68. int count=array.GetSize ();
  69. for(int i=0; i<count; i++)
  70. {
  71. if(str==array.ElementAt (i))
  72. return i;
  73. }
  74. return -1;
  75. }
  76. int GetPosFromHwnd(HWND hWnd)
  77. {
  78. return FindPos((DWORD)hWnd, g_wndstatelist);
  79. }
  80. // 绘制渐变矩形 ReleaseMemDCXP
  81. VOID GradientRectXP(HDC hDC, LPRECT pRect,COLORREF crColor[4])
  82. {
  83. int i;
  84. TRIVERTEX Tve[4];
  85. GRADIENT_RECT GRect;
  86. GRADIENT_TRIANGLE GTrg;
  87. for (i = 0; i < 4; i++)
  88. {
  89. Tve[i].Red = ((COLOR16) GetRValue(crColor[i])) << 8;
  90. Tve[i].Green = ((COLOR16) GetGValue(crColor[i])) << 8;
  91. Tve[i].Blue = ((COLOR16) GetBValue(crColor[i])) << 8;
  92. Tve[i].Alpha = ((COLOR16) (crColor[i] >> 24)) << 8;
  93. }
  94. Tve[0].x = pRect->left;
  95. Tve[0].y = pRect->top;
  96. Tve[1].x = pRect->right;
  97. Tve[1].y = pRect->top;
  98. Tve[2].x = pRect->left;
  99. Tve[2].y = pRect->bottom;
  100. Tve[3].x = pRect->right;
  101. Tve[3].y = pRect->bottom;
  102. if ((crColor[0] == crColor[2]) &&
  103. (crColor[1] == crColor[3]))
  104. i = GRADIENT_FILL_RECT_H;
  105. if ((crColor[0] == crColor[1]) &&
  106. (crColor[2] == crColor[3]))
  107. i = GRADIENT_FILL_RECT_V;
  108. else
  109. i = GRADIENT_FILL_TRIANGLE;
  110. if (i == GRADIENT_FILL_TRIANGLE)
  111. {
  112. GTrg.Vertex1 = 0;
  113. GTrg.Vertex2 = 1;
  114. GTrg.Vertex3 = 2;
  115. }
  116. else
  117. {
  118. GRect.UpperLeft = 0;
  119. GRect.LowerRight = 3;
  120. }
  121. GradientFill(hDC, Tve, 4,
  122. ((i == GRADIENT_FILL_TRIANGLE) ? ((PVOID) &GTrg) : ((PVOID) &GRect)), 1, i);
  123. if (i == GRADIENT_FILL_TRIANGLE)
  124. {
  125. GTrg.Vertex1 = 3;
  126. GradientFill(hDC,Tve, 4, &GTrg, 1, GRADIENT_FILL_TRIANGLE);
  127. }
  128. }
  129. // 绘制 Thumb 块
  130. VOID ScrollDrowThumbXP(HDC hDC, RECT Rect, LONG lState)
  131. {
  132. int i;
  133. HANDLE hHandle;
  134. static COLORREF s_crGradientXP[][4] =
  135. {
  136. {0x00EFF3F7, 0x00DEE7E7, 0x00DEE3E7, 0x00DEE3E7},
  137. {0x00DEAEA5, 0x00F7CBBD, 0x00DE8273, 0x00F7C7B5},
  138. {0x00EFC7B5, 0x00E7AE94, 0x00DEA284, 0x00DEA68C},
  139. {0x00FFE3D6, 0x00F7CBBD, 0x00F7C3AD, 0x00F7C7B5},
  140. {0x00F7F7F7, 0x00EFF3F7, 0x00EFF3F7, 0x00EFF3F7},
  141. {0x00DEC3BD, 0x00DEB6AD, 0x00FFE3DE, 0x00F7E3DE},
  142. {0x00EFDBCE, 0x00EFCFC6, 0x00E7CFC6, 0x00E7CBBD},
  143. {0x00FFEFE7, 0x00FFE7DE, 0x00FFE3DE, 0x00F7E3DE},
  144. {0x00F7F7F7, 0x00E7EFEF, 0x00E7EBEF, 0x00DEE7E7},
  145. {0x00F78E6B, 0x00F79684, 0x00EF9E8C, 0x00EFDFD6},
  146. {0x00FFFFFF, 0x00FFE3CE, 0x00FFDFC6, 0x00FFDBBD},
  147. {0x00FFEBE7, 0x00FFCFBD, 0x00FFCBB5, 0x00F7CBAD},
  148. {0x00EFF3F7, 0x00DEE7E7, 0x00EFF3F7, 0x00DEE3E7},//水平滚条
  149. {0x00DEAEA5, 0x00F7CBBD, 0x00DEAEA5, 0x00F7C7B5},
  150. {0x00EFC7B5, 0x00E7AE94, 0x00EFC7B5, 0x00DEA68C},
  151. {0x00FFE3D6, 0x00F7CBBD, 0x00FFE3D6, 0x00F7C7B5},
  152. {0x00DEE7E7, 0x00DEE7E7, 0x00DEE3E7, 0x00DEE3E7},//垂直滚条
  153. {0x00F7CBBD, 0x00F7CBBD, 0x00DE8273, 0x00F7C7B5},
  154. {0x00EFC7B5, 0x00EFC7B5, 0x00E7AE94, 0x00DEA68C},
  155. {0x00F7CBBD, 0x00F7CBBD, 0x00F7C3AD, 0x00F7C7B5},
  156. };
  157. if (lState & CXPH_HASFRAME) //画外框阴影
  158. {
  159. Rect.right--;
  160. Rect.bottom--;
  161. FrameRect(hDC, &Rect, (HBRUSH )GetStockObject(WHITE_BRUSH));
  162. hHandle = (HANDLE) SelectObject(hDC,
  163. CreatePen(PS_SOLID, 1, (lState & CXPS_DISABLED) ? 0x00BDCFCE : 0x00D6B69C));
  164. MoveToEx(hDC, Rect.right, Rect.top + 2, NULL);
  165. LineTo(hDC, Rect.right, Rect.bottom - 2);
  166. LineTo(hDC, Rect.right - 2, Rect.bottom);
  167. LineTo(hDC, Rect.left + 1, Rect.bottom);
  168. LineTo(hDC, Rect.left - 1, Rect.bottom - 2);
  169. DeleteObject(SelectObject(hDC, (HGDIOBJ) hHandle));
  170. InflateRect(&Rect, -1, -1);
  171. }
  172. // 绘制 Thumb 外框
  173. if (lState & CXPS_DISABLED)
  174. i = 0;
  175. else if (lState & CXPS_PRESSED)
  176. i = 1;
  177. else if (lState & CXPS_HOTLIGHT)
  178. i = 2;
  179. else
  180. i = 3;
  181. if(lState & CXPH_AREA) //只绘滚条内区
  182. {
  183. i += 12;
  184. if(lState & CXPS_HORIZON)
  185. {
  186. i += 4;
  187. GradientRectXP(hDC, &Rect, s_crGradientXP[i]);
  188. }
  189. else
  190. {
  191. GradientRectXP(hDC, &Rect, s_crGradientXP[i]);
  192. }
  193. return;
  194. }
  195. else //画按钮
  196. {
  197. GradientRectXP(hDC, &Rect, s_crGradientXP[i]);
  198. // 绘制下拉外框拐角像素
  199. SetPixel(hDC, Rect.left, Rect.top, s_crGradientXP[i + 4][0]);
  200. SetPixel(hDC, Rect.right - 1, Rect.top, s_crGradientXP[i + 4][1]);
  201. SetPixel(hDC, Rect.left, Rect.bottom - 1, s_crGradientXP[i + 4][2]);
  202. SetPixel(hDC, Rect.right - 1, Rect.bottom - 1, s_crGradientXP[i + 4][3]);
  203. // 绘制 Thumb 内框
  204. InflateRect(&Rect, -1, -1);
  205. GradientRectXP(hDC, &Rect, s_crGradientXP[i + 8]);
  206. }
  207. // 绘制 Thumb 标志
  208. Rect.left += (Rect.right - Rect.left) / 2;
  209. Rect.top += (Rect.bottom - Rect.top) / 2;
  210. if (lState & CXPH_DROPHANDLE)
  211. {
  212. hHandle = (HANDLE) SelectObject(hDC, CreatePen(PS_SOLID, 1, 0x00FFF7EF));
  213. for (i = -4; i <= 2; i += 2)
  214. {
  215. if (lState & CXPS_HORIZON)
  216. {
  217. MoveToEx(hDC, Rect.left + i, Rect.top - 3, NULL);
  218. LineTo(hDC, Rect.left + i, Rect.top + 3);
  219. }
  220. else
  221. {
  222. MoveToEx(hDC, Rect.left - 3, Rect.top + i, NULL);
  223. LineTo(hDC, Rect.left + 3, Rect.top + i);
  224. }
  225. }
  226. DeleteObject(SelectObject(hDC, (HGDIOBJ) hHandle));
  227. hHandle = (HANDLE) SelectObject(hDC, CreatePen(PS_SOLID, 1, 0x00FFB28C));
  228. for (i = -3; i <= 3; i += 2)
  229. {
  230. if (lState & CXPS_HORIZON)
  231. {
  232. MoveToEx(hDC, Rect.left + i, Rect.top - 2, NULL);
  233. LineTo(hDC, Rect.left + i, Rect.top + 4);
  234. }
  235. else
  236. {
  237. MoveToEx(hDC, Rect.left - 2, Rect.top + i, NULL);
  238. LineTo(hDC, Rect.left + 4, Rect.top + i);
  239. }
  240. }
  241. DeleteObject(SelectObject(hDC, (HGDIOBJ) hHandle));
  242. }
  243. else
  244. {
  245. hHandle = (HANDLE) SelectObject(hDC,
  246. CreatePen(PS_SOLID, 1, (lState & CXPS_DISABLED) ? 0x00C6CBCE : 0x0084614A));
  247. if (lState & CXPH_SMALLARROW)
  248. {
  249. if (lState & CXPH_LEFTWARDS)
  250. {
  251. MoveToEx(hDC, Rect.left - 2, Rect.top, NULL);
  252. LineTo(hDC, Rect.left - 2, Rect.top + 1);
  253. MoveToEx(hDC, Rect.left - 1, Rect.top - 1, NULL);
  254. LineTo(hDC, Rect.left - 1, Rect.top + 2);
  255. MoveToEx(hDC, Rect.left, Rect.top - 2, NULL);
  256. LineTo(hDC, Rect.left, Rect.top + 3);
  257. MoveToEx(hDC, Rect.left + 1, Rect.top - 3, NULL);
  258. LineTo(hDC, Rect.left + 1, Rect.top);
  259. MoveToEx(hDC, Rect.left + 1, Rect.top + 1, NULL);
  260. LineTo(hDC, Rect.left + 1, Rect.top + 4);
  261. }
  262. else if (lState & CXPH_UPWARDS)
  263. {
  264. MoveToEx(hDC, Rect.left - 3, Rect.top + 1, NULL);
  265. LineTo(hDC, Rect.left, Rect.top + 1);
  266. MoveToEx(hDC, Rect.left + 1, Rect.top + 1, NULL);
  267. LineTo(hDC, Rect.left + 4, Rect.top + 1);
  268. MoveToEx(hDC, Rect.left - 2, Rect.top, NULL);
  269. LineTo(hDC, Rect.left + 3, Rect.top);
  270. MoveToEx(hDC, Rect.left - 1, Rect.top - 1, NULL);
  271. LineTo(hDC, Rect.left + 2, Rect.top - 1);
  272. MoveToEx(hDC, Rect.left, Rect.top - 2, NULL);
  273. LineTo(hDC, Rect.left + 1, Rect.top - 2);
  274. }
  275. else if (lState & CXPH_RIGHTWARDS)
  276. {
  277. MoveToEx(hDC, Rect.left + 2, Rect.top, NULL);
  278. LineTo(hDC, Rect.left + 2, Rect.top + 1);
  279. MoveToEx(hDC, Rect.left + 1, Rect.top - 1, NULL);
  280. LineTo(hDC, Rect.left + 1, Rect.top + 2);
  281. MoveToEx(hDC, Rect.left, Rect.top - 2, NULL);
  282. LineTo(hDC, Rect.left, Rect.top + 3);
  283. MoveToEx(hDC, Rect.left - 1, Rect.top - 3, NULL);
  284. LineTo(hDC, Rect.left - 1, Rect.top);
  285. MoveToEx(hDC, Rect.left - 1, Rect.top + 1, NULL);
  286. LineTo(hDC, Rect.left - 1, Rect.top + 4);
  287. }
  288. else if (lState & CXPH_DOWNWARDS)
  289. {
  290. MoveToEx(hDC, Rect.left - 3, Rect.top - 1, NULL);
  291. LineTo(hDC, Rect.left, Rect.top - 1);
  292. MoveToEx(hDC, Rect.left + 1, Rect.top - 1, NULL);
  293. LineTo(hDC, Rect.left + 4, Rect.top - 1);
  294. MoveToEx(hDC, Rect.left - 2, Rect.top, NULL);
  295. LineTo(hDC, Rect.left + 3, Rect.top);
  296. MoveToEx(hDC, Rect.left - 1, Rect.top + 1, NULL);
  297. LineTo(hDC, Rect.left + 2, Rect.top + 1);
  298. MoveToEx(hDC, Rect.left, Rect.top + 2, NULL);
  299. LineTo(hDC, Rect.left + 1, Rect.top + 2);
  300. }
  301. }
  302. else if (lState & CXPH_LARGEARROW)
  303. {
  304. if (lState & CXPH_LEFTWARDS)
  305. {
  306. MoveToEx(hDC, Rect.left + 1, Rect.top - 4, NULL);
  307. LineTo(hDC, Rect.left - 3, Rect.top);
  308. LineTo(hDC, Rect.left + 2, Rect.top + 5);
  309. MoveToEx(hDC, Rect.left + 1, Rect.top - 3, NULL);
  310. LineTo(hDC, Rect.left - 2, Rect.top);
  311. LineTo(hDC, Rect.left + 2, Rect.top + 4);
  312. MoveToEx(hDC, Rect.left + 2, Rect.top - 3, NULL);
  313. LineTo(hDC, Rect.left - 1, Rect.top);
  314. LineTo(hDC, Rect.left + 3, Rect.top + 4);
  315. }
  316. else if (lState & CXPH_UPWARDS)
  317. {
  318. MoveToEx(hDC, Rect.left - 4, Rect.top + 1, NULL);
  319. LineTo(hDC, Rect.left, Rect.top - 3);
  320. LineTo(hDC, Rect.left + 5, Rect.top + 2);
  321. MoveToEx(hDC, Rect.left - 3, Rect.top + 1, NULL);
  322. LineTo(hDC, Rect.left, Rect.top - 2);
  323. LineTo(hDC, Rect.left + 4, Rect.top + 2);
  324. MoveToEx(hDC, Rect.left - 3, Rect.top + 2, NULL);
  325. LineTo(hDC, Rect.left, Rect.top - 1);
  326. LineTo(hDC, Rect.left + 4, Rect.top + 3);
  327. }
  328. else if (lState & CXPH_RIGHTWARDS)
  329. {
  330. MoveToEx(hDC, Rect.left - 1, Rect.top - 4, NULL);
  331. LineTo(hDC, Rect.left + 3, Rect.top);
  332. LineTo(hDC, Rect.left - 2, Rect.top + 5);
  333. MoveToEx(hDC, Rect.left - 1, Rect.top - 3, NULL);
  334. LineTo(hDC, Rect.left + 2, Rect.top);
  335. LineTo(hDC, Rect.left - 2, Rect.top + 4);
  336. MoveToEx(hDC, Rect.left - 2, Rect.top - 3, NULL);
  337. LineTo(hDC, Rect.left + 1, Rect.top);
  338. LineTo(hDC, Rect.left - 3, Rect.top + 4);
  339. }
  340. else if (lState & CXPH_DOWNWARDS)
  341. {
  342. MoveToEx(hDC, Rect.left - 4, Rect.top - 2, NULL);
  343. LineTo(hDC, Rect.left, Rect.top + 2);
  344. LineTo(hDC, Rect.left + 5, Rect.top - 3);
  345. MoveToEx(hDC, Rect.left - 3, Rect.top - 2, NULL);
  346. LineTo(hDC, Rect.left, Rect.top + 1);
  347. LineTo(hDC, Rect.left + 4, Rect.top - 3);
  348. MoveToEx(hDC, Rect.left - 3, Rect.top - 3, NULL);
  349. LineTo(hDC, Rect.left, Rect.top);
  350. LineTo(hDC, Rect.left + 4, Rect.top - 4);
  351. }
  352. }
  353. DeleteObject(SelectObject(hDC, (HGDIOBJ) hHandle));
  354. }
  355. }
  356. void DrawScrollBar(HWND m_hWnd, HDC hDC, const RECT& rect, int nType, BOOL bScrollbarCtrl )
  357. {
  358. int nScrollSize = GetSystemMetrics( SM_CXHSCROLL );
  359. // The minimal thumb size depends on the system version
  360. // For Windows 98 minimal thumb size is a half of scrollbar size
  361. // and for Windows NT is always 8 pixels regardless of system metrics.
  362. // I really don't know why.
  363. int nMinThumbSize;
  364. if ( GetVersion() & 0x80000000 ) // Windows 98 code
  365. nMinThumbSize = nScrollSize / 2;
  366. else
  367. nMinThumbSize = 8;
  368. // Calculate the arrow rectangles
  369. RECT rc1 = rect, rc2 = rect;
  370. if ( nType == SB_HORZ )
  371. {
  372. if ( ( rect.right - rect.left ) < 2 * nScrollSize )
  373. nScrollSize = ( rect.right - rect.left ) / 2;
  374. rc1.right = rect.left + nScrollSize;
  375. rc2.left = rect.right - nScrollSize;
  376. ScrollDrowThumbXP( hDC, rc1, CXPH_LARGEARROW|CXPH_LEFTWARDS);
  377. ScrollDrowThumbXP( hDC, rc2, CXPH_LARGEARROW|CXPH_RIGHTWARDS);
  378. }
  379. else // SB_VERT
  380. {
  381. if ( ( rect.bottom - rect.top ) < 2 * nScrollSize )
  382. nScrollSize = ( rect.bottom - rect.top ) / 2;
  383. rc1.bottom = rect.top + nScrollSize;
  384. rc2.top = rect.bottom - nScrollSize;
  385. ScrollDrowThumbXP( hDC, rc1, CXPH_LARGEARROW|CXPH_UPWARDS);
  386. ScrollDrowThumbXP( hDC, rc2, CXPH_LARGEARROW|CXPH_DOWNWARDS);
  387. }
  388. // Disabled scrollbar never have a thumb
  389. if ( bScrollbarCtrl == TRUE && IsWindowEnabled( m_hWnd ) == FALSE )
  390. return;
  391. /* SCROLLINFO si;
  392. si.cbSize = sizeof( SCROLLINFO );
  393. si.fMask = SIF_ALL;
  394. GetScrollInfo( m_hWnd, bScrollbarCtrl ? SB_CTL : nType, &si );*/
  395. int pos=GetPosFromHwnd(m_hWnd);
  396. if(pos==-1)return;
  397. pos++;
  398. MYSCROLL *sb=(MYSCROLL*)g_wndstatelist.ElementAt (pos);
  399. SCROLLINFO *si=&(sb->VertInfo) ;
  400. // Calculate the size and position of the thumb
  401. int nRange = si->nMax - si->nMin + 1;
  402. if ( nRange )
  403. {
  404. int nScrollArea = ( nType == SB_VERT ? ( rect.bottom - rect.top ) : ( rect.right - rect.left ) ) - 2 * nScrollSize;
  405. int nThumbSize;
  406. if ( si->nPage == 0 ) // If nPage is not set then thumb has default size
  407. nThumbSize = GetSystemMetrics( SM_CXHTHUMB );
  408. else
  409. nThumbSize = max( MulDiv( si->nPage ,nScrollArea, nRange ), nMinThumbSize );
  410. if ( nThumbSize >= nScrollArea )
  411. {
  412. nThumbSize = nScrollArea;
  413. if ( bScrollbarCtrl == FALSE )
  414. return;
  415. }
  416. int nThumbPos;
  417. if ( UINT( nRange ) == si->nPage )
  418. {
  419. nThumbPos = 0;
  420. nThumbSize--;
  421. }
  422. else
  423. nThumbPos = MulDiv( si->nPos - si->nMin, nScrollArea - nThumbSize, nRange - si->nPage );
  424. if ( nType == SB_VERT )
  425. {
  426. rc1.top += nScrollSize + nThumbPos;
  427. rc1.bottom = rc1.top + nThumbSize;
  428. }
  429. else // SB_HORZ
  430. {
  431. rc1.left += nScrollSize + nThumbPos;
  432. rc1.right = rc1.left + nThumbSize;
  433. }
  434. if ( nThumbSize <= nScrollArea ) // Don't draw the thumb when it's larger than the scroll area
  435. {
  436. ScrollDrowThumbXP( hDC, rc1, CXPH_HASFRAME|CXPH_AREA);
  437. }
  438. }
  439. }
  440. void DrawScrollBars(HWND m_hWnd, HDC hDC, const RECT& rect )
  441. {
  442. const int nFrameSize = GetSystemMetrics( SM_CXEDGE );
  443. const int nScrollSize = GetSystemMetrics( SM_CXHSCROLL );
  444. RECT rc;
  445. // DWORD dwStyle = GetWindowLong( m_hWnd, GWL_STYLE );
  446. int pos=GetPosFromHwnd(m_hWnd);
  447. if(pos==-1)return;
  448. pos++;
  449. MYSCROLL *sb=(MYSCROLL*)g_wndstatelist.ElementAt (pos);
  450. DWORD dwStyle = sb->style ;
  451. if ( dwStyle & WS_HSCROLL && dwStyle & WS_VSCROLL )
  452. {
  453. rc.left = rect.left + nFrameSize; rc.top = rect.bottom - nFrameSize - nScrollSize;
  454. rc.right = rect.right - nFrameSize - nScrollSize; rc.bottom = rect.bottom - nFrameSize;
  455. DrawScrollBar(m_hWnd, hDC, rc, SB_HORZ );
  456. rc.left = rect.right - nFrameSize - nScrollSize; rc.top = rect.top + nFrameSize;
  457. rc.right = rect.right - nFrameSize; rc.bottom = rect.bottom - nFrameSize - nScrollSize;
  458. DrawScrollBar(m_hWnd, hDC, rc, SB_VERT );
  459. }
  460. else if ( dwStyle & WS_VSCROLL )
  461. {
  462. rc.left = rect.right - nFrameSize - nScrollSize;
  463. rc.top = rect.top + nFrameSize;
  464. rc.right = rect.right - nFrameSize;
  465. rc.bottom = rect.bottom - nFrameSize;
  466. DrawScrollBar(m_hWnd, hDC, rc, SB_VERT );
  467. }
  468. else if ( dwStyle & WS_HSCROLL )
  469. {
  470. rc.left = rect.left + nFrameSize; rc.top = rect.bottom - nFrameSize - nScrollSize;
  471. rc.right = rect.right - nFrameSize; rc.bottom = rect.bottom - nFrameSize;
  472. DrawScrollBar(m_hWnd, hDC, rc, SB_HORZ );
  473. }
  474. }
  475. // 获取窗口的内存兼容设备场景
  476. HDC GetMemDCXP(LPMEMDCXP pMdcxp)
  477. {
  478. RECT ctrlRect;
  479. GetWindowRect(pMdcxp->hWnd, &ctrlRect);
  480. // 创建兼容内存兼容设备场景并设置为透明模式
  481. pMdcxp->hDC = GetWindowDC(pMdcxp->hWnd);
  482. pMdcxp->hMemDC = CreateCompatibleDC(pMdcxp->hDC);;
  483. SetBkMode(pMdcxp->hMemDC, TRANSPARENT);
  484. // 是否已经指定了位图句柄
  485. if (pMdcxp->hBitmap)
  486. {
  487. // 选择位图对象
  488. SelectObject(pMdcxp->hMemDC, pMdcxp->hBitmap);
  489. }
  490. else
  491. {
  492. // 创建并选择位图对象
  493. pMdcxp->hBitmap = (HBITMAP) SelectObject(pMdcxp->hMemDC,
  494. CreateCompatibleBitmap(pMdcxp->hDC, ctrlRect.right - ctrlRect.left, ctrlRect.bottom - ctrlRect.top));
  495. #ifdef NEW_SKIN
  496. if(g_pMainWnd2->m_pBk && g_bDrawBk)
  497. {
  498. g_bDrawBk=0;
  499. HWND parenthwnd=::GetParent (pMdcxp->hWnd);
  500. DWORD style=GetWindowLong(parenthwnd, GWL_STYLE);
  501. BOOL bInDlg=1;
  502. if((style & WS_CHILD) == WS_CHILD||(style & WS_CAPTION) != WS_CAPTION)
  503. {
  504. bInDlg=0;
  505. }
  506. CRect parentrc;
  507. ::GetClientRect (parenthwnd, parentrc);
  508. Graphics graph(pMdcxp->hMemDC);
  509. Rect destinationRect(0,0,ctrlRect.right - ctrlRect.left,ctrlRect.bottom - ctrlRect.top);
  510. CRect rc=g_pMainWnd2->m_rcarray.ElementAt (16);
  511. CRect rc2=ctrlRect;
  512. CPoint pt1,pt2;
  513. pt1=rc2.TopLeft ();
  514. pt2=rc2.BottomRight ();
  515. ::ScreenToClient (::GetParent (pMdcxp->hWnd), &pt1);
  516. ::ScreenToClient (::GetParent (pMdcxp->hWnd), &pt2);
  517. rc2.left =pt1.x;
  518. rc2.top =pt1.y;
  519. rc2.right =pt2.x;
  520. rc2.bottom =pt2.y;
  521. float fscalex=1.0;
  522. float fscaley=1.0;
  523. if(bInDlg)
  524. {
  525. fscalex=(float)parentrc.Width ()/(float)rc.Width ();
  526. fscaley=(float)parentrc.Height ()/(float)rc.Height ();
  527. }
  528. rc2.left /=fscalex ;
  529. rc2.right /=fscalex ;
  530. rc2.top /=fscaley ;
  531. rc2.bottom /=fscaley ;
  532. rc2.left +=rc.left ;
  533. rc2.right +=rc.left ;
  534. rc2.top +=rc.top ;
  535. rc2.bottom +=rc.top ;
  536. rc=rc2;
  537. rc.left /=g_fscalex;
  538. rc.right /=g_fscalex;
  539. rc.top /=g_fscaley;
  540. rc.bottom /=g_fscaley;
  541. /* rc.left *=fscalex;
  542. rc.right *=fscalex;
  543. rc.top *=fscaley;
  544. rc.bottom *=fscaley;*/
  545. graph.DrawImage(g_pMainWnd2->m_pBk, destinationRect, rc.left , rc.top ,rc.Width (), rc.Height (),UnitPixel);
  546. }
  547. #endif
  548. // ::FillRect (pMdcxp->hMemDC, CRect(0,0,ctrlRect.right - ctrlRect.left, ctrlRect.bottom - ctrlRect.top), (HBRUSH)::GetStockObject (NULL_BRUSH));
  549. }
  550. // 如果要传送数据
  551. if (pMdcxp->bTransfer == TRUE)
  552. {
  553. BitBlt(pMdcxp->hMemDC, 0 , 0,
  554. ctrlRect.right - ctrlRect.left, ctrlRect.bottom - ctrlRect.top, pMdcxp->hDC, 0 , 0, SRCCOPY);
  555. }
  556. return pMdcxp->hMemDC;
  557. }
  558. VOID ReleaseMemDCXP(LPMEMDCXP pMdcxp)
  559. {
  560. RECT Rect;
  561. // 如果要传送数据
  562. if (pMdcxp->bTransfer == TRUE)
  563. {
  564. GetWindowRect(pMdcxp->hWnd, &Rect);
  565. BitBlt(pMdcxp->hDC, 0 , 0,Rect.right - Rect.left, Rect.bottom - Rect.top, pMdcxp->hMemDC, 0 ,0, SRCCOPY);
  566. }
  567. if (pMdcxp->hBitmap)
  568. DeleteObject(SelectObject(pMdcxp->hMemDC, pMdcxp->hBitmap));
  569. DeleteDC(pMdcxp->hMemDC);
  570. ReleaseDC(pMdcxp->hWnd, pMdcxp->hDC);
  571. }
  572. /*
  573. * Windows Hook Procduce Routine
  574. * nCode - hook code
  575. * wParam - current-process flag
  576. * lParam - message data
  577. */
  578. extern BOOL CALLBACK EnumChildProcDlg(HWND hwnd,LPARAM lParam);
  579. LRESULT CALLBACK IRCallWndProc( int nCode, WPARAM wParam, LPARAM lParam )
  580. {
  581. PCWPSTRUCT pcs = (PCWPSTRUCT) lParam;
  582. HWND hWnd = pcs->hwnd;
  583. WNDPROC WndProc;
  584. if( hWnd )
  585. {
  586. char sClassName[201] = "\0";
  587. GetClassName( hWnd, sClassName, 200 );
  588. if( strcmp( sClassName, "Button" ) == 0 )
  589. {
  590. CWnd *pWnd = CWnd::FromHandle( hWnd );
  591. DWORD dwStyle = pWnd->GetStyle();
  592. if ( ( dwStyle & BS_OWNERDRAW ) == BS_OWNERDRAW )
  593. return CallNextHookEx( globalWndHookEx, nCode, wParam, lParam );
  594. else if ( ( dwStyle & BS_GROUPBOX ) == BS_GROUPBOX )//groupbox
  595. return CallNextHookEx( globalWndHookEx, nCode, wParam, lParam );
  596. else if( (dwStyle & SS_TYPEMASK)==BS_DEFPUSHBUTTON || (dwStyle & SS_TYPEMASK)==BS_PUSHBUTTON )
  597. {
  598. WNDPROC WndProc;
  599. WndProc = (WNDPROC) GetWindowLong( hWnd, GWL_WNDPROC );
  600. if( CButtonExt::m_cWndProc != NULL && WndProc != CButtonExt::m_cWndProc )
  601. {
  602. return CallNextHookEx( globalWndHookEx, nCode, wParam, lParam );
  603. }
  604. if( WndProc != (WNDPROC) CButtonExt::DefWindowProc )
  605. {
  606. WndProc = (WNDPROC) SetWindowLong( hWnd, GWL_WNDPROC, (LONG) CButtonExt::DefWindowProc );
  607. CButtonExt::m_cWndProc = WndProc;
  608. }
  609. }
  610. /* else if ( ( dwStyle & BS_AUTOCHECKBOX ) == BS_AUTOCHECKBOX ||
  611. ( dwStyle & BS_CHECKBOX ) == BS_CHECKBOX ||
  612. ( dwStyle & BS_3STATE ) == BS_3STATE )//checkbox
  613. {
  614. WndProc = (WNDPROC) GetWindowLong( hWnd, GWL_WNDPROC );
  615. if( CCheckBoxExt::m_cWndProc != NULL && \
  616. WndProc != CCheckBoxExt::m_cWndProc )
  617. {
  618. return CallNextHookEx( globalWndHookEx, nCode, wParam, lParam );
  619. }
  620. if( WndProc != (WNDPROC) CCheckBoxExt::DefWindowProc )
  621. {
  622. g_wndstatelist.Add ((DWORD)hWnd);
  623. g_wndstatelist.Add ((DWORD)0);
  624. WndProc = (WNDPROC) SetWindowLong( hWnd, GWL_WNDPROC, (LONG) CCheckBoxExt::DefWindowProc );
  625. CCheckBoxExt::m_cWndProc = WndProc;
  626. }
  627. }
  628. else if ( ( dwStyle & BS_AUTORADIOBUTTON ) == BS_AUTORADIOBUTTON ||
  629. ( dwStyle & BS_RADIOBUTTON ) == BS_RADIOBUTTON )//radio
  630. {
  631. WndProc = (WNDPROC) GetWindowLong( hWnd, GWL_WNDPROC );
  632. if( CRadioExt::m_cWndProc != NULL && \
  633. WndProc != CRadioExt::m_cWndProc )
  634. {
  635. return CallNextHookEx( globalWndHookEx, nCode, wParam, lParam );
  636. }
  637. if( WndProc != (WNDPROC) CRadioExt::DefWindowProc )
  638. {
  639. g_wndstatelist.Add ((DWORD)hWnd);
  640. g_wndstatelist.Add ((DWORD)0);
  641. WndProc = (WNDPROC) SetWindowLong( hWnd, GWL_WNDPROC, (LONG) CRadioExt::DefWindowProc );
  642. CRadioExt::m_cWndProc = WndProc;
  643. }
  644. }*/
  645. }
  646. else if(0)// strcmp( sClassName, "ComboBox" ) == 0 )//combobox
  647. {
  648. WndProc = (WNDPROC) GetWindowLong( hWnd, GWL_WNDPROC );
  649. if( CComboBoxExt::m_cWndProc != NULL && \
  650. WndProc != CComboBoxExt::m_cWndProc )
  651. {
  652. return CallNextHookEx( globalWndHookEx, nCode, wParam, lParam );
  653. }
  654. if( WndProc != (WNDPROC) CComboBoxExt::DefWindowProc )
  655. {
  656. WndProc = (WNDPROC) SetWindowLong( hWnd, GWL_WNDPROC, (LONG) CComboBoxExt::DefWindowProc );
  657. CComboBoxExt::m_cWndProc = WndProc;
  658. }
  659. }
  660. else if(0)//strcmp( sClassName, "#32770" ) == 0 )//dialog
  661. {
  662. CWnd *pWnd = CWnd::FromHandle( hWnd );
  663. DWORD style=GetWindowLong(hWnd, GWL_STYLE);
  664. if(0)//(style & WS_CHILD) == WS_CHILD||(style & WS_CAPTION) != WS_CAPTION)
  665. {
  666. EnumChildWindows(hWnd,(WNDENUMPROC)EnumChildProcDlg,0);
  667. return CallNextHookEx( globalWndHookEx, nCode, wParam, lParam );
  668. }
  669. WndProc = (WNDPROC) GetWindowLong( hWnd, GWL_WNDPROC );
  670. if( WndProc != (WNDPROC) CDialogExt::DefWindowProc )
  671. {
  672. WndProc = (WNDPROC) SetWindowLong( hWnd, GWL_WNDPROC, (LONG) CDialogExt::DefWindowProc );
  673. DWORD style = GetWindowLong( hWnd, GWL_STYLE );
  674. WNDSTATE *m_wndstate;
  675. if ( !g_ctrlMap.Lookup( hWnd, (void*&)m_wndstate) )
  676. {
  677. m_wndstate=new WNDSTATE;
  678. m_wndstate->m_sizable =style & WS_SIZEBOX;
  679. m_wndstate->m_minable =style & WS_MINIMIZEBOX;
  680. m_wndstate->m_maxable =style & WS_MAXIMIZEBOX;
  681. m_wndstate->oldWndProc =WndProc;
  682. g_ctrlMap.SetAt( hWnd, m_wndstate );
  683. }
  684. style &= ~WS_MINIMIZEBOX;//去掉最小化钮
  685. style &= ~WS_MAXIMIZEBOX;
  686. SetWindowLong( hWnd, GWL_STYLE, style);
  687. }
  688. }
  689. }
  690. return CallNextHookEx( globalWndHookEx, nCode, wParam, lParam );
  691. }
  692. //按钮的外边框
  693. CPen m_BoundryPen;
  694. //鼠标指针置于按钮之上时按钮的内边框
  695. CPen m_InsideBoundryPenLeft;
  696. CPen m_InsideBoundryPenRight;
  697. CPen m_InsideBoundryPenTop;
  698. CPen m_InsideBoundryPenBottom;
  699. //按钮获得焦点时按钮的内边框
  700. CPen m_InsideBoundryPenLeftSel;
  701. CPen m_InsideBoundryPenRightSel;
  702. CPen m_InsideBoundryPenTopSel;
  703. CPen m_InsideBoundryPenBottomSel;
  704. //按钮的底色,包括有效和无效两种状态
  705. CBrush m_FillActive;
  706. CBrush m_FillInactive;
  707. BOOL IRStartup( HINSTANCE hModule, DWORD dwThreadID )
  708. {//return 1;
  709. // CoolSB_InitializeApp();
  710. // CDialogExt::Init();
  711. m_BoundryPen.CreatePen(PS_INSIDEFRAME | PS_SOLID, 1, RGB(0, 0, 0));
  712. m_InsideBoundryPenLeft.CreatePen(PS_INSIDEFRAME | PS_SOLID, 3, RGB(250, 196, 88));
  713. m_InsideBoundryPenRight.CreatePen(PS_INSIDEFRAME | PS_SOLID, 3, RGB(251, 202, 106));
  714. m_InsideBoundryPenTop.CreatePen(PS_INSIDEFRAME | PS_SOLID, 2, RGB(252, 210, 121));
  715. m_InsideBoundryPenBottom.CreatePen(PS_INSIDEFRAME | PS_SOLID, 2, RGB(229, 151, 0));
  716. m_FillActive.CreateSolidBrush(RGB(223, 222, 236));
  717. m_FillInactive.CreateSolidBrush(RGB(222, 223, 236));
  718. m_InsideBoundryPenLeftSel.CreatePen(PS_INSIDEFRAME | PS_SOLID, 3, RGB(153, 198, 252));
  719. m_InsideBoundryPenTopSel.CreatePen(PS_INSIDEFRAME | PS_SOLID, 2, RGB(162, 201, 255));
  720. m_InsideBoundryPenRightSel.CreatePen(PS_INSIDEFRAME | PS_SOLID, 3, RGB(162, 189, 252));
  721. m_InsideBoundryPenBottomSel.CreatePen(PS_INSIDEFRAME | PS_SOLID, 2, RGB(162, 201, 255));
  722. globalWndHookEx = SetWindowsHookEx(
  723. WH_CALLWNDPROC, (HOOKPROC) IRCallWndProc, hModule, dwThreadID );
  724. return TRUE;
  725. }
  726. BOOL IRComplete( void )
  727. {//return 1;
  728. UnhookWindowsHookEx( globalWndHookEx );
  729. m_BoundryPen.DeleteObject();
  730. m_InsideBoundryPenLeft.DeleteObject();
  731. m_InsideBoundryPenRight.DeleteObject();
  732. m_InsideBoundryPenTop.DeleteObject();
  733. m_InsideBoundryPenBottom.DeleteObject();
  734. m_FillActive.DeleteObject();
  735. m_FillInactive.DeleteObject();
  736. m_InsideBoundryPenLeftSel.DeleteObject();
  737. m_InsideBoundryPenTopSel.DeleteObject();
  738. m_InsideBoundryPenRightSel.DeleteObject();
  739. m_InsideBoundryPenBottomSel.DeleteObject();
  740. return TRUE;
  741. }