深入浅出 CPropertySheet,深入浅出 CPropertySheet
【 tulaoshi.com - C语言心得技巧 】
深入浅出 CPropertySheet
译者:徐景周(原作:Mustafa Demirhan)
为了最大限度的发挥属性页的效用,首先让我们先从 CPropertySheet 继承一个新类,取名为 CMyPropSheet.
接着便可以进行下面的各种操作:
一、隐藏属性页默认按钮
隐藏掉Apply应用按钮:
propsheet.m_psh.dwFlags |= PSH_NOAPPLYNOW;或隐藏掉Cancel取消按钮:
CWnd *pWnd = GetDlgItem( IDCANCEL );pWnd->ShowWindow( FALSE );二、移动属性页按钮
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 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);五、在属性页标签上显示位图
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 );
来源:http://www.tulaoshi.com/n/20160129/1484277.html
看过《深入浅出 CPropertySheet》的人还看了以下文章 更多>>