CPropertySheet使用收集

来源:互联网 发布:京东抢购脚本 知乎 编辑:程序博客网 时间:2024/03/28 18:28

属性表/属性页定义   

使用集锦   

一、          按钮操作    2

1. 移动:    2

2. 隐藏:    2

3.移除按钮    2

4. 设置默认焦点按钮(响应Enter键按钮)    2

二、          属性页标签操作    3

1. 修改名字:    3

2. 改变字体    3

3.改变颜色    3

4. 显示位图    3

5. Disable 某个标签    4

三、          向导方式    4

1.       启用向导模式    4

2.       设置向导模式按钮    4

3.       启用Wizard97风格    4

4.       在属性页上显示Header Title/SubTitle  5

四、          在属性页中动态加入其它控件    6

五、          改变属性表大小    7

六、          消息处理    7

1. 属性页间通信    7

 

CPropertySheet/CPropertyPage使用集锦

属性页定义

[引至MSDN]属性表,也就是选项卡对话框,提供管理对话框中大量控件的方法。属性表包含属性页,每个属性页都基于单独的对话框模板资源。可将对话框控件分为逻辑组并将每个组放到各自的属性页上。

属性表基于CPropertySheet类, 属性页基于CPropertyPage类。

使用集锦

  一、     按钮操作

移动:

CRect rcMove; //根据需求,想要显示的位置
CWnd* pHelpButton = GetDlgItem(IDHELP);
pHelpButton->MoveWindow(rcMove);

隐藏:

//隐藏标准按钮

CWnd* pWnd = GetDlgItem(IDHELP);
if(pWnd)
{
  pWnd->ShowWindow(FALSE);
}

 

.移除按钮

移除Help按钮

mySheet.m_psh.dwFlags &= ~PSH_HASHELP;

OR

page1.m_psp.dwFlags &= ~PSP_HASHELP;

 

移除Apply按钮:

propsheet.m_psh.dwFlags |= PSH_NOAPPLYNOW;

Refer to: http://support.microsoft.com/kb/141039/en-us

 

 

 

设置默认焦点按钮(响应Enter键按钮)

mySheet.SendMessage (DM_SETDEFID, IDC_MYBUTTON);

Refer to:  http://support.microsoft.com/kb/140587/en-us

 

  二     属性页标签操作

修改名字:

Method1:(构造的时候设置)

m_Page1.Contrusct(L”My Label Name”)

 

Method2:

m_Page1->m_psp.dwFlags|=PSP_USETITLE;
m_Page1->m_psp.pszTitle=_T("My Label Name ");

 

Method3: (运行时设置)

TC_ITEM item;

item.mask = TCIF_TEXT;

item.pszText = L" My Label Name ";

 

//Change the label of the first tab (0 is the index of the first tab)...

GetTabControl ()->SetItem (0, &item);

Refer to: http://support.microsoft.com/kb/141487/en-us

 

改变字体

m_NewFont.CreateFont (14, 0, 0, 0, 800, TRUE, 0, 0, 1, 0, 0, 0, 0, _T("Arial") );

GetTabControl()->SetFont (&m_NewFont);

Refer tohttp://support.microsoft.com/kb/142170/en-us

 

 改变颜色

Refer tohttp://support.microsoft.com/kb/206626/en-us

 

显示位图

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;

item.iImage = iIndex; // the index of imagelist

//Change the label of the first tab (0 is the index of the first tab)...

pTabCtrl->SetItem (0, &item );

 

Disable某个标签

Refer tohttp://support.microsoft.com/kb/151662/en-us

 

  三     向导方式

   启用向导模式

mySheet.SetWizardMode(); //set this before DoModel

mySheet.DoModel();

 

   设置向导模式按钮

向导模式默认的标准按钮有:

IDHELP

IDCACEL

ID_WIZNEXT

ID_WIZBACK

ID_WIZFINISH(最后一个属性表上显示Finish按钮取代Next按钮)

mySheet.SetWizardButtons(DWORD dwFlags)

Refer to

ms-help://MS.VSCC.v80/MS.MSDN.v80/MS.VisualStudio.v80.en/dv_vclib/html/97484c08-23b6-4033-a441-22f3734be0c2.htm

 

风格

设置Wizard97风格及相应位图

m_psh.dwFlags |= PSH_WIZARD97|PSH_WATERMARK|PSH_HEADER;

m_psh.pszbmWatermark = MAKEINTRESOURCE(IDB_WATERMARK);//Watermark bitmap

//The bimap in the right of title

m_psh.pszbmHeader = MAKEINTRESOURCE(IDB_BANNER);

m_psh.hInstance = AfxGetInstanceHandle();

 

   在属性页上显示Header Title/SubTitle

m_psp.dwFlags |= PSP_DEFAULT|PSP_USEHEADERTITLE|PSP_USEHEADERSUBTITLE;

m_psp.pszHeaderTitle = L"Title: display title text here...";

m_psp.pszHeaderSubTitle = L"SubTitle: Display Sub Title here...";

 

 

Refer to:  http://windowssdk.msdn.microsoft.com/en-us/library/ms652417.aspx

  四、   在属性页中动态加入其它控件

e.g: 左下角加入一Edit控件

BOOL CMyPropSheet::OnInitDialog ()

{

    BOOL bResult = CPropertySheet::OnInitDialog ();

CRect rect;

    int nHeight = 24;

    int nWidth = 120;

    int nOffset = 6;

   

    GetClientRect (&rect);

// Find a bottom-left point for the edit control in the client area

    int nX = rect.left + nOffset;

    int nY = rect.top + (rect.Height() - nHeight) - nOffset;

   

    // finally create the edit control

    m_Edit.CreateEx (WS_EX_CLIENTEDGE, _T("EDIT"), NULL,

                     WS_CHILD | WS_VISIBLE | WS_TABSTOP | WS_BORDER,

        nX, nY, nWidth, nHeight, m_hWnd, 0, 0 );

 

    return bResult;

}

 Note

在动态加入控件是还要考虑该控件与属性表上其他控件相对位置关系。如果属性表支持Resize的话,很有可能发生控件布局错位的现象。

Refer to

http://www.codeguru.com/Cpp/controls/propertysheet/article.php/c3973/

http://www.codeproject.com/property/resizableproperties.asp

 

  五、  改变属性表大小

使用ResizableLib适用于几乎所有窗口Dialog,PropSheet,SDI,MDI
http://www.codeproject.com/dialog/ResizableLib.asp
也可参看Resizable CPropertySheet
http://www.codeproject.com/property/resizableproperties.asp
http://www.codeguru.com/Cpp/controls/propertysheet/sizing/article.php/c599/
运行期间动态进行调整大小避免切换后又恢复原来大小参见

http://support.microsoft.com/default.aspx?scid=kb;en-us;143291

Note:如果自己在OnInitDialogMoveWindow的时候要记住代码放到CPropertySheet::OnInitDialog()

  六、     消息处理

属性页间通信

发送消息PSM_QUERYSIBLINGS给属性表Sheet

该消息的传播路径是:

[引用MSDN] This message is sent to a property sheet, which then forwards the message to each of its pages. If a page returns a nonzero value, the property sheet does not send the message to subsequent pages.

在想接受和处理该消息的Page中添加对事件PSM_QUERYSIBLINGS的处理函数,具体如下:

afx_msg BOOL OnQuerySiblings(WPARAM wParam, LPARAM lParam);
ON_MESSAGE(PSM_QUERYSIBLINGS, OnQuerySiblings)
BOOL CPage1::OnQuerySiblings(WPARAM wParam, LPARAM lParam)
{
}


若该函数返回非零值,则消息传递就停止了,否则消息会遍历到每一个Page


 

References:

http://windowssdk.msdn.microsoft.com/en-us/library/ms652415.aspx

http://www.vckbase.com/document/viewdoc/?id=427

http://dev.csdn.net/article/76/76107.shtm

 

 

原创粉丝点击