📄 demopsheet.cpp
字号:
// DemoPSheet.cpp : implementation file
//
#include "stdafx.h"
#include "ManageButtons.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
m_bChangeCaptions = TRUE;
}
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()
///////////////////////////////////////////////////////////
// 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();
if( m_bChangeCaptions )
{
// Change "OK" button caption
CWnd* pWnd = GetDlgItem( IDOK );
ASSERT( pWnd != NULL );
pWnd->SetWindowText( _T( "Accept" ) );
// Change "Cancel" button caption
pWnd = GetDlgItem( IDCANCEL );
ASSERT( pWnd != NULL );
pWnd->SetWindowText( _T( "Revert" ) );
// Change "Apply" button caption
pWnd = GetDlgItem( ID_APPLY_NOW );
ASSERT( pWnd != NULL );
pWnd->SetWindowText( _T( "Apply Now" ) );
}
else
{
// Hide "Cancel" and "Apply" buttons
EkHidePropertySheetButtons( this, FALSE, TRUE, TRUE );
// Center "OK" button in property sheet
EkCenterPropertySheetButtons( this, TRUE, FALSE, FALSE );
}
return bResult;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -