我是一个MFC入门者,可能这是比较初级的问题,望大虾解答。1:如何在程序开始时创建多个重叠的ListView文档
2:如何通过TabCtrl点击,在几个List文档之间切换
2:如何通过TabCtrl点击,在几个List文档之间切换
解决方案 »
- 求助~~
- Delphi调用C++接口错误
- Win32程序在64位Windows下运行的问题:如何正确枚举系统进程?
- 5000分寻OPC Server的例子代码?
- 跨进程COM的问题!相对比较急!
- 执行CDC *pDC=GetDC();这行时出错:Access violation reading location 0x00000020.
- 关于CREATESTRUCT 这个数据结构
- 钩子是什么东东
- 用mfc写com 在生成工程时需不需要选中automation ?
- VC:如何在切换视的同时不删除原来的视??
- 用什么方法判断程序是 SDI MDI DLG?
- 如果使用softice调试一个只有exe的文件
#define AFX_MYTABCTRL_H__2F98A082_0F12_46F8_8B57_35256125D574__INCLUDED_#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
// MyTabCtrl.h : header file
//#include <afxtempl.h>
#include "MyWndCommon.h"
#include "inserttest.h"/////////////////////////////////////////////////////////////////////////////
// CMyTabCtrl window
class CMainFrame;
class CMyTabCtrl : public CTabCtrl
{
// Construction
public:
CMyTabCtrl();// Attributes
public:
UINT m_nID; //窗口编号
//member
CArray<CMyWndCommon*,CMyWndCommon*> m_arpPane;protected:
CMyWndCommon* m_pCurPane; // the pointer to current selected pane
// Operations
public:// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CMyTabCtrl)
//}}AFX_VIRTUAL// Implementation
public:
CMyWndCommon* GetCurPane();
void SelectPane(UINT nPaneID);
void SelectTab(int index);
BOOL CreatePanes();
virtual ~CMyTabCtrl(); // Generated message map functions
protected:
//{{AFX_MSG(CMyTabCtrl)
afx_msg void OnSize(UINT nType, int cx, int cy);
afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);
afx_msg void OnSelchange(NMHDR* pNMHDR, LRESULT* pResult);
//}}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__2F98A082_0F12_46F8_8B57_35256125D574__INCLUDED_)
//#include "stdafx.h"
#include "MyTabCtrl.h"#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif/////////////////////////////////////////////////////////////////////////////
// CMyTabCtrlCMyTabCtrl::CMyTabCtrl()
{
m_pCurPane = 0x00000000;
}CMyTabCtrl::~CMyTabCtrl()
{
int i;
for(i = 0;i<m_arpPane.GetSize();i++)
delete m_arpPane[i];
}
BEGIN_MESSAGE_MAP(CMyTabCtrl, CTabCtrl)
//{{AFX_MSG_MAP(CMyTabCtrl)
ON_WM_SIZE()
ON_WM_CREATE()
ON_NOTIFY_REFLECT(TCN_SELCHANGE, OnSelchange)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()BOOL CMyTabCtrl::CreatePanes()
{
CString childWindowText;
CMainFrame* pMainWnd = (CMainFrame*)AfxGetApp()->GetMainWnd();
////////////
switch(m_nID)
{ case 3000:
InsertItem(0, _T("测试")); m_arpPane.Add(new InsertTest);//InserTest为你自己创建的pane if(!m_arpPane[0]->Create(this))
{
return FALSE;
}
break;
}
// GetParent()->GetParent()->SetWindowText(childWindowText);
return TRUE;
}
CMyWndCommon* CMyTabCtrl::GetCurPane()
{
int index = -1;
index = GetCurSel();
if(index>=0 && index<GetItemCount())
return m_arpPane[index];
else return NULL;
}
void CMyTabCtrl::SelectPane(UINT nPaneID)
{
int i;
int n = GetItemCount(); for(i=0;i<n;i++)
{
if(m_arpPane[i]->m_nID == nPaneID)
{
SelectTab(i);
}
}
}void CMyTabCtrl::SelectTab(int index)
{
ZDBGMsgBox(index<0&&index>=GetItemCount(),"tab index over the bound!"); CMainFrame* pMainWnd = (CMainFrame*)AfxGetApp()->GetMainWnd(); SetCurSel(index);
//
CMyWndCommon* n_pPane = m_arpPane[index];
if(m_pCurPane)
{
m_pCurPane->m_pEndTimeCtrl = 0x00000000;
m_pCurPane->m_pStartTimeCtrl = 0x00000000;
m_pCurPane->m_pComboSubcenter = 0x00000000;
m_pCurPane->HidePane(); //隐藏pane
}
if(n_pPane)
{
n_pPane->m_pEndTimeCtrl = &pMainWnd->m_timeEnd;
n_pPane->m_pStartTimeCtrl = &pMainWnd->m_timeStart;
n_pPane->m_pComboSubcenter = &pMainWnd->m_comboSubcenter;
n_pPane->ShowPane();
}
m_pCurPane = n_pPane; char msg[256];
TCITEM tcitem;
tcitem.mask=TCIF_TEXT;
tcitem.pszText=msg;
tcitem.cchTextMax=256;
GetItem(GetCurSel(),&tcitem); pMainWnd->GetActiveFrame()->SetWindowText(tcitem.pszText);
}
/////////////////////////////////////////////////////////////////////////////
// CMyTabCtrl message handlers
void CMyTabCtrl::OnSize(UINT nType, int cx, int cy)
{
CTabCtrl::OnSize(nType, cx, cy);
// TODO: Add your message handler code here
int i;
CRect rect,r;
GetClientRect(rect);
GetItemRect(0,r);
rect.DeflateRect(5,r.Height()+7,6,5);
for(i=0;i<m_arpPane.GetSize();i++)
{
m_arpPane[i]->MoveWindow(rect);
// m_arpPane[i]->OnSize(SIZE_RESTORED, rect.Width(),rect.Height());
}
}int CMyTabCtrl::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CTabCtrl::OnCreate(lpCreateStruct) == -1)
return -1; SetFont(&((CMainFrame*)AfxGetApp()->GetMainWnd())->m_Font);//GetFont());
if(!CreatePanes())return -1; return 0;
}
void CMyTabCtrl::OnSelchange(NMHDR* pNMHDR, LRESULT* pResult)
{
CMainFrame* pMainWnd = (CMainFrame*)::AfxGetApp()->GetMainWnd();
int index = GetCurSel();
if(index<0)return; SelectTab(index);
pMainWnd->m_wndTaskBar.SelectTask((WPARAM)(GetCurPane()->m_nID)); *pResult = 0;
}