ScrollBarExt.cpp 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. // ScrollBarExt.cpp: implementation of the CScrollBarExt class.
  2. //
  3. //////////////////////////////////////////////////////////////////////
  4. #include "stdafx.h"
  5. #include "ScrollBarExt.h"
  6. #ifdef _DEBUG
  7. #undef THIS_FILE
  8. static char THIS_FILE[]=__FILE__;
  9. #define new DEBUG_NEW
  10. #endif
  11. WNDPROC CScrollBarExt::m_cWndProc = NULL;
  12. int CScrollBarExt::pos = 0;
  13. //////////////////////////////////////////////////////////////////////
  14. // Construction/Destruction
  15. //////////////////////////////////////////////////////////////////////
  16. LRESULT CScrollBarExt::DefWindowProc( HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam )
  17. {
  18. switch( message )
  19. {
  20. case WM_PAINT:
  21. case WM_NCPAINT:
  22. case WM_LBUTTONDOWN:
  23. case WM_LBUTTONUP:
  24. case WM_MOUSEMOVE:
  25. CallWindowProc( m_cWndProc, hwnd, message, wParam, lParam );
  26. // ShowWindow(hwnd, SW_HIDE);
  27. OnPaint(hwnd);
  28. return 0;
  29. case WM_ERASEBKGND:
  30. return 1;
  31. default:
  32. break;
  33. }
  34. return CallWindowProc( m_cWndProc, hwnd, message, wParam, lParam );
  35. }
  36. void CScrollBarExt::OnPaint( HWND hWnd )
  37. {
  38. RECT rcItem;
  39. HDC hdc=GetWindowDC(hWnd);
  40. GetWindowRect(hWnd, &rcItem);
  41. rcItem.right -=rcItem.left ;
  42. rcItem.bottom -=rcItem.top ;
  43. rcItem.top =rcItem.left =0;
  44. const int nFrameSize = GetSystemMetrics( SM_CXEDGE );
  45. const int nScrollSize = GetSystemMetrics( SM_CXHSCROLL );
  46. RECT rc;
  47. if(rcItem.right >rcItem.bottom )//根据滚动的长宽判断是水平还是垂直..水平
  48. {
  49. rc.left = rcItem.left + nFrameSize;
  50. rc.top = rcItem.bottom - nFrameSize - nScrollSize;
  51. rc.right = rcItem.right - nFrameSize;
  52. rc.bottom = rcItem.bottom - nFrameSize;
  53. DrawScrollBar(hWnd, hdc, rc, SB_HORZ, 1 );
  54. }
  55. else
  56. {
  57. rc.left = rcItem.right - nFrameSize - nScrollSize; rc.top = rcItem.top + nFrameSize;
  58. rc.right = rcItem.right - nFrameSize; rc.bottom = rcItem.bottom - nFrameSize;
  59. DrawScrollBar(hWnd, hdc, rc, SB_VERT, 1 );
  60. }
  61. }