深入浅出 CPropertySheet

豆豆包饭

豆豆包饭

2016-01-29 12:01

深入浅出 CPropertySheet,深入浅出 CPropertySheet

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

(本文来源于图老师网站,更多请访问https://m.tulaoshi.com/cyuyanjiaocheng/)

为了最大限度的发挥属性页的效用,首先让我们先从 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 );      
展开更多 50%)
分享

猜你喜欢

深入浅出 CPropertySheet

C语言教程 C语言函数
深入浅出 CPropertySheet

Singleton深入浅出

电脑网络
Singleton深入浅出

s8lol主宰符文怎么配

英雄联盟 网络游戏
s8lol主宰符文怎么配

ActiveX深入浅出(二)

Web开发
ActiveX深入浅出(二)

网页制作深入浅出

Web开发
网页制作深入浅出

lol偷钱流符文搭配推荐

英雄联盟 网络游戏
lol偷钱流符文搭配推荐

深入浅出谈防火墙

电脑网络
深入浅出谈防火墙

深入浅出MySQL双向复制技术

编程语言 网络编程
深入浅出MySQL双向复制技术

lolAD刺客新符文搭配推荐

英雄联盟
lolAD刺客新符文搭配推荐

如何在状态栏中实现进度指示器控制

如何在状态栏中实现进度指示器控制

《高达破坏者2》光束全弹与实弹全弹适用部件研究

《高达破坏者2》光束全弹与实弹全弹适用部件研究
下拉加载更多内容 ↓