EditXP.cpp 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. // EditXP.cpp: implementation of the EditXP 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 "EditXP.h"
  17. //////////////////////////////////////////////////////////////////////////////////////////////////
  18. // 全局变量
  19. extern HHOOK g_hPrevHookXP ; // 窗口消息 HOOK 句柄
  20. extern PCLASSXP g_pClassXP ; // 窗口的 CLASSXP 结构指针
  21. extern COLORREF g_crDialogbkColor; // 窗口背景颜色
  22. //////////////////////////////////////////////////////////////
  23. /****************************************************************/
  24. ////////////////////////////////////////////////////////////////////////////////////////////////////
  25. // 绘制编辑框
  26. VOID WINAPI EditDrawEditBoxXP(PCLASSXP pCxp)
  27. {
  28. HDC hDC;
  29. RECT Rect;
  30. LONG lExStyle;
  31. HANDLE hHandle;
  32. lExStyle = GetWindowLong(pCxp->hWnd, GWL_EXSTYLE);
  33. if ((GetWindowLong(pCxp->hWnd, GWL_STYLE) & WS_BORDER) ||
  34. (lExStyle & WS_EX_CLIENTEDGE) || (lExStyle & WS_EX_STATICEDGE))
  35. {
  36. // 由于绘制的东西很少,所以直接绘制而不使用 MEMDCXP 方式
  37. hDC = GetWindowDC(pCxp->hWnd);
  38. // 获取窗口大小
  39. GetWindowRect(pCxp->hWnd, &Rect);
  40. Rect.right -= Rect.left;
  41. Rect.bottom -= Rect.top;
  42. Rect.top = Rect.left = 0;
  43. // 绘制外框
  44. hHandle = (HANDLE) CreateSolidBrush(
  45. (pCxp->dwState & CXPS_DISABLED) ? (GetSysColor(COLOR_BTNFACE) - 0x00202020) : 0x00BD9E7B);
  46. FrameRect(hDC, &Rect, (HBRUSH) hHandle);
  47. DeleteObject((HGDIOBJ) hHandle);
  48. // 绘制内框
  49. if ((lExStyle & WS_EX_CLIENTEDGE) || (lExStyle & WS_EX_STATICEDGE))
  50. {
  51. InflateRect(&Rect, -1, -1);
  52. // hHandle = (HANDLE) GetSysColorBrush(
  53. // (pCxp->dwState & CXPS_DISABLED) || (pCxp->dwState & CXPS_READONLY) ? COLOR_BTNFACE : COLOR_WINDOW);
  54. if ((pCxp->dwState & CXPS_DISABLED) || (pCxp->dwState & CXPS_READONLY))
  55. hHandle = (HANDLE) GetSysColorBrush(COLOR_WINDOW);
  56. else
  57. hHandle = (HANDLE) GetSysColorBrush(g_crDialogbkColor);
  58. FrameRect(hDC, &Rect, (HBRUSH) hHandle);
  59. if ((lExStyle & WS_EX_CLIENTEDGE) && (lExStyle & WS_EX_STATICEDGE))
  60. {
  61. InflateRect(&Rect, -1, -1);
  62. FrameRect(hDC, &Rect, (HBRUSH)hHandle);
  63. }
  64. }
  65. // 释放设备场景
  66. ReleaseDC(pCxp->hWnd, hDC);
  67. }
  68. }
  69. ////////////////////////////////////////////////////////////////////////////////////////////////////
  70. LRESULT EditWindowProc(PCLASSXP pCxp, UINT message,WPARAM wParam, LPARAM lParam)
  71. {
  72. LONG lReturn;
  73. HWND hWnd = pCxp->hWnd;
  74. switch(message)
  75. {
  76. case WM_NCPAINT:
  77. case WM_PAINT:
  78. lReturn = (LONG) DefWindowProc(hWnd, message, wParam, lParam);
  79. EditDrawEditBoxXP(pCxp);
  80. return lReturn;
  81. case EM_SETREADONLY:
  82. CXPM_SETSTATE(pCxp->dwState, CXPS_READONLY, wParam);
  83. EditDrawEditBoxXP(pCxp);
  84. break;
  85. }
  86. // 调用原来的回调函数
  87. lReturn = (LONG) CallWindowProc(pCxp->wpPrev, hWnd, message, wParam, lParam);
  88. switch (message)
  89. {
  90. case WM_DESTROY: // 窗口销毁
  91. DeleteClassXP(hWnd);
  92. }
  93. return lReturn;
  94. return lReturn;
  95. }
  96. /**************以下设置必需包含在每个子类中**********************/
  97. //尾部
  98. #ifdef __cplusplus
  99. }
  100. #endif // __cplusplus
  101. /*****************************************************************/