SheetInDlg.cpp
上传用户:hjw22cn
上传日期:2007-01-11
资源大小:192k
文件大小:5k
- // this file contains the functions necessary to place the property sheet into a dialog box.
- #include "stdafx.h"
- #include "SheetInDlg.h"
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- //-----------------------------------------------------------------------------/
- BOOL CreateDlgSheet(CWnd* pParent, CPropertySheet* pPSheet, DWORD dwStyle/*=WS_CHILD | WS_VISIBLE*/, DWORD dwExStyle/*=0*/)
- {
- ASSERT_VALID(pParent);
- ASSERT_VALID(pPSheet);
- // 1 - Create the embedded property sheet window
- if (!pPSheet->Create(pParent, dwStyle, dwExStyle))
- {
- TRACE0("Embedded property sheet creation failedn");
- return FALSE;
- }
- // 2 - Add WS_TABSTOP and WS_EX_CONTROLPARENT to the property sheet styles
- pPSheet->ModifyStyle(0, WS_TABSTOP);
- pPSheet->ModifyStyleEx(0, WS_EX_CONTROLPARENT);
- // 3 - Add WS_EX_CONTROLPARENT to the parent window styles
- pParent->ModifyStyleEx (0, WS_EX_CONTROLPARENT);
- return TRUE;
- }
- //-----------------------------------------------------------------------------/
- void MoveDlgSheet(CWnd* pParent, CPropertySheet* pPSheet, CRect rcNewPos)
- {
- ASSERT_VALID(pParent);
- ASSERT_VALID(pPSheet);
- // 0 - get the currently active page and set redraw to false. This
- // will keep the dialog box from flashing when it's resized
- int nCurrentPage = pPSheet->GetActiveIndex();
- pPSheet->SetRedraw(FALSE);
- // 1 - Get current coordinates of tab control
- // and property sheet window
- CTabCtrl* pTabCtrl = pPSheet->GetTabControl();
- ASSERT(pTabCtrl != NULL);
- CRect rcTabCtrl;
- pTabCtrl->GetWindowRect(&rcTabCtrl);
- pParent->ScreenToClient(&rcTabCtrl);
- CRect rcPSheet;
- pPSheet->GetWindowRect(&rcPSheet);
- pParent->ScreenToClient(&rcPSheet);
- // 2 - Calculate margin between property sheet
- // and tab control
- int dcx = rcPSheet.Width() - rcTabCtrl.Width();
- int dcy = rcPSheet.Height() - rcTabCtrl.Height();
- // 3 - Move and resize property sheet window
- // (also moves the tab window because it is a child
- // of the property sheet window)
- pPSheet->MoveWindow(rcNewPos.left, rcNewPos.top, rcNewPos.Width(), rcNewPos.Height());
- // 4 - Resize tab control window to restore
- // right / bottom margins
- pTabCtrl->SetWindowPos(NULL,
- 0, 0,
- rcNewPos.Width() - dcx, rcNewPos.Height() - dcy,
- SWP_NOZORDER | SWP_NOMOVE | SWP_NOACTIVATE );
- // 5 - turn the drawing back on now, and invalidate the whole dialog
- pPSheet->SetRedraw(TRUE);
- pParent->Invalidate();
- // now reset the active page
- pPSheet->SetActivePage(nCurrentPage);
- }
- //-----------------------------------------------------------------------------/
- void MoveDlgSheet(CWnd* pParent, CPropertySheet* pPSheet, UINT nIDPSheetArea )
- {
- ASSERT_VALID(pParent);
- ASSERT_VALID(pPSheet);
- // 1 - Retrieve property sheet destination position
- CRect rcNewPosition;
- CWnd* pWndNewArea = pParent->GetDlgItem(nIDPSheetArea);
- if (pWndNewArea == NULL)
- {
- ASSERT(FALSE); // Invalid nIDPSheetArea
- return;
- }
- pWndNewArea->GetWindowRect(&rcNewPosition);
- pParent->ScreenToClient(&rcNewPosition);
- // 2 - Call overloaded function
- MoveDlgSheet(pParent, pPSheet, rcNewPosition);
- }
- void MoveWndSheet(CWnd* pParent, CPropertySheet* pPSheet, CRect rcNewPos)
- {
- ASSERT_VALID(pParent);
- ASSERT_VALID(pPSheet);
- // 0 - get the currently active page and set redraw to false. This
- // will keep the dialog box from flashing when it's resized
- int nCurrentPage = pPSheet->GetActiveIndex();
- pPSheet->SetRedraw(FALSE);
- // 1 - Get current coordinates of tab control
- // and property sheet window
- CTabCtrl* pTabCtrl = pPSheet->GetTabControl();
- ASSERT(pTabCtrl != NULL);
- CRect rcTabCtrl;
- pTabCtrl->GetWindowRect(&rcTabCtrl);
- pParent->ScreenToClient(&rcTabCtrl);
- CRect rcPSheet;
- pPSheet->GetWindowRect(&rcPSheet);
- pParent->ScreenToClient(&rcPSheet);
- // 2 - Calculate margin between property sheet
- // and tab control
- int dcx = rcPSheet.Width() - rcTabCtrl.Width();
- int dcy = rcPSheet.Height() - rcTabCtrl.Height();
- // 3 - Move and resize property sheet window
- // (also moves the tab window because it is a child
- // of the property sheet window)
- pPSheet->MoveWindow(rcNewPos.left, rcNewPos.top, rcNewPos.Width(), rcNewPos.Height());
- // 4 - Resize tab control window to restore
- // right / bottom margins
- pTabCtrl->SetWindowPos(NULL,
- 0, 0,
- rcNewPos.Width() - dcx, rcNewPos.Height() - dcy,
- SWP_NOZORDER | SWP_NOMOVE | SWP_NOACTIVATE );
- // 5 - turn the drawing back on now, and invalidate the whole dialog
- pPSheet->SetRedraw(TRUE);
- pParent->Invalidate();
- // now reset the active page
- pPSheet->SetActivePage(nCurrentPage);
- }