www.pudn.com > 2007071212243513681.rar > ResTabCtrl.cpp


// MyTabCtrl.cpp : ʵÏÖÎļþ 
// 
 
#include "stdafx.h" 
#include "fun.h" 
#include "ResTabCtrl.h" 
 
#include "ResDialog1.h" 
#include "ResDialog2.h" 
#include "ResDialog3.h" 
#include "ResDialog4.h" 
 
///////////////////////////////////////////////////////////////////////////// 
// CMyTabCtrl 
 
CResTabCtrl::CResTabCtrl() 
{ 
	m_tabPages[0]		= new CResDialog1; 
	m_tabPages[1]		= new CResDialog2; 
	m_tabPages[2]		= new CResDialog3; 
	m_tabPages[3]		= new CResDialog4; 
	m_nNumberOfPages	= 4; 
} 
 
CResTabCtrl::~CResTabCtrl() 
{ 
	for (int nCount = 0; nCount < m_nNumberOfPages; nCount++) 
		delete m_tabPages[nCount]; 
} 
 
void CResTabCtrl::Init() 
{ 
	m_tabCurrent	= 0; 
 
	m_tabPages[0]->Create(IDD_RESDIALOG1, this); 
	m_tabPages[1]->Create(IDD_RESDIALOG2, this); 
	m_tabPages[2]->Create(IDD_RESDIALOG3, this); 
	m_tabPages[3]->Create(IDD_RESDIALOG4, this); 
 
	m_tabPages[0]->ShowWindow(SW_SHOW); 
	m_tabPages[1]->ShowWindow(SW_HIDE); 
	m_tabPages[2]->ShowWindow(SW_HIDE); 
	m_tabPages[3]->ShowWindow(SW_HIDE); 
 
	SetRectangle(); 
} 
 
void CResTabCtrl::SetRectangle() 
{ 
	CRect tabRect, itemRect; 
	int nX, nY, nXc, nYc; 
 
	GetClientRect(&tabRect); 
	GetItemRect(0, &itemRect); 
 
	nX	= itemRect.left; 
	nY	= itemRect.bottom + 1; 
	nXc	= tabRect.right - itemRect.left - 1; 
	nYc	= tabRect.bottom - nY - 1; 
 
	m_tabPages[0]->SetWindowPos(&wndTop, nX, nY, nXc, nYc, SWP_SHOWWINDOW); 
	for (int nCount = 1; nCount < m_nNumberOfPages; nCount++) 
	{ 
		m_tabPages[nCount]->SetWindowPos(&wndTop, nX, nY, nXc, nYc, SWP_HIDEWINDOW); 
	} 
} 
 
BEGIN_MESSAGE_MAP(CResTabCtrl, CTabCtrl) 
	ON_WM_LBUTTONDOWN() 
END_MESSAGE_MAP() 
 
void CResTabCtrl::OnLButtonDown(UINT nFlags, CPoint point)  
{ 
	CTabCtrl::OnLButtonDown(nFlags, point); 
 
	if ( m_tabCurrent != GetCurFocus() ) 
	{ 
		m_tabPages[m_tabCurrent]->ShowWindow(SW_HIDE); 
		m_tabCurrent	= GetCurFocus(); 
		m_tabPages[m_tabCurrent]->ShowWindow(SW_SHOW); 
		m_tabPages[m_tabCurrent]->SetFocus(); 
	} 
}