library.cpp 25 KB

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