关于TabCtrole的问题,

dycdyc123 2002-05-26 09:50:06
1.怎样使用TabCtrol生成叶面
其中的控件怎样安排?(visible 与unvisible)
2.怎样把视View的指定Rect区域拷贝到CDC MyDc 中??

...全文
75 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
masterz 2002-06-04
  • 打赏
  • 举报
回复
// MyTabCtrl.cpp : implementation file
//
/////////////////////////////////////////////////////
// This class is provided as is and Ben Hill takes no
// responsibility for any loss of any kind in connection
// to this code.
/////////////////////////////////////////////////////
// Is is meant purely as a educational tool and may
// contain bugs.
/////////////////////////////////////////////////////
// ben@shido.fsnet.co.uk
// http://www.shido.fsnet.co.uk
/////////////////////////////////////////////////////
// Thanks to a mystery poster in the C++ forum on
// www.codeguru.com I can't find your name to say thanks
// for your Control drawing code. If you are that person
// thank you very much. I have been able to use some of
// you ideas to produce this sample application.
/////////////////////////////////////////////////////

#include "stdafx.h"
#include "MyTabExample.h"
#include "MyTabCtrl.h"

#include "TabOne.h"
#include "TabTwo.h"
#include "TabThree.h"

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

/////////////////////////////////////////////////////////////////////////////
// CMyTabCtrl

CMyTabCtrl::CMyTabCtrl()
{
m_tabPages[0]=new CTabOne;
m_tabPages[1]=new CTabTwo;
m_tabPages[2]=new CTabThree;

m_nNumberOfPages=3;
}

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_TAB_ONE, this);
m_tabPages[1]->Create(IDD_TAB_TWO, this);
m_tabPages[2]->Create(IDD_TAB_THREE, this);

m_tabPages[0]->ShowWindow(SW_SHOW);
m_tabPages[1]->ShowWindow(SW_HIDE);
m_tabPages[2]->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)
//{{AFX_MSG_MAP(CMyTabCtrl)
ON_WM_LBUTTONDOWN()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CMyTabCtrl message handlers

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();
}
}
masterz 2002-06-04
  • 打赏
  • 举报
回复
#if !defined(AFX_MYTABCTRL_H__F3E8650F_019C_479F_9E0F_60FE1181F49F__INCLUDED_)
#define AFX_MYTABCTRL_H__F3E8650F_019C_479F_9E0F_60FE1181F49F__INCLUDED_

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

/////////////////////////////////////////////////////////////////////////////
// CMyTabCtrl window

class CMyTabCtrl : public CTabCtrl
{
// Construction
public:
CMyTabCtrl();
CDialog *m_tabPages[3];
int m_tabCurrent;
int m_nNumberOfPages;

// Attributes
public:

// Operations
public:
void Init();
void SetRectangle();

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

// Implementation
public:
virtual ~CMyTabCtrl();

// Generated message map functions
protected:
//{{AFX_MSG(CMyTabCtrl)
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_MYTABCTRL_H__F3E8650F_019C_479F_9E0F_60FE1181F49F__INCLUDED_)
masterz 2002-06-04
  • 打赏
  • 举报
回复
Creating a CTabCtrl Application

--------------------------------------------------------------------------------

This article was contributed by Ben Hill.



Environment: VC6 SP3, NT4, Windows 2000 Pro, Windows 2000 Server

Firstly add the CMyTabCtrl.cpp and CMyTabCtrl.h to your project.

Using Visual Studio add a CTabCtrl control to your dialog. Add a member variable for this control as a CMyTabCtrl type not a simple CTabCtrl. CMyTabCtrl is derived from CTabCtrl.

You can simply add a CTabCtrl member variable and manually edit the file to become CMyTabCtrl

Now create dialogs for every page you require. These must be child dialogs with no border. Any controls here in these dialogs are handled by their own class.

Create a Class for each dialog. In the example these are CTabOne, CTabTwo and CTabThree.

In the CmyTabCtrl constructor you must add a ‘new’ for each page. Also in the Init function you must specify all tab dialogs to hide all but one

In this example the OnLButtonDown message handler is used to show and hide the various dialogs. The page is managed with a variable m_tabCurrent which holds the value of selected pages.

In the main app dialog’s OnInitDialog message handler add the tabs you require for your dialog. In this example these are ‘Tab One’, ‘Tab Two’ and ‘Tab Three’.

Functionality for the left and right cursor keys to select the tabs can be added in the CMyTabCtrl class.

CMyTabCtrl::CMyTabCtrl()
{
m_tabPages[0]=new CTabOne;
m_tabPages[1]=new CTabTwo;
m_tabPages[2]=new CTabThree;

m_nNumberOfPages=3;
}

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_TAB_ONE, this);
m_tabPages[1]->Create(IDD_TAB_TWO, this);
m_tabPages[2]->Create(IDD_TAB_THREE, this);

m_tabPages[0]->ShowWindow(SW_SHOW);
m_tabPages[1]->ShowWindow(SW_HIDE);
m_tabPages[2]->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);
}
}


//////////////////////////////////////////////////////
// CMyTabCtrl message handlers

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();
}
}

The Dialog Showing, Hiding and Drawing code is from the C++ Forum On this site. It was posted by someone whom I don't have name for.

If it was you then please let me know and I will have your name added

I hope this code is of some use. It has helped me to develop much more complex dialogs.

Downloads
Download demo project - 18 Kb
Download source - 2 Kb
xfz 2002-06-03
  • 打赏
  • 举报
回复
CTabCtrl* pTab=(CTabCtrl*)GetDlgItem(IDC_TAB1);
pTab->InsertItem(0,"page1");
pTab->InsertItem(1,"page2");
msfmegryvc 2002-06-03
  • 打赏
  • 举报
回复
up
dycdyc123 2002-06-03
  • 打赏
  • 举报
回复
每人呀?

dycdyc123 2002-06-02
  • 打赏
  • 举报
回复
打不开!

masterz 2002-05-26
  • 打赏
  • 举报
回复
http://www.codeguru.com/controls/CMyTabCtrl.html
sxychee 2002-05-26
  • 打赏
  • 举报
回复
我不用VC做程序,不过我也从不用TabCtrol控件,太不好用,有好多好用的控件,功能比他强,如SSTAB,等
dycdyc123 2002-05-26
  • 打赏
  • 举报
回复
高手那里去了?

16,551

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC相关问题讨论
社区管理员
  • 基础类社区
  • AIGC Browser
  • encoderlee
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……

试试用AI创作助手写篇文章吧