急!!!请各位大虾给我一个CMap类的例子,不胜感激!!

czaoth 2001-09-14 03:58:32
...全文
70 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
蒋晟 2001-09-14
  • 打赏
  • 举报
回复
HOWTO: How To Disable Tabs in CPropertySheet
ID: Q151662


--------------------------------------------------------------------------------
The information in this article applies to:

The Microsoft Foundation Classes (MFC), used with:
Microsoft Visual C++, 32-bit Editions, versions 4.0, 4.1

--------------------------------------------------------------------------------


SUMMARY
This article describes how to disable tabs in a CPropertySheet so the user is not allowed to activate the tab. To accomplish this behavior, you can do the following:



Handle the TCN_SELCHANGING notification in the sheet and save the index of the current tab.


Handle the TCN_SELCHANGE notification in the sheet and call GetActiveIndex() to determine if you want the page disabled.


If you want the page disabled, post a PSM_SETCURSEL message to the sheet using the index that was saved in TCN_SELCHANGING.


The sample code below shows how to implement an EnablePage() function that allows you to enable and disable pages.



MORE INFORMATION
Because there is no way to gray out the text in the tab of the disabled page, append "Disabled" to the tab label to inform the user that the page is disabled.

Instead of posting a PSM_SETCURSEL message in the handler for TCN_SELCHANGE to activate a different page, you can accomplish this behavior in OnSetActive() for a CPropertyPage.

If OnSetActive() returns FALSE, it tries to activate the next tab. The method described above allows you to reactivate the previously active tab.

Sample Code


// This sample disables page #2 of a property sheet.

// We need to include this file so we can use CMap
#include <afxtempl.h>

class CMySheet : public CPropertySheet
{
protected:
// we save the current page in TCN_SELCHANGING
int m_nLastActive;
// list of indexes of disabled pages
CMap <int, int&, int, int&> m_DisabledPages;
public:
void EnablePage (int nPage, BOOL bEnable = TRUE);
...
};

BOOL CMySheet::OnInitDialog()
{
// OnInitDialog() must be called before EnablePage()
// or GetTabControl() will fail.
BOOL bReturn = CPropertySheet::OnInitDialog();
// disable page #2
EnablePage (1, FALSE);
return bReturn;
}

void CMySheet::EnablePage (int nPage, BOOL bEnable)
{
// if we want to enable the page
if (bEnable)
{
// remove the index from the map
m_DisabledPages.RemoveKey (nPage);
// take out " - Disabled" from tab label
CTabCtrl* pTab = GetTabControl();
ASSERT (pTab);
TC_ITEM ti;
char szText[100];
ti.mask = TCIF_TEXT;
ti.pszText = szText;
ti.cchTextMax = 100;
VERIFY (pTab->GetItem (nPage, &ti));
char * pFound = strstr (szText, " - Disabled");
if (pFound)
{
*pFound = '\0';
VERIFY (pTab->SetItem (nPage, &ti));
}
}
// if we want to disable it
else
{
// add the index to the map
m_DisabledPages.SetAt (nPage, nPage);
// add " - Disabled" to tab label
CTabCtrl* pTab = GetTabControl();
ASSERT (pTab);
TC_ITEM ti;
char szText[100];
ti.mask = TCIF_TEXT;
ti.pszText = szText;
ti.cchTextMax = 100;
VERIFY (pTab->GetItem (nPage, &ti));
strcat (szText, " - Disabled");
VERIFY (pTab->SetItem (nPage, &ti));
}
}

BOOL CMySheet::OnNotify(WPARAM wParam, LPARAM lParam, LRESULT* pResult)
{
NMHDR* pnmh = (NMHDR*)lParam;
// tab is about to change
if (TCN_SELCHANGING == pnmh->code)
// save the current page index
m_nLastActive = GetActiveIndex ();
// tab has been changed
else if (TCN_SELCHANGE == pnmh->code)
{
// get the current page index
int nCurrentPage = GetActiveIndex ();
// if current page is in our map of disabled pages
if (m_DisabledPages.Lookup (nCurrentPage, nCurrentPage))
// activate the previous page
PostMessage (PSM_SETCURSEL, m_nLastActive);
}
return CPropertySheet::OnNotify(wParam, lParam, pResult);
}

/* Compile options needed: default
*/

Additional query words: 4.00 4.10 CPropertySheet CPropertyPage disable

Keywords : kbMFC kbPropSheet KbUIDesign kbVC kbGrpMFCATL
Version : winnt:4.0,4.1
Platform : winnt
Issue type : kbhowto
Technology : kbvc


Last Reviewed: March 13, 2000
© 2000 Microsoft Corporation. All rights reserved. Terms of Use.




--------------------------------------------------------------------------------
Send feedback to MSDN.Look here for MSDN Online resources.
tzgh2000 2001-09-14
  • 打赏
  • 举报
回复
关注

16,472

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC相关问题讨论
社区管理员
  • 基础类社区
  • Web++
  • encoderlee
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……

试试用AI创作助手写篇文章吧