MainFrm.cpp
资源名称:TabSample.rar [点击查看]
上传用户:sz86035077
上传日期:2013-02-27
资源大小:40k
文件大小:4k
源码类别:
Tab控件
开发平台:
Visual C++
- // MainFrm.cpp : implementation of the CMainFrame class
- //
- #include "stdafx.h"
- #include "Tab.h"
- #include "MainFrm.h"
- #include "DownloadView.h"
- #include "ProxyView.h"
- #include "DetectView.h"
- #include "TabDoc.h"
- #include "TabView.h"
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- /////////////////////////////////////////////////////////////////////////////
- // CMainFrame
- IMPLEMENT_DYNCREATE(CMainFrame, CFrameWnd)
- BEGIN_MESSAGE_MAP(CMainFrame, CFrameWnd)
- //{{AFX_MSG_MAP(CMainFrame)
- // NOTE - the ClassWizard will add and remove mapping macros here.
- // DO NOT EDIT what you see in these blocks of generated code !
- ON_WM_CREATE()
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
- static UINT indicators[] =
- {
- ID_SEPARATOR, // status line indicator
- ID_INDICATOR_CAPS,
- ID_INDICATOR_NUM,
- ID_INDICATOR_SCRL,
- };
- /////////////////////////////////////////////////////////////////////////////
- // CMainFrame construction/destruction
- CMainFrame::CMainFrame()
- {
- // TODO: add member initialization code here
- m_nCurrentID=0;
- }
- CMainFrame::~CMainFrame()
- {
- }
- int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
- {
- if (CFrameWnd::OnCreate(lpCreateStruct) == -1)
- return -1;
- if (!m_wndToolBar.CreateEx(this, TBSTYLE_FLAT, WS_CHILD | WS_VISIBLE | CBRS_TOP
- | CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC) ||
- !m_wndToolBar.LoadToolBar(IDR_MAINFRAME))
- {
- TRACE0("Failed to create toolbarn");
- return -1; // fail to create
- }
- if (!m_wndStatusBar.Create(this) ||
- !m_wndStatusBar.SetIndicators(indicators,
- sizeof(indicators)/sizeof(UINT)))
- {
- TRACE0("Failed to create status barn");
- return -1; // fail to create
- }
- // TODO: Delete these three lines if you don't want the toolbar to
- // be dockable
- m_wndToolBar.EnableDocking(CBRS_ALIGN_ANY);
- EnableDocking(CBRS_ALIGN_ANY);
- DockControlBar(&m_wndToolBar);
- return 0;
- }
- BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)
- {
- if( !CFrameWnd::PreCreateWindow(cs) )
- return FALSE;
- // TODO: Modify the Window class or styles here by modifying
- // the CREATESTRUCT cs
- return TRUE;
- }
- /////////////////////////////////////////////////////////////////////////////
- // CMainFrame diagnostics
- #ifdef _DEBUG
- void CMainFrame::AssertValid() const
- {
- CFrameWnd::AssertValid();
- }
- void CMainFrame::Dump(CDumpContext& dc) const
- {
- CFrameWnd::Dump(dc);
- }
- #endif //_DEBUG
- /////////////////////////////////////////////////////////////////////////////
- // CMainFrame message handlers
- BOOL CMainFrame::OnCreateClient(LPCREATESTRUCT lpcs, CCreateContext* pContext)
- {
- // TODO: Add your specialized code here and/or call the base class
- if(!m_tabView.CreateStatic(this))
- {
- TRACE0("failed to createpropertysheetn");
- return false;
- }
- //CRuntimeClass* pNewViewClass = RUNTIME_CLASS(CDownloadView);
- CRuntimeClass* pNewViewClass = RUNTIME_CLASS(CTabView);
- m_tabView.SetTab(0);
- CSize size(160, 180);
- if (!m_tabView.CreateView(pNewViewClass, size, pContext))
- {
- TRACE0("failed to create first panen");
- return false;
- }
- SetActiveView(m_tabView.GetActiveView());
- //Invalidate();
- return TRUE;
- // return CFrameWnd::OnCreateClient(lpcs, pContext);
- }
- void CMainFrame::HandleTabs(int sel)
- {
- if (sel == m_nCurrentID)
- return; // already selected
- CView* pOldActiveView = GetActiveView();
- ::SetWindowLong(pOldActiveView->m_hWnd, GWL_ID, m_nCurrentID);
- CRuntimeClass* pNewViewClass;
- switch (sel)
- {
- case 0:
- pNewViewClass = RUNTIME_CLASS(CTabView);
- break;
- case 1:
- pNewViewClass = RUNTIME_CLASS(CProxyView);
- break;
- case 2:
- pNewViewClass = RUNTIME_CLASS(CDetectView);
- break;
- default:
- ASSERT(0);
- return;
- }
- // create the new view
- CCreateContext context;
- context.m_pNewViewClass = pNewViewClass;
- context.m_pCurrentDoc = GetActiveDocument();
- CView* pNewView = m_tabView.CreateView(pNewViewClass, CSize(100,100), &context);//sunxin
- if (pNewView != NULL)
- {
- // the new view is there, but invisible and not active...
- pNewView->ShowWindow(SW_SHOW);
- pNewView->OnInitialUpdate();
- SetActiveView(pNewView);
- m_tabView.RecalcLayout(); //sunxin
- RecalcLayout();
- m_nCurrentID = sel;
- // finally destroy the old view...
- pOldActiveView->DestroyWindow();
- }
- }