CTabSheet

// TabSheet.cpp : implementation file
//

#include "stdafx.h"
#include "dltool.h"
#include "TabSheet.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CTabSheet

CTabSheet::CTabSheet()
{
 m_nNumOfPages = 0;
 m_nCurrentPage = 0;
}

CTabSheet::~CTabSheet()
{
}


BEGIN_MESSAGE_MAP(CTabSheet, CTabCtrl)
 //{{AFX_MSG_MAP(CTabSheet)
 ON_WM_LBUTTONDOWN()
 //}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CTabSheet message handlers

BOOL CTabSheet::AddPage(LPCTSTR title, CDialog *pDialog,UINT ID)
{
 if( MAXPAGE == m_nNumOfPages )
  return FALSE;

 m_nNumOfPages++;

 m_pPages[m_nNumOfPages-1] = pDialog;
 m_IDD[m_nNumOfPages-1] = ID;
 m_Title[m_nNumOfPages-1] = title;

 return TRUE;
}

void CTabSheet::SetRect()
{
 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-2;
 nYc=tabRect.bottom-nY-2;

 m_pPages[0]->SetWindowPos(&wndTop, nX, nY, nXc, nYc, SWP_SHOWWINDOW);
 for( int nCount=1; nCount < m_nNumOfPages; nCount++ )
  m_pPages[nCount]->SetWindowPos(&wndTop, nX, nY, nXc, nYc, SWP_HIDEWINDOW);

}

void CTabSheet::Show()
{
 for( int i=0; i < m_nNumOfPages; i++ )
 {
  m_pPages[i]->Create( m_IDD[i], this );
  InsertItem( i, m_Title[i] );
 }

 m_pPages[0]->ShowWindow(SW_SHOW);
 for( i=1; i < m_nNumOfPages; i++)
  m_pPages[i]->ShowWindow(SW_HIDE);

 SetRect();

}

void CTabSheet::OnLButtonDown(UINT nFlags, CPoint point)
{
 CTabCtrl::OnLButtonDown(nFlags, point);

 if(m_nCurrentPage != GetCurFocus())
 {
  m_pPages[m_nCurrentPage]->ShowWindow(SW_HIDE);
  m_nCurrentPage=GetCurFocus();
  m_pPages[m_nCurrentPage]->ShowWindow(SW_SHOW);
//  m_pPages[m_nCurrentPage]->SetFocus();
 }
}

int CTabSheet::SetCurSel(int nItem)
{
 if( nItem < 0 || nItem >= m_nNumOfPages)
  return -1;

 int ret = m_nCurrentPage;

 if(m_nCurrentPage != nItem )
 {
  m_pPages[m_nCurrentPage]->ShowWindow(SW_HIDE);
  m_nCurrentPage = nItem;
  m_pPages[m_nCurrentPage]->ShowWindow(SW_SHOW);
//  m_pPages[m_nCurrentPage]->SetFocus();
  CTabCtrl::SetCurSel(nItem);
 }

 return ret;
}

int CTabSheet::GetCurSel()
{
 return CTabCtrl::GetCurSel();
}

 

 

#if !defined(AFX_TABSHEET_H__42EE262D_D15F_46D5_8F26_28FD049E99F4__INCLUDED_)
#define AFX_TABSHEET_H__42EE262D_D15F_46D5_8F26_28FD049E99F4__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
// TabSheet.h : header file
//

/////////////////////////////////////////////////////////////////////////////
// CTabSheet window
#define MAXPAGE 16

class CTabSheet : public CTabCtrl
{
// Construction
public:
 CTabSheet();

// Attributes
public:

// Operations
public:

// Overrides
 // ClassWizard generated virtual function overrides
 //{{AFX_VIRTUAL(CTabSheet)
 //}}AFX_VIRTUAL

// Implementation
public:
 int GetCurSel();
 int SetCurSel(int nItem);
 void Show();
 void SetRect();
 BOOL AddPage(LPCTSTR title, CDialog *pDialog, UINT ID);
 virtual ~CTabSheet();

 // Generated message map functions
protected:
 LPCTSTR m_Title[MAXPAGE];
 UINT m_IDD[MAXPAGE];
 CDialog* m_pPages[MAXPAGE];
 int m_nNumOfPages;
 int m_nCurrentPage;
 //{{AFX_MSG(CTabSheet)
 afx_msg void OnLButtonDown(UINT nFlags, CPoint point);
 //}}AFX_MSG

 DECLARE_MESSAGE_MAP()
};

/////////////////////////////////////////////////////////////////////////////

//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.

#endif // !defined(AFX_TABSHEET_H__42EE262D_D15F_46D5_8F26_28FD049E99F4__INCLUDED_)

使用

// dltoolDlg.h : header file
//

#pragma once


// CdltoolDlg dialog
#include "TabSheet.h"
#include "DisplayDlg.h" 
#include "GdcDlg.h"
#include "BacklightDlg.h"
#include "KeypadDlg.h"
#include "AudioDlg.h"
#include "afxcmn.h"

class CdltoolDlg : public CDialog
{
// Construction
public:
 CDisplayDlg m_display_dlg;
 CGdcDlg m_gdc_dlg;
 CBacklightDlg m_backlight_dlg;
 CKeypadDlg m_keypad_dlg;
 CAudioDlg m_audio_dlg;


 CdltoolDlg(CWnd* pParent = NULL); // standard constructor

// Dialog Data
 enum { IDD = IDD_DLTOOL_DIALOG };

 protected:
 virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support


// Implementation
public:
 void printmsg(CString str);


protected:
 HICON m_hIcon;

 // Generated message map functions
 virtual BOOL OnInitDialog();
 afx_msg void OnSysCommand(UINT nID, LPARAM lParam);
 afx_msg void OnPaint();
 afx_msg HCURSOR OnQueryDragIcon();
 DECLARE_MESSAGE_MAP()
public:
 CTabSheet m_tab;
 afx_msg void OnBnClickedConnect();
 afx_msg void OnBnClickedCheckconn();
 afx_msg void OnBnClickedDisconnect();
 CString m_message;
 UINT m_comport;
};

你可能感兴趣的:(function,header,File,Microsoft,insert,dialog)