SpinBox.cpp 6.1 KB

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