// MyTabCtrl.cpp : 实现文件 // #include "stdafx.h" #include "FileCleaner.h" #include "MyTabCtrl.h" // CMyTabCtrl IMPLEMENT_DYNAMIC(CMyTabCtrl, CTabCtrl) CMyTabCtrl::CMyTabCtrl() { } CMyTabCtrl::~CMyTabCtrl() { } //参数列表 //第1个位子窗口个数 //后面依次为:窗口名、基类指针、ID void CMyTabCtrl::Insert(int nCount...) {//获取客户区尺寸 CRect RC = {}; GetClientRect(&RC); RC.DeflateRect(1, 30, 1, 1); va_list vl; va_start(vl, nCount); for (int i = 0; i < nCount; i++) {//插入窗口名,创建新窗口 InsertItem(i, va_arg(vl, WCHAR*)); m_pDlg[i] = va_arg(vl, CDialogEx*); int ID = va_arg(vl, int); m_pDlg[i]->Create(MAKEINTRESOURCE(ID), this); m_pDlg[i]->MoveWindow(RC); } m_pDlg[0]->ShowWindow(SW_SHOW); va_end(vl); } BEGIN_MESSAGE_MAP(CMyTabCtrl, CTabCtrl) ON_NOTIFY_REFLECT(TCN_SELCHANGE, &CMyTabCtrl::OnTcnSelchange) END_MESSAGE_MAP() // CMyTabCtrl 消息处理程序 void CMyTabCtrl::OnTcnSelchange(NMHDR *pNMHDR, LRESULT *pResult) { // TODO: 在此添加控件通知处理程序代码 int n = GetCurSel(); for (int i = 0; i < 2;i++) { if (i == n) { m_pDlg[i]->ShowWindow(SW_SHOW); continue; } m_pDlg[i]->ShowWindow(SW_HIDE); } *pResult = 0; }
#pragma once // CMyTabCtrl class CMyTabCtrl : public CTabCtrl { DECLARE_DYNAMIC(CMyTabCtrl) public: CMyTabCtrl(); virtual ~CMyTabCtrl(); void Insert(int nCount...); CDialogEx *m_pDlg[2]; protected: DECLARE_MESSAGE_MAP() public: afx_msg void OnTcnSelchange(NMHDR *pNMHDR, LRESULT *pResult); };