WTL CTabCtrl 使用实例

WTL CTabCtrl 使用实例
假设基于对话框界面开发, 实现一组Tab页面。

在 .H  文件中,对类及成员的定义如下:

对话框子类继承:

class CMyMainDlg :  public CDialogImpl<CMyMainDlg>,
	public CWinDataExchange<CMyMainDlg>



消息映射:
BEGIN_MSG_MAP_EX(CMyMainDlg)
		MSG_WM_INITDIALOG(OnInitDialog)
		MESSAGE_HANDLER(WM_SYSCOMMAND, OnSysCommand)
		NOTIFY_HANDLER_EX(IDC_TAB1, TCN_SELCHANGE, OnSelchangeTab1)
	END_MSG_MAP()



响应函数声明:
LRESULT OnSelchangeTab1(LPNMHDR pnmh);



定义类成员变量:
界面上,放置有4个Tab页面:
CDialogImpl* m_pFunctionDlg[4];
	int m_CurSelTabIndex;
	CTabCtrl	m_tab;

在源文件中,增加TabCtrl变量的初始化、点击响应过程如下:

BOOL CMyMainDlg::OnInitDialog(CWindow wndFocus, LPARAM lInitParam)
{
	m_tab = GetDlgItem(IDC_TAB1);


    
	TCITEM t1;
	t1.mask = TCIF_TEXT;
	t1.pszText = (LPTSTR)“1”;//_T("完整性检查");
    m_tab.InsertItem(0, &t1);
    m_Dlg1.Create(m_tab.m_hWnd);
    m_pFunctionDlg[0] = (CDialogImpl *)&m_Dlg1;
    m_pFunctionDlg[0]->MoveWindow(&rc);
    m_pFunctionDlg[0]->ShowWindow(SW_SHOW);




    TCITEM t2;
	t2.mask = TCIF_TEXT;
	t2.pszText = (LPTSTR)“2”;
	m_tab.InsertItem(1, &t2);
	m_Dlg2.Create(m_tab.m_hWnd);
	m_pFunctionDlg[1] = (CDialogImpl *)&m_Dlg2;
	m_pFunctionDlg[1]->MoveWindow(&rc);
	m_pFunctionDlg[1]->ShowWindow(SW_HIDE);


    TCITEM t3;
	t3.mask = TCIF_TEXT;
	t3.pszText = (LPTSTR)“3”;
	m_tab.InsertItem(2, &t3);
	m_Dlg3.Create(m_tab.m_hWnd);
	m_pFunctionDlg[2] = (CDialogImpl *)&m_Dlg3;
	m_pFunctionDlg[2]->MoveWindow(&rc);
	m_pFunctionDlg[2]->ShowWindow(SW_HIDE);


	TCITEM t3;
	t3.mask = TCIF_TEXT;
	t3.pszText = (LPTSTR)“3”;
	m_tab.InsertItem(3, &t3);
	m_Dlg3.Create(m_tab.m_hWnd);
	m_pFunctionDlg[3] = (CDialogImpl *)&m_Dlg3;
	m_pFunctionDlg[3]->MoveWindow(&rc);
	m_pFunctionDlg[3]->ShowWindow(SW_HIDE);


	m_CurSelTabIndex = 0;


	return TRUE;  // return TRUE unless you set the focus to a control
}


LRESULT CMyMainDlg::OnSelchangeTab1(LPNMHDR pnmh)
{
	m_pFunctionDlg[m_CurSelTabIndex]->ShowWindow(SW_HIDE);
	m_CurSelTabIndex = m_tab.GetCurSel();
	m_pFunctionDlg[m_CurSelTabIndex]->ShowWindow(SW_SHOW);


	return 0;
}



猜你喜欢

转载自blog.csdn.net/boise/article/details/53334634
WTL