RTScrollControlContainer.cpp
上传用户:qhonly
上传日期:2013-06-10
资源大小:487k
文件大小:6k
源码类别:

界面编程

开发平台:

Visual C++

  1. // RTScrollControlContainer.cpp : 实现文件
  2. //
  3. #include "stdafx.h"
  4. #include "RTScrollControlContainer.h"
  5. // CRTScrollControlContainer
  6. IMPLEMENT_DYNAMIC(CRTScrollControlContainer, CWnd)
  7. CRTScrollControlContainer::CRTScrollControlContainer()
  8. {
  9. m_Control = NULL;
  10. }
  11. CRTScrollControlContainer::~CRTScrollControlContainer()
  12. {
  13. }
  14. BEGIN_MESSAGE_MAP(CRTScrollControlContainer, CWnd)
  15. ON_WM_HSCROLL()
  16. ON_WM_VSCROLL()
  17. ON_WM_SIZE()
  18. ON_WM_ERASEBKGND()
  19. END_MESSAGE_MAP()
  20. // CRTScrollControlContainer 消息处理程序
  21. void CRTScrollControlContainer::OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
  22. {
  23. m_Control->SendMessage(WM_HSCROLL,MAKEWPARAM(nSBCode,nPos),NULL);
  24. }
  25. void CRTScrollControlContainer::OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
  26. {
  27. m_Control->SendMessage(WM_VSCROLL,MAKEWPARAM(nSBCode,nPos),NULL);
  28. }
  29. BOOL CRTScrollControlContainer::Create(CWnd* pControl)
  30. {
  31. if(pControl == NULL)return FALSE;
  32. m_Control = pControl;
  33. CRect rtWnd;
  34. pControl->GetWindowRect(&rtWnd);
  35. pControl->GetParent()->ScreenToClient(&rtWnd);
  36. DWORD style = WS_CHILD|WS_VISIBLE;
  37. DWORD ExStyle = 0;
  38.     DWORD MoveStyle = 0;
  39. DWORD MoveExStyle = 0;
  40. DWORD ListStyle = pControl->GetStyle();
  41. DWORD ListExStyle = pControl->GetExStyle();
  42. if((ListStyle & WS_BORDER) == WS_BORDER)
  43. {
  44. style |= WS_BORDER;
  45. MoveStyle = WS_BORDER;
  46. }
  47. if((ListStyle & WS_DLGFRAME) == WS_DLGFRAME)
  48. {
  49. style |= WS_DLGFRAME;
  50. MoveStyle |= WS_DLGFRAME;
  51. }
  52. if((ListExStyle & WS_EX_CLIENTEDGE) == WS_EX_CLIENTEDGE)
  53. {
  54. ExStyle |= WS_EX_CLIENTEDGE;
  55. MoveExStyle |= WS_EX_CLIENTEDGE;
  56. }
  57. if((ListExStyle & WS_EX_STATICEDGE) == WS_EX_STATICEDGE)
  58. {
  59. ExStyle |= WS_EX_STATICEDGE;
  60. MoveExStyle |= WS_EX_STATICEDGE;
  61. }
  62. if((ListExStyle & WS_EX_WINDOWEDGE ) == WS_EX_WINDOWEDGE)
  63. {
  64. ExStyle |= WS_EX_WINDOWEDGE;
  65. MoveExStyle |= WS_EX_WINDOWEDGE;
  66. }
  67. if(!CreateEx(ExStyle,NULL,NULL,style,rtWnd,pControl->GetParent(),65535))return FALSE;
  68. pControl->SetParent(this);
  69. GetClientRect(&rtWnd);
  70. pControl->ModifyStyle(MoveStyle,0);
  71. pControl->ModifyStyleEx(MoveExStyle,0);
  72. m_VerScrollBar.Create(WS_CHILD|SBS_VERT,CRect(0,0,0,0),pControl->GetParent(),65535);
  73. m_HorScrollBar.Create(WS_CHILD|SBS_HORZ,CRect(0,0,0,0),pControl->GetParent(),65535);
  74. m_VerScrollBar.SetSizeArea(CRTScrollBar::AreaBottom);
  75. InitializeFlatSB(pControl->m_hWnd);
  76. FlatSB_EnableScrollBar(pControl->m_hWnd, SB_BOTH, ESB_DISABLE_BOTH);
  77. FlatSB_ShowScrollBar(pControl->m_hWnd,SB_BOTH,FALSE);
  78. ReSize();
  79. return 0;
  80. }
  81. void CRTScrollControlContainer::OnSize(UINT nType, int cx, int cy)
  82. {
  83. CWnd::OnSize(nType, cx, cy);
  84. if(!IsWindow(m_HorScrollBar.m_hWnd))return;
  85. if(!IsWindow(m_VerScrollBar.m_hWnd))return;
  86. if(!IsWindow(m_Control->m_hWnd))return;
  87. ReSize();
  88. }
  89. void CRTScrollControlContainer::ReSize(void)
  90. {
  91. if(m_Control == NULL)return;
  92. CRect rtWnd;
  93. GetClientRect(&rtWnd);
  94. CRect rtList;
  95. CRect rtVer;
  96. CRect rtHor;
  97. DWORD ListExStyle = m_Control->GetExStyle();
  98. int ScrollWidth = 0;
  99. int ScrollHeight = 0;
  100. if(m_VerScrollBar.IsWindowVisible())
  101. {
  102. ScrollWidth = GetSystemMetrics(SM_CXVSCROLL);
  103. }
  104. if(m_HorScrollBar.IsWindowVisible())
  105. {
  106. ScrollHeight = GetSystemMetrics(SM_CYHSCROLL);
  107. }
  108. if((ListExStyle & WS_EX_RIGHTSCROLLBAR) == WS_EX_RIGHTSCROLLBAR)
  109. {
  110. rtList.SetRect(rtWnd.left,rtWnd.top,rtWnd.right - ScrollWidth,rtWnd.bottom - ScrollHeight);
  111. rtVer.SetRect(rtList.right,rtWnd.top,rtWnd.right,rtWnd.bottom);
  112. rtHor.SetRect(rtWnd.left,rtList.bottom,rtList.right,rtWnd.bottom);
  113. }
  114. else
  115. {
  116. rtList.SetRect(rtWnd.left + ScrollWidth,rtWnd.top,rtWnd.right,rtWnd.bottom - ScrollHeight);
  117. rtVer.SetRect(rtWnd.left,rtWnd.top,rtList.left,rtWnd.bottom);
  118. rtHor.SetRect(rtList.left,rtList.bottom,rtWnd.right,rtWnd.bottom);
  119. }
  120. if(IsWindow(m_Control->m_hWnd))m_Control->MoveWindow(&rtList);
  121. if(IsWindow(m_VerScrollBar.m_hWnd))m_VerScrollBar.MoveWindow(&rtVer);
  122. if(IsWindow(m_HorScrollBar.m_hWnd))m_HorScrollBar.MoveWindow(&rtHor);
  123. }
  124. void CRTScrollControlContainer::SetHorPos(int pos, BOOL redraw)
  125. {
  126. m_HorScrollBar.SetPos(pos,redraw);
  127. }
  128. void CRTScrollControlContainer::SetVerRange(int nmin, int nmax,BOOL redraw)
  129. {
  130. DWORD style = m_Control->GetStyle();
  131. if((style & WS_VSCROLL) == WS_VSCROLL)
  132. {
  133. if(!m_VerScrollBar.IsWindowVisible())
  134. {
  135. m_VerScrollBar.ShowWindow(SW_SHOW);
  136. if(m_HorScrollBar.IsWindowVisible())
  137. {
  138. m_VerScrollBar.SetSizeArea(CRTScrollBar::AreaBottom);
  139. }
  140. else
  141. {
  142. m_VerScrollBar.SetSizeArea(CRTScrollBar::AreaNone);
  143. }
  144. ReSize();
  145. }
  146. }
  147. else
  148. {
  149. if(m_VerScrollBar.IsWindowVisible())
  150. {
  151. m_VerScrollBar.ShowWindow(SW_HIDE);
  152. ReSize();
  153. }
  154. }
  155. m_VerScrollBar.SetRange(nmin,nmax,redraw);
  156. }
  157. void CRTScrollControlContainer::SetVerPos(int pos, BOOL redraw)
  158. {
  159. m_VerScrollBar.SetPos(pos,redraw);
  160. }
  161. void CRTScrollControlContainer::SetHorRange(int nmin, int nmax,BOOL redraw)
  162. {
  163. DWORD style = m_Control->GetStyle();
  164. if((style & WS_HSCROLL) == WS_HSCROLL)
  165. {
  166. if(!m_HorScrollBar.IsWindowVisible())
  167. {
  168. m_HorScrollBar.ShowWindow(SW_SHOW);
  169. m_VerScrollBar.SetSizeArea(CRTScrollBar::AreaBottom);
  170. ReSize();
  171. }
  172. }
  173. else
  174. {
  175. if(m_HorScrollBar.IsWindowVisible())
  176. {
  177. m_HorScrollBar.ShowWindow(SW_HIDE);
  178. m_VerScrollBar.SetSizeArea(CRTScrollBar::AreaNone);
  179. ReSize();
  180. }
  181. }
  182. m_HorScrollBar.SetRange(nmin,nmax,redraw);
  183. }
  184. BOOL CRTScrollControlContainer::OnEraseBkgnd(CDC* pDC)
  185. {
  186. return TRUE;
  187. }
  188. BOOL CRTScrollControlContainer::PassMessage(HWND hWnd, UINT Message, WPARAM wParam, LPARAM lParam, LRESULT* lpResult)
  189. {
  190. return FALSE;
  191. }
  192. LRESULT CRTScrollControlContainer::WindowProc(UINT message, WPARAM wParam, LPARAM lParam)
  193. {
  194. if(message > WM_USER)
  195. {
  196. CWnd* pParent = GetParent();
  197. if(pParent != NULL)pParent->SendMessage(message,wParam,lParam);
  198. }
  199. return CWnd::WindowProc(message, wParam, lParam);
  200. }