📄 demopsheet.cpp
字号:
// DemoPSheet.cpp : implementation file
//
#include "stdafx.h"
#include "ResizePropertySheet.h"
#include "DemoPSheet.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CDemoPSheet
IMPLEMENT_DYNAMIC(CDemoPSheet, CPropertySheet)
CDemoPSheet::CDemoPSheet(CWnd* pParentWnd, UINT iSelectPage)
:CPropertySheet(IDS_PSHEET_CAPTION, pParentWnd, iSelectPage)
{
AddPage( &m_CoordsPPage ); // First page
AddPage( &m_ShapePPage ); // Second page
}
CDemoPSheet::~CDemoPSheet()
{
}
BEGIN_MESSAGE_MAP(CDemoPSheet, CPropertySheet)
//{{AFX_MSG_MAP(CDemoPSheet)
// NOTE - the ClassWizard will add and remove mapping macros here.
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
///////////////////////////////////////////////////////////
// EkResizePropertySheet
void EkResizePropertySheet( CPropertySheet* pPSheet, int nWidth )
{
ASSERT_VALID( pPSheet );
// 1 - Get current dimensions of tab control
// and property sheet window
CTabCtrl* pTabCtrl = pPSheet->GetTabControl();
ASSERT( pTabCtrl != NULL );
CRect rcTabCtrl;
pTabCtrl->GetWindowRect( &rcTabCtrl );
pPSheet->ScreenToClient( &rcTabCtrl );
CRect rcPSheet;
pPSheet->GetWindowRect( &rcPSheet );
// 2 - Compute resizing offset
int dcx = rcPSheet.Width() - nWidth;
// 3 - Resize property sheet window
pPSheet->SetWindowPos( NULL,
0, 0,
nWidth,
rcPSheet.Height(),
SWP_NOZORDER | SWP_NOMOVE | SWP_NOACTIVATE );
// 4 - Resize tab control window to restore
// right margin
pTabCtrl->SetWindowPos( NULL,
0, 0,
rcTabCtrl.Width() - dcx,
rcTabCtrl.Height(),
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 );
}
///////////////////////////////////////////////////////////
// EkHidePropertySheetButtons
void EkHidePropertySheetButtons( CPropertySheet* pPSheet,
BOOL bHideOK,
BOOL bHideCancel,
BOOL bHideApply )
{
ASSERT_VALID( pPSheet );
// Hide "OK" button
if( bHideOK )
{
CWnd* pWnd = pPSheet->GetDlgItem( IDOK );
ASSERT( pWnd != NULL );
pWnd->ShowWindow( SW_HIDE );
}
// Hide "Cancel" button
if( bHideCancel )
{
CWnd* pWnd = pPSheet->GetDlgItem( IDCANCEL );
ASSERT( pWnd != NULL );
pWnd->ShowWindow( SW_HIDE );
}
// Hide "Apply" button
if( bHideApply )
{
CWnd* pWnd = pPSheet->GetDlgItem( ID_APPLY_NOW );
ASSERT( pWnd != NULL );
pWnd->ShowWindow( SW_HIDE );
}
}
///////////////////////////////////////////////////////////
// EkCenterPropertySheetButtons
void EkCenterPropertySheetButtons( CPropertySheet* pPSheet,
BOOL bCenterOK,
BOOL bCenterCancel,
BOOL bCenterApply )
{
ASSERT_VALID( pPSheet );
ASSERT( bCenterOK || bCenterCancel || bCenterApply );
// Find "OK" button rectangle
CWnd* pWndOK = pPSheet->GetDlgItem( IDOK );
ASSERT( pWndOK != NULL );
CRect rcOK;
pWndOK->GetWindowRect( &rcOK );
pPSheet->ScreenToClient( &rcOK );
// Find "Cancel" button rectangle
CWnd* pWndCancel = pPSheet->GetDlgItem( IDCANCEL );
ASSERT( pWndCancel != NULL );
CRect rcCancel;
pWndCancel->GetWindowRect( &rcCancel );
pPSheet->ScreenToClient( &rcCancel );
// Find "Apply" button rectangle
CWnd* pWndApply = pPSheet->GetDlgItem( ID_APPLY_NOW );
ASSERT( pWndApply != NULL );
CRect rcApply;
pWndApply->GetWindowRect( &rcApply );
pPSheet->ScreenToClient( &rcApply );
// Find property sheet client rectangle
CRect rcClient;
pPSheet->GetClientRect( &rcClient );
// Compute layout values
int nButtonWidth = rcOK.Width();
int nButtonMargin = rcCancel.left - rcOK.right;
int nButtons = (bCenterOK ? 1 : 0) + (bCenterCancel ? 1 : 0)
+ (bCenterApply ? 1 : 0);
int nGlobalWidth = nButtonWidth * nButtons;
if( nButtons > 1 )
{
nGlobalWidth += nButtonMargin * (nButtons - 1);
}
int nCurrentX = ( rcClient.left + rcClient.right - nGlobalWidth ) / 2;
int nTop = rcOK.top;
// Center "OK" button
if( bCenterOK )
{
pWndOK->SetWindowPos( NULL,
nCurrentX,
nTop,
0, 0,
SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE );
nCurrentX += nButtonWidth + nButtonMargin;
}
// Center "Cancel" button
if( bCenterCancel )
{
pWndCancel->SetWindowPos( NULL,
nCurrentX,
nTop,
0, 0,
SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE );
nCurrentX += nButtonWidth + nButtonMargin;
}
// Center "Apply" button
if( bCenterApply )
{
pWndApply->SetWindowPos( NULL,
nCurrentX,
nTop,
0, 0,
SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE );
}
}
/////////////////////////////////////////////////////////////////////////////
// CDemoPSheet message handlers
BOOL CDemoPSheet::OnInitDialog()
{
BOOL bResult = CPropertySheet::OnInitDialog();
EkResizePropertySheet( this, 200 );
// Note : 200 width determined by trial and error
// Hide "Apply" button
EkHidePropertySheetButtons( this, FALSE, FALSE, TRUE );
// Center "OK" and "Cancel" buttons in property sheet
EkCenterPropertySheetButtons( this, TRUE, TRUE, FALSE );
return bResult;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -