Welcome

首页 / 软件开发 / C++ / 深入浅出CPropertySheet

深入浅出CPropertySheet2007-10-07徐景周为了最大限度的发挥属性页的效用,首先让我们先从 CPropertySheet 继承一个新类,取名为 CMyPropSheet.

接着便可以进行下面的各种操作:

一、隐藏属性页默认按钮

隐藏掉Apply应用按钮:

propsheet.m_psh.dwFlags |= PSH_NOAPPLYNOW;

或隐藏掉Cancel取消按钮:

CWnd *pWnd = GetDlgItem( IDCANCEL );
pWnd->ShowWindow( FALSE );

二、移动属性页按钮

首先,要获取按钮的句柄,然后就可以象对待窗体一样处理它们了. 下面代码先隐藏掉Apply和Help铵钮,再把OK和Cancel按移动到右侧。

BOOL CMyPropSheet::OnInitDialog ()
{
BOOL bResult = CPropertySheet::OnInitDialog();
int ids [] = {IDOK, IDCANCEL};//, ID_APPLY_NOW, IDHELP };

// Hide Apply and Help buttons
CWnd *pWnd = GetDlgItem (ID_APPLY_NOW);
pWnd->ShowWindow (FALSE);
pWnd = GetDlgItem (IDHELP);
pWnd->ShowWindow (FALSE);

CRect rectBtn;
int nSpacing = 6; // space between two buttons...
for( int i =0; i < sizeof(ids)/sizeof(int); i++)
{
GetDlgItem (ids [i])->GetWindowRect (rectBtn);

ScreenToClient (&rectBtn);
int btnWidth = rectBtn.Width();
rectBtn.left = rectBtn.left + (btnWidth + nSpacing)* 2;
rectBtn.right = rectBtn.right + (btnWidth + nSpacing)* 2;
GetDlgItem (ids [i])->MoveWindow(rectBtn);
}

return bResult;
}

下面代码移动所有按钮到右侧,并且重新置属性页为合适的大小.