PropPgFormView.cpp
上传用户:sisi1999
上传日期:2007-01-02
资源大小:39k
文件大小:6k
源码类别:

PropertySheet

开发平台:

Visual C++

  1. // PropPgFormView.cpp : implementation of the CPropPgFormView class
  2. //
  3. #include "stdafx.h"
  4. #include <../src/afximpl.h> // Get access to afxData
  5. #include "PropPgFormView.h"
  6. #include "resource.h"
  7. #ifdef _DEBUG
  8. #define new DEBUG_NEW
  9. #undef THIS_FILE
  10. static char THIS_FILE[] = __FILE__;
  11. #endif
  12. /////////////////////////////////////////////////////////////////////////////
  13. // CPropPgFormView
  14. IMPLEMENT_DYNCREATE(CPropPgFormView, CFormView)
  15. BEGIN_MESSAGE_MAP(CPropPgFormView, CFormView)
  16. //{{AFX_MSG_MAP(CPropPgFormView)
  17. ON_WM_SIZE()
  18. ON_WM_HSCROLL()
  19. ON_WM_VSCROLL()
  20. //}}AFX_MSG_MAP
  21. END_MESSAGE_MAP()
  22. /////////////////////////////////////////////////////////////////////////////
  23. // CPropPgFormView construction/destruction
  24. CPropPgFormView::CPropPgFormView()
  25. : CFormView(IDD_VIEW_DLG), m_PS_Offset(PS_Y_OFFSET)
  26. {
  27. }
  28. CPropPgFormView::CPropPgFormView(UINT nIDTemplate)
  29. : CFormView(nIDTemplate), m_PS_Offset(PS_Y_OFFSET)
  30. {
  31. }
  32. CPropPgFormView::CPropPgFormView(LPCTSTR lpszTemplateName)
  33. : CFormView(lpszTemplateName), m_PS_Offset(PS_Y_OFFSET)
  34. {
  35. }
  36. CPropPgFormView::~CPropPgFormView()
  37. {
  38. }
  39. // overrides
  40. BOOL CPropPgFormView::Create(LPCTSTR lpszClassName, LPCTSTR lpszWindowName, DWORD dwStyle, const RECT& rect, CWnd* pParentWnd, UINT nID, CCreateContext* pContext) 
  41. {
  42. if (!CFormView::Create(lpszClassName, lpszWindowName, dwStyle, rect, pParentWnd, nID, pContext))
  43. return FALSE;
  44. m_sizeControl = GetMaxControl(); // get max control for placing prop sheet below
  45. return TRUE;
  46. }
  47. BOOL CPropPgFormView::PreTranslateMessage(MSG* pMsg) 
  48. {
  49. static BOOL bEntered = FALSE; // watch for re-entry from property sheet call to views PreTranslateMessage
  50. if (!bEntered) {
  51. BOOL bRet;
  52. bEntered = TRUE;
  53. bRet = m_PropSheet.PreTranslateMessage(pMsg);
  54. bEntered = FALSE;
  55. if (bRet)
  56. return TRUE;
  57. }
  58. return CFormView::PreTranslateMessage(pMsg);
  59. }
  60. // operations
  61. void CPropPgFormView::AdjustPropSheetPosition()
  62. {
  63. if (m_PropSheet.GetSafeHwnd()) {
  64. CRect rect;
  65. GetClientRect(&rect);
  66. rect.DeflateRect(-GetScrollPos(SB_HORZ), -GetScrollPos(SB_VERT) + m_sizeControl.cy + m_PS_Offset, 0, 0);
  67. m_PropSheet.MoveWindow(&rect);
  68. }
  69. }
  70. // resize frame window to encompass all controls
  71. // also sets scroll sizes
  72. //
  73. void CPropPgFormView::ResizeParentFrame()
  74. {
  75. CFrameWnd* pFrame = GetParentFrame();
  76. if (pFrame != NULL && m_PropSheet.GetSafeHwnd()) {
  77. // remove the 3d style from the frame, since the view is providing it.
  78. if (afxData.bWin4 && (GetExStyle() & WS_EX_CLIENTEDGE))
  79. ModifyStyleEx(WS_EX_CLIENTEDGE, 0, SWP_FRAMECHANGED);
  80. CRect rectFrame;
  81. CRect rectResized;
  82. CSize sizeScroll; // min scroll size
  83. pFrame->GetWindowRect(rectFrame);
  84. // compute right and bottom of frame for template controls and prop sheet
  85. rectResized.top = rectResized.left = 0;
  86. rectResized.right = m_sizeControl.cx;
  87. rectResized.bottom = m_sizeControl.cy;
  88. rectResized.right = max(m_sizeControl.cx, m_PropSheet.m_rectOriginal.right);
  89. rectResized.bottom += m_PS_Offset + m_PropSheet.m_rectOriginal.bottom;
  90. // adjust for sheet's tab
  91. CTabCtrl *pTab;
  92. pTab = m_PropSheet.GetTabControl();
  93. RECT rect;
  94. pTab->GetItemRect(1, &rect);
  95. rectResized.bottom -= (rect.bottom - rect .top);
  96.  
  97. sizeScroll.cx = rectResized.Width(); // save scroll size
  98. sizeScroll.cy = rectResized.Height();
  99. // adjust for border,menu,etc
  100. // NOTE: CalcWindowRect() does not correctly adjust for all styles, use AdjustWindowRectEx()
  101. //pFrame->CalcWindowRect(rectResized); // incorrect!!!
  102. DWORD st   = pFrame->GetStyle();
  103. DWORD exst = pFrame->GetExStyle();
  104. ::AdjustWindowRectEx(&rectResized, st, FALSE, exst);
  105. // move back to original frame origin
  106. rectResized.OffsetRect(rectFrame.left-rectResized.left, rectFrame.top-rectResized.top);
  107. CWnd* pParent = pFrame->GetParent();
  108. if (pParent)
  109. pParent->ScreenToClient(rectResized);
  110. pFrame->MoveWindow(rectResized);
  111. SetScrollSizes(MM_TEXT, sizeScroll);
  112. }
  113. }
  114. // determine the maximum extent of the forms controls.
  115. // NOTE: this is called in the Create function to gather the control extent of the
  116. // template-based controls and assigned to m_sizeControl.  Any app created controls will not
  117. // be reflected in m_sizeControl!
  118. // If you create new controls, 
  119. //
  120. CSize CPropPgFormView::GetMaxControl()
  121. {
  122. CSize size(0, 0);
  123. WINDOWPLACEMENT wp;
  124. CWnd *wnd = GetWindow(GW_CHILD);
  125. while (wnd) {
  126. wnd->GetWindowPlacement(&wp);
  127. if (wp.rcNormalPosition.right > size.cx)
  128. size.cx = wp.rcNormalPosition.right;
  129. if (wp.rcNormalPosition.bottom > size.cy)
  130. size.cy = wp.rcNormalPosition.bottom;
  131. wnd = wnd->GetNextWindow(GW_HWNDNEXT);
  132. }
  133. return size;
  134. }
  135. // call this function to set the horiz spacing between the bottom-most control on form and prop sheet
  136. void CPropPgFormView::SetPropertySheetOffset(int iOffset /* = PS_Y_OFFSET */, BOOL bRedraw /* = FALSE */)
  137. {
  138. m_PS_Offset = iOffset;
  139. if (bRedraw)
  140. ResizeParentFrame();
  141. }
  142. int CPropPgFormView::GetPropertySheetOffset()
  143. {
  144. return m_PS_Offset;
  145. }
  146. // call this function after adding new controls on the fly
  147. void CPropPgFormView::ResizeForNewControl()
  148. {
  149. m_sizeControl = GetMaxControl();
  150. ResizeParentFrame();
  151. }
  152. /////////////////////////////////////////////////////////////////////////////
  153. // CPropPgFormView diagnostics
  154. #ifdef _DEBUG
  155. void CPropPgFormView::AssertValid() const
  156. {
  157. CFormView::AssertValid();
  158. }
  159. void CPropPgFormView::Dump(CDumpContext& dc) const
  160. {
  161. CFormView::Dump(dc);
  162. }
  163. CPropPgFormDoc* CPropPgFormView::GetDocument() // non-debug version is inline
  164. {
  165. ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CPropPgFormDoc)));
  166. return (CPropPgFormDoc*)m_pDocument;
  167. }
  168. #endif //_DEBUG
  169. /////////////////////////////////////////////////////////////////////////////
  170. // CPropPgFormView message handlers
  171. void CPropPgFormView::OnSize(UINT nType, int cx, int cy) 
  172. {
  173. CFormView::OnSize(nType, cx, cy);
  174. AdjustPropSheetPosition();
  175. }
  176. void CPropPgFormView::OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar) 
  177. {
  178. CFormView::OnHScroll(nSBCode, nPos, pScrollBar);
  179. AdjustPropSheetPosition();
  180. }
  181. void CPropPgFormView::OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar) 
  182. {
  183. CFormView::OnVScroll(nSBCode, nPos, pScrollBar);
  184. AdjustPropSheetPosition();
  185. }
  186. void CPropPgFormView::OnInitialUpdate() 
  187. {
  188. ResizeParentFrame(); // resize frame to fit
  189. CFormView::OnInitialUpdate();
  190. }