📄 demodlg.cpp
字号:
// DemoDlg.cpp : implementation file
//
#include "stdafx.h"
#include "PropertySheetInDialog.h"
#include "DemoDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CDemoDlg dialog
CDemoDlg::CDemoDlg(CWnd* pParent /*=NULL*/)
: CDialog(CDemoDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CDemoDlg)
//}}AFX_DATA_INIT
}
void CDemoDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CDemoDlg)
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CDemoDlg, CDialog)
//{{AFX_MSG_MAP(CDemoDlg)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// EkCreateEmbeddedPropertySheet
BOOL EkCreateEmbeddedPropertySheet( 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 failed\n" );
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;
}
/////////////////////////////////////////////////////////////////////////////
// EkPositionEmbeddedPropertySheet
void EkPositionEmbeddedPropertySheet( CWnd* pParent, CPropertySheet* pPSheet,
CRect rcNewPosition )
{
ASSERT_VALID( pParent );
ASSERT_VALID( pPSheet );
// 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( rcNewPosition .left, rcNewPosition.top,
rcNewPosition .Width(), rcNewPosition.Height() );
// 4 - Resize tab control window to restore
// right / bottom margins
pTabCtrl->SetWindowPos( NULL,
0, 0,
rcNewPosition.Width() - dcx,
rcNewPosition.Height() - dcy,
SWP_NOZORDER | SWP_NOMOVE | SWP_NOACTIVATE );
// 5 - Activate each property page to prevent drawing
// problem
int nCurrentPage = pPSheet->GetActiveIndex();
for( int i = 0; i < pPSheet->GetPageCount(); ++i )
{
pPSheet->SetActivePage( i );
}
pPSheet->SetActivePage( nCurrentPage );
}
void EkPositionEmbeddedPropertySheet( 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
EkPositionEmbeddedPropertySheet( pParent, pPSheet, rcNewPosition );
}
/////////////////////////////////////////////////////////////////////////////
// CDemoDlg message handlers
BOOL CDemoDlg::OnInitDialog()
{
CDialog::OnInitDialog();
EkCreateEmbeddedPropertySheet( this, &m_psheet );
EkPositionEmbeddedPropertySheet( this, &m_psheet, IDC_PSHEET_AREA );
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
void CDemoDlg::OnOK()
{
m_psheet.GetActivePage()->UpdateData( TRUE );
CDialog::OnOK();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -