当前位置: 首页 > 图文教程 > 开发语言 > VC++ > 深入浅出 CPropertySheet

VC++
如何隐藏显示在任务栏中的对话框程序
一个效果很好的outlookbar控件CXTOutBarCtrl
如何在对话框程序中使用动画控件
形态各异的不规则窗体
支持换肤功能的窗口实例
如何给基于对话框的应用加启动画面
Convert CHtmlView to CHtmlCtrl(View与Frame的分离)
《Windows 程序设计》学习笔记(四)
如何模拟《WORD》的窗口形式
如何按非客户区移动窗体
仿制金山毒霸专杀工具界面
在对话框程序中插入DialogBar
接触VC之三:MFC基于对话框程序
无标题栏对话框的拖动
MFC框架程序中全屏显示特性的实现
给你的应用程序添加动态鼠标
在MFC程序中添加全屏显示功能
制作类似网络蚂蚁的拉帘式Tab
如何有效的使用对话框之二
IE控制条的实现

VC++ 中的 深入浅出 CPropertySheet


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-10-30   浏览: 109 ::
收藏到网摘: n/a

深入浅出 CPropertySheet
译者:徐景周(原作:Mustafa Demirhan)

为了最大限度的发挥属性页的效用,首先让我们先从 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;}

下面代码移动所有按钮到右侧,并且重新置属性页为合适的大小.
BOOL CMyPropSheet::OnInitDialog () { BOOL bResult = CPropertySheet::OnInitDialog(); int ids[] = { IDOK, IDCANCEL, ID_APPLY_NOW }; CRect rectWnd; CRect rectBtn; GetWindowRect (rectWnd); GetDlgItem (IDOK)->GetWindowRect (rectBtn); int btnWidth = rectBtn.Width(); int btnHeight = rectBtn.Height(); int btnOffset = rectWnd.bottom - rectBtn.bottom; int btnLeft = rectWnd.right - rectWnd.left; rectWnd.bottom = rectBtn.top; rectWnd.right = rectWnd.right + btnWidth + btnOffset; MoveWindow(rectWnd); rectBtn.left = btnLeft; rectBtn.right = btnLeft + btnWidth; for (int i = 0; i < sizeof (ids) / sizeof (int); i++) { rectBtn.top = (i + 1) * btnOffset + btnHeight * i; rectBtn.bottom = rectBtn.top + btnHeight; GetDlgItem (ids [i])->MoveWindow (rectBtn); } return bResult;}

三、改变属性页上的标签文字

首先修改TC_ITEM结构,然后用 SetItem 来修改标签文字,如下代码:
TC_ITEM item;item.mask = TCIF_TEXT;item.pszText = "New Label";//Change the label of the first tab (0 is the index of the first tab)...GetTabControl ()->SetItem (0, &item);
四、改变属性页标签文字的字体属性
代码如下
m_NewFont.CreateFont (14, 0, 0, 0, 800, TRUE, 0, 0, 1, 0, 0, 0, 0, _T("Arial") ); GetTabControl()->SetFont (&m_NewFont);
五、在属性页标签上显示位图
可以用 CImageList 建立图像. 用 SetItem 来设置,如下代码所示:
BOOL CMyPropSheet::OnInitDialog (){ BOOL bResult = CPropertySheet::OnInitDialog(); m_imageList.Create (IDB_MYIMAGES, 13, 1, RGB(255,255,255)); CTabCtrl *pTabCtrl = GetTabControl (); pTabCtrl->SetImageList (&m_imageList); TC_ITEM item; item.mask = TCIF_IMAGE; for (int i = 0; i < NUMBER_OF_TABS; i++) { item.iImage = i; pTabCtrl->SetItem (i, &item );