SpinXP.cpp 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  1. // ListXP.cpp: implementation of the CListXP class.
  2. //
  3. //////////////////////////////////////////////////////////////////////
  4. /**************以下设置必需包含在每个子类中**********************/
  5. //头部
  6. ////////////////////////////////////////////////////////////////////////////////////////////////////
  7. // 编译预处理
  8. #if _WIN32_WINNT < 0x0400
  9. #define _WIN32_WINNT 0x0400
  10. #endif
  11. #if WINVER < 0x0500
  12. #define WINVER 0x0500
  13. #endif // WINVER < 0x0500
  14. // 强制使用 C 语言方式编译
  15. #ifdef __cplusplus
  16. extern "C"
  17. {
  18. #endif // __cplusplus
  19. #include "SpinXP.h"
  20. #include "ScrollXP.H"
  21. #include <CommCtrl.H>
  22. //////////////////////////////////////////////////////////////////////////////////////////////////
  23. // 全局变量
  24. extern HHOOK g_hPrevHookXP ; // 窗口消息 HOOK 句柄
  25. extern PCLASSXP g_pClassXP ; // 窗口的 CLASSXP 结构指针
  26. extern COLORREF g_crDialogbkColor; // 窗口背景颜色
  27. //////////////////////////////////////////////////////////////
  28. /****************************************************************/
  29. ////////////////////////////////////////////////////////////////////////////////////////////////////
  30. // 绘制旋转控件
  31. VOID WINAPI SpinDrawSpinBox(const PCLASSXP pCxp)
  32. {
  33. RECT Rect;
  34. int i;
  35. MEMDCXP Mdcxp;
  36. HANDLE hHandle;
  37. PCLASSXP pEditCxp;
  38. HDC hDC;
  39. HWND hWnd;
  40. // 获取内存兼容设备场景
  41. Mdcxp.hWnd = pCxp->hWnd;
  42. Mdcxp.bTransfer = FALSE;
  43. Mdcxp.hBitmap = NULL;
  44. GetMemDCXP(&Mdcxp);
  45. hWnd = pCxp->hWnd;
  46. // hDC = GetWindowDC(hWnd);
  47. hDC = Mdcxp.hMemDC;
  48. if(hDC == NULL) return;
  49. if((pCxp->dwState & CXPU_ALIGNLEFT) || (pCxp->dwState & CXPU_ALIGNRIGHT))
  50. {
  51. pEditCxp = GetClassXP((HWND) SendMessage(hWnd, UDM_GETBUDDY, 0, 0));
  52. CXPM_SETSTATE(pCxp->dwState, CXPS_DISABLED, pEditCxp->dwState & CXPS_DISABLED);
  53. }
  54. else
  55. pEditCxp = NULL;
  56. GetClientRect(hWnd, &Rect);
  57. if (pEditCxp)
  58. {
  59. #ifdef CXP_BKCOLOR
  60. // 绘制外框
  61. hHandle = (HANDLE) CreateSolidBrush(
  62. (pCxp->dwState & CXPS_DISABLED) ? (CXP_BKCOLOR - 0x00202020) : 0x00BD9E7B);
  63. #else // CXP_BKCOLOR
  64. // 绘制外框
  65. hHandle = (HANDLE) CreateSolidBrush(
  66. (pCxp->dwState & CXPS_DISABLED) ? (GetSysColor(COLOR_BTNFACE) - 0x00202020) : 0x00BD9E7B);
  67. #endif // CXP_BKCOLOR
  68. FrameRect(hDC, &Rect, (HBRUSH)hHandle);
  69. DeleteObject((HGDIOBJ) hHandle);
  70. #ifdef CXP_BKCOLOR
  71. hHandle = (HANDLE) SelectObject(hDC, CreatePen(PS_SOLID, 1,
  72. (pCxp->dwState & CXPS_DISABLED) || (pEditCxp->lState & CXPE_READONLY) ?
  73. CXP_BKCOLOR : GetSysColor(COLOR_WINDOW)));
  74. #else // CXP_BKCOLOR
  75. hHandle = (HANDLE) SelectObject(hDC, CreatePen(PS_SOLID, 1,
  76. GetSysColor((pCxp->dwState & CXPS_DISABLED) || (pEditCxp->dwState & CXPE_READONLY) ?
  77. COLOR_BTNFACE : COLOR_WINDOW)));
  78. #endif // CXP_BKCOLOR
  79. MoveToEx(hDC, (pCxp->dwState & CXPU_ALIGNLEFT) ? Rect.right - 1 : 0, 1, NULL);
  80. LineTo(hDC, (pCxp->dwState & CXPU_ALIGNLEFT) ? Rect.right - 1 : 0, Rect.bottom - 1);
  81. DeleteObject(SelectObject(hDC, hHandle));
  82. InflateRect(&Rect, -1, -1);
  83. }
  84. FillRect(hDC, &Rect, GetSysColorBrush(COLOR_WINDOW));
  85. InflateRect(&Rect, -1, -1);
  86. if (pCxp->dwState & CXPS_HORIZON)
  87. Rect.left += (Rect.right - Rect.left) / 2;
  88. else
  89. Rect.top += (Rect.bottom - Rect.top) / 2;
  90. i = pCxp->dwState | CXPH_SMALLARROW;
  91. if (pCxp->dwState & CXPU_UPPART)
  92. {
  93. i &= ~CXPS_HOTLIGHT;
  94. i &= ~CXPS_PRESSED;
  95. }
  96. i |= (pCxp->dwState & CXPS_HORIZON) ? CXPH_RIGHTWARDS : CXPH_DOWNWARDS;
  97. // DropThumbXP(Mdcxp.hMemDC, &Rect, i);
  98. ScrollDrowThumbXP(hDC, Rect, i);
  99. i = pCxp->dwState | CXPH_SMALLARROW;
  100. i |= (pCxp->dwState & CXPS_HORIZON) ? CXPH_LEFTWARDS : CXPH_UPWARDS;
  101. if (!(pCxp->dwState & CXPU_UPPART))
  102. {
  103. i &= ~CXPS_HOTLIGHT;
  104. i &= ~CXPS_PRESSED;
  105. }
  106. if (pCxp->dwState & CXPS_HORIZON)
  107. {
  108. Rect.right = Rect.left;
  109. Rect.left = pEditCxp ? 2 : 1;
  110. }
  111. else
  112. {
  113. Rect.bottom = Rect.top;
  114. Rect.top = pEditCxp ? 2: 1;
  115. }
  116. // DropThumbXP(Mdcxp.hMemDC, &Rect, i);
  117. ScrollDrowThumbXP(hDC, Rect, i);
  118. // 还原并释放内存设备场景
  119. Mdcxp.bTransfer = TRUE;
  120. ReleaseMemDCXP(&Mdcxp);
  121. // ReleaseDC(hWnd, hDC);
  122. }
  123. ////////////////////////////////////////////////////////////////////////////////////////////////////
  124. ////////////////////////////////////////////////////////////////////////////////////////////////////
  125. LRESULT SpinWindowProc(PCLASSXP pCxp, UINT message,WPARAM wParam, LPARAM lParam)
  126. {
  127. // SCROLLINFO sif;
  128. LONG lReturn;
  129. RECT Rect;
  130. HWND hWnd = pCxp->hWnd;
  131. switch (message)
  132. {
  133. case WM_PAINT:
  134. case WM_NCPAINT:
  135. SendMessage(hWnd,WM_SETREDRAW,FALSE,0);
  136. lReturn = (LONG) CallWindowProc(pCxp->wpPrev, hWnd, message, wParam, lParam);
  137. SendMessage(hWnd,WM_SETREDRAW,TRUE,0);
  138. SpinDrawSpinBox(pCxp);
  139. return lReturn;
  140. // return CXPC_DRAWCLASSXP | CXPC_PRECALLDEFPROC;
  141. case WM_LBUTTONDBLCLK:
  142. return TRUE;
  143. case WM_LBUTTONDOWN:
  144. pCxp->dwState |= CXPS_PRESSED;
  145. SendMessage(hWnd,WM_SETREDRAW,FALSE,0);
  146. lReturn = (LONG) CallWindowProc(pCxp->wpPrev, hWnd, message, wParam, lParam);
  147. SendMessage(hWnd,WM_SETREDRAW,TRUE,0);
  148. SpinDrawSpinBox(pCxp);
  149. return lReturn;
  150. // return CXPC_DRAWCLASSXP | CXPC_PRECALLWNDPROC;
  151. case WM_LBUTTONUP:
  152. pCxp->dwState &= ~CXPS_PRESSED;
  153. SendMessage(hWnd,WM_SETREDRAW,FALSE,0);
  154. lReturn = (LONG) CallWindowProc(pCxp->wpPrev, hWnd, message, wParam, lParam);
  155. SendMessage(hWnd,WM_SETREDRAW,TRUE,0);
  156. SpinDrawSpinBox(pCxp);
  157. return lReturn;
  158. // return CXPC_DRAWCLASSXP | CXPC_PRECALLWNDPROC;
  159. case WM_MOUSEMOVE:
  160. GetClientRect(hWnd, &Rect);
  161. if (pCxp->dwState & CXPU_UPPART)
  162. {
  163. if (((pCxp->dwState & CXPS_HORIZON) && (LOWORD(lParam) > Rect.right / 2)) ||
  164. (!(pCxp->dwState & CXPS_HORIZON) && (HIWORD(lParam) > Rect.bottom / 2)))
  165. {
  166. pCxp->dwState &= ~CXPU_UPPART;
  167. SendMessage(hWnd,WM_SETREDRAW,FALSE,0);
  168. lReturn = (LONG) CallWindowProc(pCxp->wpPrev, hWnd, message, wParam, lParam);
  169. SendMessage(hWnd,WM_SETREDRAW,TRUE,0);
  170. SpinDrawSpinBox(pCxp);
  171. return lReturn;
  172. // return CXPC_DRAWCLASSXP | CXPC_PRECALLWNDPROC | CXPC_CALLCOMMON;
  173. }
  174. }
  175. else
  176. {
  177. if (((pCxp->dwState & CXPS_HORIZON) && (LOWORD(lParam) <= Rect.right / 2)) ||
  178. (!(pCxp->dwState & CXPS_HORIZON) && (HIWORD(lParam) <= Rect.bottom / 2)))
  179. {
  180. pCxp->dwState |= CXPU_UPPART;
  181. SendMessage(hWnd,WM_SETREDRAW,FALSE,0);
  182. lReturn = (LONG) CallWindowProc(pCxp->wpPrev, hWnd, message, wParam, lParam);
  183. SendMessage(hWnd,WM_SETREDRAW,TRUE,0);
  184. SpinDrawSpinBox(pCxp);
  185. return lReturn;
  186. //return CXPC_DRAWCLASSXP | CXPC_PRECALLWNDPROC | CXPC_CALLCOMMON;
  187. }
  188. }
  189. return DefWindowProc(hWnd, message, wParam, lParam);
  190. // return CXPC_CALLCOMMON;
  191. case WM_ERASEBKGND:
  192. return TRUE;
  193. }
  194. /* switch (message)
  195. {
  196. case WM_PAINT:
  197. case WM_NCPAINT:
  198. pCxp->dwState |= CXPS_NOPAINT;
  199. lReturn = (LONG) CallWindowProc(pCxp->wpPrev, hWnd, message, wParam, lParam);
  200. SpinDrawSpinBoxXP(pCxp);
  201. return lReturn;
  202. }
  203. */
  204. // 调用原来的回调函数
  205. lReturn = (LONG) CallWindowProc(pCxp->wpPrev, hWnd, message, wParam, lParam);
  206. if (message == WM_NCDESTROY) // 窗口销毁
  207. DeleteClassXP(hWnd);
  208. return lReturn;
  209. }
  210. /**************以下设置必需包含在每个子类中**********************/
  211. //尾部
  212. #ifdef __cplusplus
  213. }
  214. #endif // __cplusplus
  215. /*****************************************************************/