www.pudn.com > 2007071212243513681.rar > MyTabCtrl.cpp
// MyTabCtrl.cpp : ʵÏÖÎļþ
//
#include "stdafx.h"
#include "fun.h"
#include "MyTabCtrl.h"
#include "Dialog1.h"
#include "Dialog2.h"
#include "Dialog3.h"
#include "Dialog4.h"
/////////////////////////////////////////////////////////////////////////////
// CMyTabCtrl
CMyTabCtrl::CMyTabCtrl()
{
m_tabPages[0] = new CDialog1;
m_tabPages[1] = new CDialog2;
m_tabPages[2] = new CDialog3;
m_tabPages[3] = new CDialog4;
m_nNumberOfPages = 4;
}
CMyTabCtrl::~CMyTabCtrl()
{
for (int nCount = 0; nCount < m_nNumberOfPages; nCount++)
delete m_tabPages[nCount];
}
void CMyTabCtrl::Init()
{
m_tabCurrent = 0;
m_tabPages[0]->Create(IDD_DIALOG1, this);
m_tabPages[1]->Create(IDD_DIALOG2, this);
m_tabPages[2]->Create(IDD_DIALOG3, this);
m_tabPages[3]->Create(IDD_DIALOG4, 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 CMyTabCtrl::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(CMyTabCtrl, CTabCtrl)
ON_WM_LBUTTONDOWN()
END_MESSAGE_MAP()
void CMyTabCtrl::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();
}
}