ButtonXP.cpp 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032
  1. // ButtonXP.cpp: implementation of the CButtonXP 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 "ButtonXP.h"
  17. //////////////////////////////////////////////////////////////////////////////////////////////////
  18. // 全局变量
  19. extern HHOOK g_hPrevHookXP ; // 窗口消息 HOOK 句柄
  20. extern PCLASSXP g_pClassXP ; // 窗口的 CLASSXP 结构指针
  21. extern COLORREF g_crDialogbkColor; // 窗口背景颜色
  22. //各颜色均为全局变量
  23. //gChecks:CheckBox和RadioBox共用, 禁止时画白刷
  24. //CheckBox:0=CXPS_PRESSED 1=CXPS_HOTLIGHT 2=正常
  25. //RadioBox:0=CXPS_PRESSED 1=CXPS_HOTLIGHT 3=选中
  26. static COLORREF gChecks_crGradientXP[][4] =
  27. {
  28. {0x00A5B2B5, 0x00CED7D6, 0x00CED7D6, 0x00DEEFF7},
  29. {0x00CEF3FF, 0x0063CBFF, 0x0063CBFF, 0x0031B2FF},
  30. {0x00D6DFDE, 0x00EFF3F7, 0x00EFF3F7, 0x00FFFFFF},
  31. {0x0021A221, 0x0021A221, 0x00187A18, 0x00187A18},
  32. };
  33. //按钮 0=PRESSED 1=HOTLIGHT 2=正常 3=禁止 4=其它
  34. /*
  35. static COLORREF gButtons_crGradientXP[][4] =
  36. {
  37. {RGB( 220, 214, 194 ), RGB( 245, 244, 235 ), 0,0},
  38. {RGB( 255, 255, 255 ), RGB( 226, 223, 214 ), 0, 0},
  39. {RGB( 252, 252, 251 ), RGB( 236, 235, 230 ), 0, 0},
  40. };
  41. COLORREF bkColorStart = ;
  42. COLORREF bkColorEnd = ;
  43. COLORREF FaceColorStart = ;
  44. COLORREF FaceColorEnd = ;
  45. COLORREF TextColorStart = ;
  46. COLORREF TextColorEnd = ;
  47. */
  48. //////////////////////////////////////////////////////////////
  49. /****************************************************************/
  50. //按钮设置转成文本设置
  51. UINT ButtonStyle2Format(DWORD style)
  52. {
  53. UINT uFormat = 0;
  54. if((style & BS_MULTILINE) != BS_MULTILINE)
  55. uFormat |= DT_SINGLELINE;
  56. if((style & BS_TOP) == BS_TOP)
  57. uFormat |= DT_TOP;
  58. else if((style & BS_BOTTOM) == BS_BOTTOM)
  59. uFormat |= DT_BOTTOM;
  60. else
  61. uFormat |= DT_VCENTER | DT_SINGLELINE;
  62. if((style & BS_LEFT) == BS_LEFT)
  63. uFormat |= DT_LEFT;
  64. else if((style & BS_RIGHT) == BS_RIGHT)
  65. uFormat |= DT_RIGHT;
  66. else
  67. uFormat |= DT_CENTER;
  68. uFormat |= DT_END_ELLIPSIS;
  69. return uFormat;
  70. }
  71. /////////////////////////////////////////////////////////////
  72. //设置图标
  73. LRESULT ButtonOnSetIcon(PCLASSXP pCxp, WPARAM wParam, LPARAM lParam)
  74. {
  75. //生成灰度禁止图标
  76. if (pCxp->hIconDisabled) DeleteObject(pCxp->hIconDisabled);
  77. pCxp->hIconDisabled =(HICON)CopyImage((HICON)lParam, IMAGE_ICON, 0,0,LR_MONOCHROME|LR_COPYRETURNORG);
  78. //设置使能图标
  79. LRESULT nRet = CallWindowProc(pCxp->wpPrev, pCxp->hWnd, WM_SETICON, wParam, lParam);
  80. // if(IsWindow(pCxp->hWnd)) // 重画窗口
  81. // RedrawWindow(pCxp->hWnd, NULL, NULL,RDW_UPDATENOW|RDW_ERASE | RDW_FRAME | RDW_INVALIDATE | RDW_ERASENOW);
  82. return nRet;
  83. }
  84. ////////////////////////////////////////////////
  85. //绘制按钮2
  86. /*
  87. VOID WINAPI ButtonDrawPushButtonXP(PCLASSXP pCxp)
  88. {
  89. RECT Rect, rc;
  90. MEMDCXP Mdcxp;
  91. HBRUSH hBrush;
  92. HANDLE hHandle;
  93. DWORD dwStyle;
  94. DWORD pID = NULL;
  95. HPEN pen1, pen2, pen3, pen4;
  96. int nSaveDC;
  97. TRIVERTEX vert[2] ;
  98. GRADIENT_RECT gRect;
  99. COLORREF bkColorStart = RGB( 220, 214, 194 );
  100. COLORREF bkColorEnd = RGB( 245, 244, 235 );
  101. COLORREF FaceColorStart = RGB( 255, 255, 255 );
  102. COLORREF FaceColorEnd = RGB( 226, 223, 214 );
  103. COLORREF TextColorStart = RGB( 252, 252, 251 );
  104. COLORREF TextColorEnd = RGB( 236, 235, 230 );
  105. // 获取内存兼容设备场景
  106. Mdcxp.hWnd = pCxp->hWnd;
  107. Mdcxp.bTransfer = FALSE;
  108. Mdcxp.hBitmap = NULL;
  109. GetMemDCXP(&Mdcxp);
  110. // 获取窗口大小
  111. GetWindowRect(pCxp->hWnd, &Rect);
  112. Rect.right -= Rect.left;
  113. Rect.bottom -= Rect.top;
  114. Rect.left = Rect.top = 0;
  115. rc = Rect;
  116. pen1 = CreatePen( PS_SOLID, 0, RGB(226, 222, 203) ); // 最左边的一条竖线
  117. pen2 = CreatePen( PS_SOLID, 0, RGB(248, 247, 242) ); // 最底部的一条横线
  118. nSaveDC = SaveDC(Mdcxp.hMemDC);
  119. dwStyle = (DWORD)GetWindowLong(pCxp->hWnd, GWL_STYLE);
  120. if (pCxp->dwState & CXPS_DISABLED)
  121. {
  122. pen3= CreatePen( PS_SOLID, 0, RGB(216, 213, 199) ); // 圆角矩形(4,4)
  123. pen4= CreatePen( PS_SOLID, 0, RGB(201, 199, 186) ); // 圆角矩形(6,6)
  124. }
  125. else
  126. {
  127. pen3 = CreatePen( PS_SOLID, 0, RGB(122, 149, 168) ); // 圆角矩形(4,4)
  128. pen4 = CreatePen( PS_SOLID, 0, RGB(0, 60, 116) ); // 圆角矩形(6,6)
  129. }
  130. // bkColor = GetPixel(GetDC(pCxp->hWnd), rc.right-1, rc.top );
  131. // nSaveDC = SaveDC(Mdcxp.hMemDC);
  132. //背景色填充
  133. hBrush = CreateSolidBrush(g_crDialogbkColor);
  134. SelectObject(Mdcxp.hMemDC, hBrush);
  135. FillRect(Mdcxp.hMemDC, &rc, (HBRUSH)hBrush);
  136. DeleteObject(hBrush);
  137. //空的背景色
  138. SelectObject(Mdcxp.hMemDC, GetStockObject(NULL_BRUSH));
  139. // 画最左边的一条竖线和最底部的一条横线
  140. if (!(pCxp->dwState & CXPS_DISABLED))
  141. {
  142. SelectObject(Mdcxp.hMemDC , pen1);
  143. MoveToEx(Mdcxp.hMemDC, rc.left, rc.top+1,NULL);
  144. LineTo(Mdcxp.hMemDC, rc.left, rc.bottom-1 );
  145. SelectObject(Mdcxp.hMemDC, pen2 );
  146. MoveToEx(Mdcxp.hMemDC, rc.left+2, rc.bottom-1, NULL);
  147. LineTo(Mdcxp.hMemDC, rc.right-1, rc.bottom-1 );
  148. }
  149. // 画最底层背景
  150. vert [0].y = Rect.top;
  151. vert [0].x = Rect.left+1;
  152. vert [0].Red = ((COLOR16)GetRValue( bkColorStart )) << 8;
  153. vert [0].Green = ((COLOR16)GetGValue( bkColorStart ))<< 8;
  154. vert [0].Blue = ((COLOR16)GetBValue( bkColorStart )) << 8;
  155. vert [0].Alpha = 0x0000;
  156. vert [1].y = Rect.bottom-1;
  157. vert [1].x = Rect.right;
  158. vert [1].Red = ((COLOR16)GetRValue( bkColorEnd )) << 8;
  159. vert [1].Green = ((COLOR16)GetGValue( bkColorEnd )) << 8;
  160. vert [1].Blue = ((COLOR16)GetBValue( bkColorEnd )) << 8;
  161. vert [1].Alpha = 0xFF00;
  162. gRect.UpperLeft = 0;
  163. gRect.LowerRight = 1;
  164. if (!(pCxp->dwState & CXPS_DISABLED))
  165. GradientFill(Mdcxp.hMemDC , vert, 2, &gRect, 1, GRADIENT_FILL_RECT_V );
  166. // 如果有焦点
  167. if ((pCxp->dwState & CXPS_FOCUS)|| (pCxp->dwState & CXPS_DEFAULT))
  168. {
  169. FaceColorStart = RGB(235, 160, 5 );
  170. FaceColorEnd = RGB( 251, 192, 73 );
  171. //平面充型
  172. if(dwStyle & BS_FLAT)
  173. {
  174. TextColorStart = RGB( 251, 192, 73 );
  175. TextColorEnd = RGB(235, 160, 5 );
  176. }
  177. Rect = rc;
  178. Rect.left += 2;
  179. }
  180. // 如果是高亮
  181. if (pCxp->dwState & CXPS_HOTLIGHT)
  182. {
  183. FaceColorStart = RGB( 255, 240, 207 );
  184. FaceColorEnd = RGB( 229, 151, 0 );
  185. Rect = rc;
  186. Rect.left += 2;
  187. }
  188. // 如果被按下
  189. if (pCxp->dwState & CXPS_PRESSED)
  190. {
  191. FaceColorStart = RGB( 209, 204, 193 );
  192. FaceColorEnd = RGB( 242, 241, 238 );
  193. TextColorStart = RGB( 229, 228, 221 );
  194. TextColorEnd = RGB( 226, 226, 218 );
  195. Rect = rc;
  196. Rect.left += 2;
  197. }
  198. // 如果被禁止
  199. if (pCxp->dwState & CXPS_DISABLED)
  200. {
  201. FaceColorStart = RGB( 245, 244, 234 );
  202. FaceColorEnd = FaceColorStart;
  203. TextColorStart = FaceColorStart;
  204. TextColorEnd = FaceColorStart;
  205. Rect = rc;
  206. Rect.left += 2;
  207. }
  208. // 画 BUTTON 内部所有区域背景
  209. vert [0].y = rc.top + 2;
  210. vert [0].x = rc.left + 2;
  211. vert [0].Red = ((COLOR16)GetRValue( FaceColorStart )) << 8;
  212. vert [0].Green = ((COLOR16) GetGValue( FaceColorStart)) << 8;
  213. vert [0].Blue = ((COLOR16) GetBValue( FaceColorStart)) << 8;
  214. vert [1].y = rc.bottom - 2 ;
  215. vert [1].x = rc.right - 2;
  216. vert [1].Red = ((COLOR16) GetRValue( FaceColorEnd )) << 8;
  217. vert [1].Green = ((COLOR16) GetGValue( FaceColorEnd )) << 8;
  218. vert [1].Blue = ((COLOR16) GetBValue( FaceColorEnd )) << 8;
  219. GradientFill(Mdcxp.hMemDC , vert, 2, &gRect, 1, GRADIENT_FILL_RECT_V );
  220. // 画 BUTTON 内部有效区域背景
  221. vert [0].y = Rect.top + 4;
  222. vert [0].x = Rect.left + 2;
  223. vert [0].Red = ((COLOR16) GetRValue( TextColorStart )) << 8;
  224. vert [0].Green = ((COLOR16) GetGValue( TextColorStart )) << 8;
  225. vert [0].Blue = ((COLOR16) GetBValue( TextColorStart )) << 8;
  226. vert [1].y = Rect.bottom - 4;
  227. vert [1].x = Rect.right - 4;
  228. vert [1].Red = ((COLOR16) GetRValue( TextColorEnd )) << 8 ;
  229. vert [1].Green = ((COLOR16) GetGValue( TextColorEnd )) << 8 ;
  230. vert [1].Blue = ((COLOR16) GetBValue( TextColorEnd )) << 8 ;
  231. GradientFill(Mdcxp.hMemDC , vert, 2, &gRect, 1, GRADIENT_FILL_RECT_V );
  232. // 如果有焦点
  233. if (pCxp->dwState & CXPS_FOCUS)
  234. {
  235. Rect = rc;
  236. InflateRect(&Rect, -3, -3);
  237. DrawFocusRect(Mdcxp.hMemDC, &Rect);
  238. }
  239. // 画椭圆形外框
  240. Rect = rc;
  241. InflateRect(&Rect, -1, -1);
  242. //Rect.DeflateRect( 1, 1 );
  243. hHandle = SelectObject(Mdcxp.hMemDC, pen3);
  244. RoundRect(Mdcxp.hMemDC, Rect.left, Rect.top ,
  245. Rect.right , Rect.bottom , 4,4 );
  246. hHandle = SelectObject(Mdcxp.hMemDC, pen4);
  247. RoundRect(Mdcxp.hMemDC, Rect.left, Rect.top ,
  248. Rect.right , Rect.bottom , 6,6);
  249. // 去除右上角的多余点
  250. SetPixel(Mdcxp.hMemDC, rc.right-1, rc.top, g_crDialogbkColor);
  251. ButtonDrawPushText(pCxp,Mdcxp.hMemDC,rc);
  252. RestoreDC(Mdcxp.hMemDC, nSaveDC );
  253. DeleteObject(pen1);
  254. DeleteObject(pen2);
  255. DeleteObject(pen3);
  256. DeleteObject(pen4);
  257. Mdcxp.bTransfer = TRUE;
  258. ReleaseMemDCXP(&Mdcxp);
  259. } // End of OnDrawBackground
  260. */
  261. ////////////////////////////////////////////////////////////////////////////////////////////////////
  262. // 绘制按钮文本
  263. VOID WINAPI ButtonDrawPushText(PCLASSXP pCxp, HDC hDC, RECT rc)
  264. {
  265. RECT rcIcon, rcText;
  266. HANDLE hHandle;
  267. char szTemp[256];
  268. HICON hIcon;
  269. DWORD dwStyle;//, pID = NULL;
  270. ICONINFO piconinfo;
  271. UINT uFormat;
  272. dwStyle = (DWORD)GetWindowLong(pCxp->hWnd, GWL_STYLE);
  273. //新增画图标
  274. if (pCxp->dwState & CXPS_DISABLED)
  275. hIcon = pCxp->hIconDisabled;
  276. else
  277. hIcon =(HICON) SendMessage(pCxp->hWnd, WM_GETICON, ICON_SMALL, 0);
  278. rcText = rc;
  279. if (hIcon)//有图标
  280. {
  281. GetIconInfo(hIcon,&piconinfo); //取图标信息
  282. rcIcon = rc;
  283. if (dwStyle & BS_TOP) //文字置顶
  284. {
  285. //rcIcon.left = rc.left + (rc.right - rc.left)/2 - piconinfo.xHotspot;
  286. rcIcon.top = rc.bottom - piconinfo.yHotspot*2 - 4;
  287. rcText.bottom -= piconinfo.yHotspot*2 ;
  288. }
  289. else if (dwStyle & BS_VCENTER)//文字置中
  290. {
  291. //rcIcon.left = rc.left + (rc.right - rc.left)/2 - piconinfo.xHotspot;
  292. rcIcon.top = (rc.bottom-rc.top)/2-piconinfo.yHotspot;
  293. //rcText.top += piconinfo.yHotspot*2 ;
  294. }
  295. else //if(dwStyle & BS_BOTTOM)//文字置底
  296. {
  297. //rcIcon.left = rc.left + (rc.right - rc.left)/2 - piconinfo.xHotspot;
  298. rcIcon.top = rc.top+4;
  299. rcText.top += piconinfo.yHotspot*2 + 4;
  300. }
  301. if (dwStyle & BS_RIGHT) //文字置右
  302. {
  303. rcIcon.left = 4;
  304. //rcIcon.top = Rect.top+2;
  305. rcText.left += piconinfo.yHotspot*2 + 2;
  306. }
  307. else if(dwStyle & BS_LEFT)//文字置左
  308. {
  309. rcIcon.left = rc.right - (piconinfo.yHotspot*2 + 4);
  310. //rcIcon.top = Rect.top+2;
  311. rcText.right -= (piconinfo.yHotspot*2 + 2);
  312. }
  313. else
  314. {
  315. rcIcon.left = (rc.right - rc.left)/2-piconinfo.yHotspot + 2;
  316. //rcIcon.top = Rect.top+2;
  317. //rcText.right -= (piconinfo.yHotspot*2 + 2);
  318. }
  319. DrawIcon(hDC, rcIcon.left,rcIcon.top, hIcon);
  320. }
  321. // 画文字
  322. uFormat = ButtonStyle2Format(dwStyle);
  323. if (GetWindowText(pCxp->hWnd, szTemp, sizeof(szTemp)))
  324. {
  325. if (pCxp->dwState & CXPS_PRESSED)
  326. OffsetRect(&rcText, 1, 1);
  327. SetTextColor(hDC,
  328. ((pCxp->dwState & CXPS_INDETERMINATE) || (pCxp->dwState & CXPS_DISABLED)) ?
  329. 0x0094A2A5: 0x00000000);
  330. hHandle = (HANDLE) SelectObject(hDC,
  331. (HGDIOBJ) SendMessage(pCxp->hWnd, WM_GETFONT, 0, 0));
  332. //DrawText(Mdcxp.hMemDC, szTemp, -1, &Rect, DT_CENTER | DT_SINGLELINE | DT_VCENTER);
  333. DrawText(hDC, szTemp, -1, &rcText, uFormat);
  334. SelectObject(hDC, (HGDIOBJ) hHandle);
  335. }
  336. }
  337. ////////////////////////////////////////////////////////////////////////////////////////////////////
  338. // 绘制按钮1
  339. VOID WINAPI ButtonDrawPushButtonXP(PCLASSXP pCxp)
  340. {
  341. int i;
  342. RECT Rect, rc;
  343. MEMDCXP Mdcxp;
  344. HANDLE hHandle;
  345. COLORREF crColor;
  346. HDC hDC;
  347. static COLORREF s_crGradientXP[][4] =
  348. {
  349. {0x00C1CCD1, 0x00C1CCD1, 0x00EEF1F2, 0xFFEEF1F2},
  350. {0x00CFF0FF, 0x00CFF0FF, 0x000097E5, 0xFF0097E5},
  351. {0x00BDCBD6, 0x00C6CFD6, 0x00EFF3F7, 0xFFEFF3F7},
  352. {0x00FFE7CE, 0x00FFE7CE, 0x00EE8269, 0xFFEE8269},
  353. {0x00FFFFFF, 0x00FFFFFF, 0x00D6DFE2, 0xFFD6DFE2},
  354. {0x00DEE3E7, 0x00E7E7E7, 0x00DEE3E7, 0xFFDEE3E7},
  355. {0x00FBFCFC, 0x00FBFCFC, 0x00E6EBEC, 0xFFE6EBEC},
  356. };
  357. // 获取内存兼容设备场景
  358. Mdcxp.hWnd = pCxp->hWnd;
  359. Mdcxp.bTransfer = FALSE;
  360. Mdcxp.hBitmap = NULL;
  361. GetMemDCXP(&Mdcxp);
  362. hDC = Mdcxp.hMemDC;
  363. // 获取窗口大小
  364. GetWindowRect(pCxp->hWnd, &Rect);
  365. Rect.right -= Rect.left;
  366. Rect.bottom -= Rect.top;
  367. Rect.left = Rect.top = 0;
  368. rc = Rect;
  369. // 画最外面的框,颜色与系统按钮颜色一直
  370. hHandle = (HANDLE) CreateSolidBrush(g_crDialogbkColor);
  371. FrameRect(hDC, &Rect, (HBRUSH) hHandle);
  372. DeleteObject((HGDIOBJ) hHandle);
  373. // 画最第二层边框
  374. InflateRect(&Rect, -1, -1);
  375. hHandle = (HANDLE) CreateSolidBrush(
  376. (pCxp->dwState & CXPS_DISABLED) ? (g_crDialogbkColor - 0x00202020) : 0x00733C00);
  377. FrameRect(hDC, &Rect, (HBRUSH) hHandle);
  378. DeleteObject((HGDIOBJ) hHandle);
  379. // 画热点框渐变背景
  380. InflateRect(&Rect, -1, -1);
  381. if (pCxp->dwState & CXPS_DISABLED)
  382. {
  383. i = -1;
  384. //hHandle = (HANDLE) CreateSolidBrush(0x00EAF4F5);
  385. hHandle = (HANDLE) CreateSolidBrush(g_crDialogbkColor);
  386. FillRect(hDC, &Rect, (HBRUSH) hHandle);
  387. DeleteObject((HGDIOBJ) hHandle);
  388. }
  389. else
  390. {
  391. if (pCxp->dwState & CXPS_PRESSED)
  392. i = 0;
  393. else if (pCxp->dwState & CXPS_HOTLIGHT)
  394. i = 1;
  395. else if ((pCxp->dwState & CXPS_CHECKED) || (pCxp->dwState & CXPS_INDETERMINATE))
  396. i = 2;
  397. else if ((pCxp->dwState & CXPS_FOCUS) || (pCxp->dwState & CXPS_DEFAULT))
  398. i = 3;
  399. else
  400. i = 4;
  401. GradientRectXP(hDC, &Rect, s_crGradientXP[i]);
  402. }
  403. // 画文字区域渐变背景
  404. InflateRect(&Rect, -2, -2);
  405. if ((pCxp->dwState & CXPS_PRESSED) ||
  406. (pCxp->dwState & CXPS_CHECKED) ||
  407. (pCxp->dwState & CXPS_INDETERMINATE))
  408. i = 5;
  409. else if (!(pCxp->dwState & CXPS_DISABLED))
  410. i = 6;
  411. if ((i == 5) || (i == 6))
  412. GradientRectXP(hDC, &Rect, s_crGradientXP[i]);
  413. // 用与系统按钮一直的颜色第二层边框的四角像素
  414. // crColor = GetSysColor(COLOR_BTNFACE);
  415. crColor = g_crDialogbkColor;
  416. SetPixel(hDC, 1, 1, crColor);
  417. SetPixel(hDC, 1, Rect.bottom + 2, crColor);
  418. SetPixel(hDC, Rect.right + 2, Rect.bottom + 2, crColor);
  419. SetPixel(hDC, Rect.right + 2, 1, crColor);
  420. // 画第二层边框的拐角像素,太罗嗦了,千万别仔细看:)
  421. // crColor = (pCxp->dwState & CXPS_DISABLED) ?
  422. // (GetSysColor(COLOR_BTNFACE) - 0x00151515) : 0x00A57D52;
  423. crColor = (pCxp->dwState & CXPS_DISABLED) ?
  424. (g_crDialogbkColor - 0x00151515) : g_crDialogbkColor-0x00A57D52;
  425. SetPixel(hDC, 2, 2, crColor);
  426. SetPixel(hDC, 2, Rect.bottom + 1, crColor);
  427. SetPixel(hDC, Rect.right + 1, Rect.bottom + 1, crColor);
  428. SetPixel(hDC, Rect.right + 1, 2, crColor);
  429. // crColor = (pCxp->dwState & CXPS_DISABLED) ?
  430. // (GetSysColor(COLOR_BTNFACE) - 0x00111111) : 0x00AD967B;
  431. crColor = (pCxp->dwState & CXPS_DISABLED) ?
  432. (g_crDialogbkColor - 0x00111111) : g_crDialogbkColor-0x00AD967B;
  433. SetPixel(hDC, 1, 2, crColor);
  434. SetPixel(hDC, 2, 1, crColor);
  435. SetPixel(hDC, Rect.right + 1, 1, crColor);
  436. SetPixel(hDC, Rect.right + 2, 2, crColor);
  437. SetPixel(hDC, Rect.right + 1, Rect.bottom + 2, crColor);
  438. SetPixel(hDC, Rect.right + 2, Rect.bottom + 1, crColor);
  439. SetPixel(hDC, 2, Rect.bottom + 2, crColor);
  440. SetPixel(hDC, 1, Rect.bottom + 1, crColor);
  441. // 如果有焦点,画出焦点框
  442. if (pCxp->dwState & CXPS_FOCUS)
  443. {
  444. InflateRect(&Rect, 1, 1);
  445. DrawFocusRect(hDC, &Rect);
  446. }
  447. ButtonDrawPushText(pCxp,hDC,rc);
  448. Mdcxp.bTransfer = TRUE;
  449. ReleaseMemDCXP(&Mdcxp);
  450. }
  451. ////////////////////////////////////////////////////////////////////////////////////////////////////
  452. ////////////////////////////////////////////////////////////////////////////////////////////////////
  453. // 绘制复选框
  454. VOID WINAPI ButtonDrawCheckBoxXP(PCLASSXP pCxp)
  455. {
  456. int i;
  457. RECT Rect, rcText;
  458. MEMDCXP Mdcxp;
  459. HANDLE hHandle;
  460. char szTemp[256];
  461. COLORREF crColor;
  462. DWORD dwStyle;
  463. HDC hDC;
  464. /* static COLORREF s_crGradientXP[][4] =
  465. {
  466. {0x00A5B2B5, 0x00CED7D6, 0x00CED7D6, 0x00DEEFF7},
  467. {0x00CEF3FF, 0x0063CBFF, 0x0063CBFF, 0x0031B2FF},
  468. {0x00D6DFDE, 0x00EFF3F7, 0x00EFF3F7, 0x00FFFFFF}
  469. };
  470. */
  471. // 获取内存兼容设备场景
  472. Mdcxp.hWnd = pCxp->hWnd;
  473. Mdcxp.bTransfer = FALSE;
  474. Mdcxp.hBitmap = NULL;
  475. GetMemDCXP(&Mdcxp);
  476. hDC = Mdcxp.hMemDC;
  477. // 获取窗口大小
  478. GetWindowRect(pCxp->hWnd, &Rect);
  479. Rect.right -= Rect.left;
  480. Rect.bottom -= Rect.top;
  481. Rect.left = Rect.top = 0;
  482. // 填充背景
  483. // FillRect(hDC, &Rect, GetSysColorBrush(g_crDialogbkColor));
  484. hHandle = CreateSolidBrush(g_crDialogbkColor);
  485. FillRect(hDC,&Rect, (HBRUSH)hHandle);
  486. DeleteObject(hHandle);
  487. //按显示模式调整位置
  488. dwStyle = GetWindowLong(pCxp->hWnd, GWL_STYLE);
  489. if (dwStyle & BS_LEFTTEXT)
  490. {
  491. rcText = Rect;
  492. rcText.right -= 18;
  493. Rect.left = Rect.right - 13;
  494. Rect.top = (Rect.bottom - 13) / 2;
  495. Rect.bottom = Rect.top + 13;
  496. }
  497. else
  498. {
  499. rcText = Rect;
  500. rcText.left += 18;
  501. Rect.left = 0;
  502. Rect.right = 13;
  503. Rect.top = (Rect.bottom - 13) / 2;
  504. Rect.bottom = Rect.top + 13;
  505. }
  506. // 画最外面的框
  507. hHandle = (HANDLE) CreateSolidBrush(
  508. (pCxp->dwState & CXPS_DISABLED) ? (GetSysColor(COLOR_BTNFACE) - 0x00202020) : 0x00845118);
  509. FrameRect(Mdcxp.hMemDC, &Rect, (HBRUSH) hHandle);
  510. DeleteObject((HGDIOBJ) hHandle);
  511. // 画热点框渐变背景
  512. InflateRect(&Rect, -1, -1);
  513. if (!(pCxp->dwState & CXPS_DISABLED))
  514. // FillRect(hDC, &Rect, (HBRUSH)GetStockObject(WHITE_BRUSH));
  515. // else
  516. {
  517. if (pCxp->dwState & CXPS_PRESSED)
  518. i = 0;
  519. else if (pCxp->dwState & CXPS_HOTLIGHT)
  520. i = 1;
  521. else
  522. i = 2;
  523. GradientRectXP(hDC, &Rect, gChecks_crGradientXP[i]);
  524. }
  525. // 画内框
  526. InflateRect(&Rect, -2, -2);
  527. if ((pCxp->dwState & CXPS_INDETERMINATE) ||
  528. ((pCxp->dwState & CXPS_HOTLIGHT) && (!(pCxp->dwState & CXPS_PRESSED))))
  529. {
  530. if (pCxp->dwState & CXPS_INDETERMINATE)
  531. {
  532. if (pCxp->dwState & CXPS_DISABLED)
  533. crColor = 0x00BDCBCE;
  534. else if (pCxp->dwState & CXPS_PRESSED)
  535. crColor = 0x00188A18;
  536. else if (pCxp->dwState & CXPS_HOTLIGHT)
  537. crColor = 0x0021A221;
  538. else
  539. crColor = 0x0073C373;
  540. }
  541. else if (pCxp->dwState & CXPS_CHECKED)
  542. crColor = 0x00F7F7F7;
  543. else
  544. crColor = 0x00E7E7E7;
  545. hHandle = (HANDLE) CreateSolidBrush(crColor);
  546. FillRect(hDC, &Rect, (HBRUSH) hHandle);
  547. DeleteObject((HGDIOBJ) hHandle);
  548. }
  549. // 画框内选中标志
  550. if (pCxp->dwState & CXPS_CHECKED)
  551. {
  552. hHandle = (HANDLE) SelectObject(hDC,
  553. CreatePen(PS_SOLID, 1, (pCxp->dwState & CXPS_DISABLED) ? 0x000BDCBCE : 0x0021A221));
  554. for (i = 3; i < 10; i++)
  555. {
  556. MoveToEx(hDC, Rect.left+i-3, Rect.top + ((i < 6) ? i - 1 : (9 - i)), NULL);
  557. LineTo(hDC, Rect.left+i-3, Rect.top + ((i < 6) ? i + 2 : (12 - i)));
  558. }
  559. DeleteObject(SelectObject(hDC,(HGDIOBJ) hHandle));
  560. }
  561. // 写文字
  562. if (GetWindowText(pCxp->hWnd, szTemp, sizeof(szTemp)))
  563. {
  564. SetTextColor(hDC, GetSysColor((pCxp->dwState & CXPS_DISABLED) ? COLOR_GRAYTEXT: COLOR_BTNTEXT));
  565. hHandle = (HANDLE) SelectObject(hDC,
  566. (HGDIOBJ) SendMessage(pCxp->hWnd, WM_GETFONT, 0, 0));
  567. rcText.bottom = rcText.top + 1 + DrawText(hDC, szTemp, -1, &rcText,
  568. DT_CALCRECT | DT_SINGLELINE | DT_VCENTER);
  569. DrawText(hDC, szTemp, -1, &rcText, DT_SINGLELINE | DT_VCENTER);
  570. SelectObject(hDC, (HGDIOBJ) hHandle);
  571. // 如果有焦点,画出焦点框
  572. if (pCxp->dwState & CXPS_FOCUS)
  573. {
  574. InflateRect(&rcText, 0, -1);
  575. DrawFocusRect(hDC, &rcText);
  576. }
  577. }
  578. Mdcxp.bTransfer = TRUE;
  579. ReleaseMemDCXP(&Mdcxp);
  580. }
  581. ////////////////////////////////////////////////////////////////////////////////////////////////////
  582. ////////////////////////////////////////////////////////////////////////////////////////////////////
  583. // 绘制单选框
  584. VOID WINAPI ButtonDrawRadioBoxXP(PCLASSXP pCxp)
  585. {
  586. RECT Rect,rc, rcText;
  587. MEMDCXP Mdcxp;
  588. HANDLE hHandle, hPen;
  589. char szTemp[256];
  590. COLORREF crColor;
  591. DWORD dwStyle;
  592. // UINT uFormat;
  593. HDC hDC;
  594. /* static COLORREF s_crGradientXP[][4] =
  595. {
  596. {0x00A5B2B5, 0x00CED7D6, 0x00CED7D6, 0x00DEEFF7},
  597. {0x00CEF3FF, 0x0063CBFF, 0x0063CBFF, 0x0031B2FF},
  598. {0x00D6DFDE, 0x00EFF3F7, 0x00EFF3F7, 0x00FFFFFF},
  599. {0x0021A221, 0x0021A221, 0x00187A18, 0x00187A18},
  600. {0x00FFEBE7, 0x00F7CBAD, 0x00FF350B, 0x00F7CBAD},
  601. };
  602. */
  603. // 获取内存兼容设备场景
  604. Mdcxp.hWnd = pCxp->hWnd;
  605. Mdcxp.bTransfer = FALSE;
  606. Mdcxp.hBitmap = NULL;
  607. GetMemDCXP(&Mdcxp);
  608. hDC = Mdcxp.hMemDC;
  609. // 获取窗口大小
  610. GetWindowRect(pCxp->hWnd, &Rect);
  611. Rect.right -= Rect.left;
  612. Rect.bottom -= Rect.top;
  613. Rect.left = Rect.top = 0;
  614. // 填充背景
  615. // FillRect(hDC, &Rect, GetSysColorBrush(g_crDialogbkColor));
  616. hHandle = CreateSolidBrush(g_crDialogbkColor);
  617. FillRect(hDC,&Rect, (HBRUSH)hHandle);
  618. DeleteObject(hHandle);
  619. //按显示模式调整位置
  620. dwStyle = GetWindowLong(pCxp->hWnd, GWL_STYLE);
  621. if (dwStyle & BS_LEFTTEXT)
  622. {
  623. rcText = Rect;
  624. rcText.right -= 15;
  625. Rect.left = Rect.right-15;
  626. Rect.top = (Rect.bottom -15)/2;
  627. Rect.bottom = Rect.top + 15;
  628. rc = Rect;
  629. }
  630. else
  631. {
  632. rcText = Rect;
  633. rcText.left += 15;
  634. Rect.right = 15;
  635. Rect.top = (Rect.bottom -15)/2;
  636. Rect.bottom = Rect.top + 15;
  637. rc = Rect;
  638. }
  639. // 画热点框渐变背景
  640. if (!(pCxp->dwState & CXPS_DISABLED))
  641. // FillRect(hDC, &rc,(HBRUSH)GetStockObject(WHITE_BRUSH));
  642. // else
  643. {
  644. if (pCxp->dwState & CXPS_PRESSED)
  645. GradientRectXP(hDC, &rc, gChecks_crGradientXP[0]);
  646. else if (pCxp->dwState & CXPS_HOTLIGHT)
  647. GradientRectXP(hDC, &rc, gChecks_crGradientXP[1]);
  648. }
  649. // 画内框
  650. InflateRect(&rc, -2, -2);
  651. if ((pCxp->dwState & CXPS_INDETERMINATE) ||
  652. ((pCxp->dwState & CXPS_HOTLIGHT) && (!(pCxp->dwState & CXPS_PRESSED))))
  653. {
  654. if (pCxp->dwState & CXPS_INDETERMINATE)
  655. {
  656. if (pCxp->dwState & CXPS_DISABLED)
  657. crColor = 0x00BDCBCE;
  658. else if (pCxp->dwState & CXPS_PRESSED)
  659. crColor = 0x00188A18;
  660. else if (pCxp->dwState & CXPS_HOTLIGHT)
  661. crColor = 0x0021A221;
  662. else
  663. crColor = 0x0073C373;
  664. }
  665. else if (pCxp->dwState & CXPS_CHECKED)
  666. crColor = 0x00F7F7F7;
  667. else
  668. crColor = 0x00E7E7E7;
  669. hHandle = (HANDLE) CreateSolidBrush(crColor);
  670. FillRect(hDC, &rc, (HBRUSH) hHandle);
  671. DeleteObject((HGDIOBJ) hHandle);
  672. }
  673. //空的背景色
  674. hHandle = SelectObject(hDC, GetStockObject(NULL_BRUSH));
  675. // 画框内选中标志
  676. if (pCxp->dwState & CXPS_CHECKED)
  677. {
  678. GradientRectXP(hDC, &rc, gChecks_crGradientXP[3]);
  679. hPen = SelectObject(hDC, CreatePen(PS_SOLID, 1, g_crDialogbkColor));
  680. Ellipse(hDC, Rect.left+3, Rect.top+3,Rect.left+12,Rect.top+12);
  681. Ellipse(hDC, Rect.left+4, Rect.top+4,Rect.left+11,Rect.top+11);
  682. DeleteObject(SelectObject(hDC,hPen));
  683. }
  684. //填充圆形背景色
  685. if (!(pCxp->dwState & CXPS_HOTLIGHT))
  686. {
  687. hPen = SelectObject(hDC,CreatePen(PS_SOLID, 3, g_crDialogbkColor));
  688. Ellipse(hDC, Rect.left, Rect.top,Rect.left+14,Rect.top+14);
  689. DeleteObject(SelectObject(hDC,hPen));
  690. }
  691. //画圆
  692. hPen = SelectObject(hDC, CreatePen(PS_SOLID, 1, (pCxp->dwState & CXPS_DISABLED) ? (GetSysColor(COLOR_BTNFACE) - 0x00202020) : 0x00845118));
  693. Ellipse(hDC, Rect.left+2, Rect.top+2,Rect.left+13,Rect.top+13);
  694. DeleteObject(SelectObject(hDC,hPen));
  695. //恢复背景色
  696. SelectObject(hDC, hHandle);
  697. // 画文字
  698. // uFormat = ButtonStyle2Format(dwStyle);
  699. if (GetWindowText(pCxp->hWnd, szTemp, sizeof(szTemp)))
  700. {
  701. SetTextColor(hDC, GetSysColor((pCxp->dwState & CXPS_DISABLED) ? COLOR_GRAYTEXT: COLOR_BTNTEXT));
  702. hHandle = (HANDLE) SelectObject(hDC,
  703. (HGDIOBJ) SendMessage(pCxp->hWnd, WM_GETFONT, 0, 0));
  704. DrawText(hDC, szTemp, -1, &rcText, dwStyle);
  705. SelectObject(hDC, (HGDIOBJ) hHandle);
  706. // 如果有焦点,画出焦点框
  707. if (pCxp->dwState & CXPS_FOCUS)
  708. {
  709. InflateRect(&rcText, -1, -1);
  710. DrawFocusRect(hDC, &rcText);
  711. }
  712. }
  713. //释放句柄
  714. Mdcxp.bTransfer = TRUE;
  715. ReleaseMemDCXP(&Mdcxp);
  716. }
  717. ////////////////////////////////////////////////
  718. //绘制组合框
  719. VOID WINAPI ButtonDrawGroupBoxXP(PCLASSXP pCxp)
  720. {
  721. RECT Rect;
  722. char szTemp[256];
  723. HANDLE hHandle,hBrush;
  724. DWORD dwStyle;
  725. //取设置句柄
  726. HDC hDC = GetWindowDC(pCxp->hWnd);
  727. // 获取窗口大小
  728. GetWindowRect(pCxp->hWnd, &Rect);
  729. Rect.right -= Rect.left;
  730. Rect.bottom -= Rect.top;
  731. Rect.left = Rect.top = 0;
  732. // 画最外面的框,颜色与系统按钮颜色一直
  733. hBrush = SelectObject(hDC, GetStockObject(NULL_BRUSH));
  734. RoundRect(hDC, Rect.left,Rect.top+6,Rect.right,Rect.bottom,
  735. 6,6);
  736. SelectObject(hDC, hBrush);
  737. // 写文字
  738. dwStyle = (DWORD)GetWindowLong(pCxp->hWnd, GWL_STYLE);
  739. if (GetWindowText(pCxp->hWnd, szTemp, sizeof(szTemp)))
  740. {
  741. SetTextColor(hDC,
  742. ((pCxp->dwState & CXPS_INDETERMINATE) || (pCxp->dwState & CXPS_DISABLED)) ?
  743. 0x0094A2A5: 0x00000000);
  744. hHandle = (HANDLE) SelectObject(hDC,
  745. (HGDIOBJ) SendMessage(pCxp->hWnd, WM_GETFONT, 0, 0));
  746. //DrawText(Mdcxp.hMemDC, szTemp, -1, &Rect, DT_CENTER | DT_SINGLELINE | DT_VCENTER);
  747. Rect.left+=5;
  748. DrawText(hDC, szTemp, -1, &Rect, DT_LEFT);
  749. SelectObject(hDC, (HGDIOBJ) hHandle);
  750. }
  751. //释放句柄
  752. ReleaseDC(pCxp->hWnd,hDC);
  753. }
  754. ////////////////////////////////////////////////
  755. //绘制说明条
  756. VOID WINAPI ButtonDrawStateBoxXP(PCLASSXP pCxp)
  757. {
  758. HICON hIcon;
  759. // HBITMAP hBmp;
  760. RECT Rect;
  761. char szTemp[256];
  762. HANDLE hHandle;
  763. DWORD dwStyle;
  764. int nSaveDC;
  765. HDC hDC = GetWindowDC(pCxp->hWnd);
  766. // 获取窗口大小
  767. // GetWindowRect(pCxp->hWnd, &Rect);
  768. // Rect.right -= Rect.left;
  769. // Rect.bottom -= Rect.top;
  770. // Rect.left = Rect.top = 0;
  771. nSaveDC = SaveDC(hDC);
  772. // 画文字
  773. dwStyle = (DWORD)GetWindowLong(pCxp->hWnd, GWL_STYLE);
  774. if(dwStyle & SS_ICON)
  775. {
  776. hIcon = (HICON)SendMessage(pCxp->hWnd,STM_GETICON,0L,0L);
  777. if(hIcon)
  778. DrawIcon(hDC, Rect.left, Rect.top, hIcon);
  779. }
  780. /* else if(dwStyle & SS_BITMAP)
  781. {
  782. hBmp = (HBITMAP)SendMessage(pCxp->hWnd,STM_GETIMAGE,IMAGE_BITMAP,0L);
  783. if(hBmp)
  784. DrawIconEx(hDC,0,0,(HICON)hBmp, Rect.right-Rect.left,
  785. Rect.bottom-Rect.top,0,0,DI_DEFAULTSIZE);
  786. // BitBlt(hDC,Rect.left,Rect.top,
  787. // Rect.right-Rect.left,Rect.bottom-Rect.top,
  788. // &hBmp,0,0,SRCCOPY);
  789. }
  790. */
  791. else
  792. {
  793. if (GetWindowText(pCxp->hWnd, szTemp, sizeof(szTemp)))
  794. {
  795. SetTextColor(hDC,
  796. ((pCxp->dwState & CXPS_INDETERMINATE) || (pCxp->dwState & CXPS_DISABLED)) ?
  797. 0x0094A2A5: 0x00000000);
  798. hHandle = (HANDLE) SelectObject(hDC,
  799. (HGDIOBJ) SendMessage(pCxp->hWnd, WM_GETFONT, 0, 0));
  800. //DrawText(Mdcxp.hMemDC, szTemp, -1, &Rect, DT_CENTER | DT_SINGLELINE | DT_VCENTER);
  801. DrawText(hDC, szTemp, -1, &Rect, dwStyle);
  802. SelectObject(hDC, (HGDIOBJ) hHandle);
  803. }
  804. }
  805. RestoreDC(hDC, nSaveDC );
  806. // ReleaseDC(pCxp->hWnd, hDC);
  807. } // End of OnDrawBackground
  808. ////////////////////////////////////////////////////////////////////////////////////////////////////
  809. LRESULT ButtonWindowProc(PCLASSXP pCxp, UINT message,WPARAM wParam, LPARAM lParam)
  810. {
  811. LONG lReturn, lFound;
  812. TRACKMOUSEEVENT Tme;
  813. HWND hParent;
  814. typedef VOID (WINAPI *DRAWXP)(PCLASSXP);
  815. static DRAWXP s_DrawXP[] =
  816. {
  817. ButtonDrawPushButtonXP,
  818. ButtonDrawCheckBoxXP,
  819. ButtonDrawRadioBoxXP,
  820. ButtonDrawGroupBoxXP,
  821. ButtonDrawStateBoxXP,
  822. };
  823. HWND hWnd = pCxp->hWnd;
  824. switch (message)
  825. {
  826. case WM_SETICON:
  827. return ButtonOnSetIcon(pCxp, wParam,lParam);
  828. case BM_SETSTYLE: // 按钮风格改变
  829. CXPM_SETSTATE(pCxp->dwState, CXPS_DEFAULT, wParam & BS_DEFPUSHBUTTON);
  830. s_DrawXP[pCxp->dwType](pCxp);
  831. break;
  832. case BM_SETSTATE: // 设置按钮状态
  833. lReturn = (LONG) CallWindowProc(pCxp->wpPrev, hWnd, message, wParam, lParam);
  834. CXPM_SETSTATE(pCxp->dwState, CXPS_PRESSED, wParam);
  835. s_DrawXP[pCxp->dwType](pCxp);
  836. return lReturn;
  837. case BM_SETCHECK: // 设置选中状态
  838. lReturn = (LONG) CallWindowProc(pCxp->wpPrev, hWnd, message, wParam, lParam);
  839. CXPM_SETSTATE(pCxp->dwState, CXPS_CHECKED, (wParam == BST_CHECKED));
  840. CXPM_SETSTATE(pCxp->dwState, CXPS_INDETERMINATE, (wParam == BST_INDETERMINATE));
  841. s_DrawXP[pCxp->dwType](pCxp);
  842. return lReturn;
  843. case WM_SETTEXT: // 设置窗口文本
  844. lReturn = (LONG) DefWindowProc(hWnd, message, wParam, lParam);
  845. s_DrawXP[pCxp->dwType](pCxp);
  846. return lReturn;
  847. case WM_PAINT: // 窗口重画
  848. // if(pCxp->dwType == CXPT_STATEBOX ||
  849. // pCxp->dwType == CXPT_GROUPBOX)
  850. lReturn = DefWindowProc(pCxp->hWnd, message, wParam, lParam);
  851. // else
  852. // lReturn = (LONG) CallWindowProc(pCxp->wpPrev, hWnd, message, wParam, lParam);
  853. s_DrawXP[pCxp->dwType](pCxp);
  854. return lReturn;
  855. case WM_LBUTTONUP:
  856. if(pCxp->dwType == CXPT_PUSHBUTTON)
  857. {
  858. ReleaseCapture();
  859. hParent = GetParent(hWnd);
  860. if(hParent != NULL) SendMessage(hParent,WM_COMMAND,MAKEWPARAM(GetDlgCtrlID(hWnd),BN_CLICKED),(LPARAM)hWnd);
  861. pCxp->dwState &= ~CXPS_PRESSED;
  862. s_DrawXP[pCxp->dwType](pCxp);
  863. return 0;
  864. }
  865. break;
  866. case WM_LBUTTONDOWN:
  867. case WM_LBUTTONDBLCLK:
  868. if(pCxp->dwType == CXPT_PUSHBUTTON)
  869. {
  870. SetFocus(hWnd);
  871. pCxp->dwState |= CXPS_PRESSED;
  872. s_DrawXP[pCxp->dwType](pCxp);
  873. return 0;
  874. }
  875. break;
  876. case WM_ERASEBKGND: //禁止check和radio按钮背景重绘
  877. if(pCxp->dwType == CXPT_CHECKBOX) return TRUE;
  878. if(pCxp->dwType == CXPT_RADIOBOX) return TRUE;
  879. if(pCxp->dwType == CXPT_STATEBOX) return TRUE;
  880. if(pCxp->dwType == CXPT_GROUPBOX) return TRUE;
  881. break;
  882. case WM_MOUSELEAVE: // 鼠标移出
  883. if (pCxp->dwState & CXPS_HOTLIGHT)
  884. {
  885. pCxp->dwState &= ~CXPS_HOTLIGHT;
  886. //s_DrawXP[pCxp->dwType](pCxp);
  887. lFound = 1;
  888. }
  889. if (pCxp->dwState & CXPS_PRESSED)
  890. {
  891. pCxp->dwState &= ~CXPS_PRESSED;
  892. lFound = 1;
  893. }
  894. s_DrawXP[pCxp->dwType](pCxp);
  895. return 0;
  896. }
  897. // 调用原来的回调函数
  898. lReturn = (LONG) CallWindowProc(pCxp->wpPrev, hWnd, message, wParam, lParam);
  899. // 对所有窗口相同的处理
  900. switch (message)
  901. {
  902. case WM_MOUSEMOVE: // 窗口移动
  903. if (((pCxp->dwState & CXPS_HOTLIGHT) == 0) && ((wParam & MK_LBUTTON) == 0))
  904. {
  905. pCxp->dwState |= CXPS_HOTLIGHT;
  906. s_DrawXP[pCxp->dwType](pCxp);
  907. // 追踪鼠标移出消息一次
  908. Tme.cbSize = sizeof(TRACKMOUSEEVENT);
  909. Tme.dwFlags = TME_LEAVE;
  910. Tme.hwndTrack = hWnd;
  911. TrackMouseEvent(&Tme);
  912. }
  913. break;
  914. /* case WM_MOUSELEAVE: // 鼠标移出
  915. lFound = 0;
  916. if (pCxp->dwState & CXPS_HOTLIGHT)
  917. {
  918. pCxp->dwState &= ~CXPS_HOTLIGHT;
  919. lFound = 1;
  920. }
  921. if (pCxp->dwState & CXPS_PRESSED)
  922. {
  923. pCxp->dwState &= ~CXPS_PRESSED;
  924. lFound = 1;
  925. }
  926. if(lFound) s_DrawXP[pCxp->dwType](pCxp);
  927. break;
  928. */
  929. case WM_ENABLE: // 窗口被设置为禁用或可用
  930. CXPM_SETSTATE(pCxp->dwState, CXPS_DISABLED, !wParam);
  931. s_DrawXP[pCxp->dwType](pCxp);
  932. break;
  933. case WM_SETFOCUS: // 获得焦点
  934. SendMessage((HWND)wParam, WM_KILLFOCUS,0,0);
  935. pCxp->dwState |= CXPS_FOCUS;
  936. s_DrawXP[pCxp->dwType](pCxp);
  937. break;
  938. case WM_KILLFOCUS: // 丢失焦点
  939. pCxp->dwState &= ~CXPS_FOCUS;
  940. s_DrawXP[pCxp->dwType](pCxp);
  941. break;
  942. case WM_NCDESTROY: // 窗口销毁
  943. DeleteClassXP(hWnd);
  944. }
  945. return lReturn;
  946. }
  947. /**************以下设置必需包含在每个子类中**********************/
  948. ////////////////////////////////////////////////////////////////////////////////////////////////////
  949. #ifdef __cplusplus
  950. }
  951. #endif // __cplusplus
  952. ////////////////////////////////////////////////////////////////////////////////////////////////////
  953. /*****************************************************************/