CMFCShellListCtrl 和 CMFCShellTreeCtrl 关联的问题
-
2012年7月17日 11:01
今天学着Visual C++ 2008 Feature Pack的Explorer例子,做了一个窗口切分的Explorer,结果在关联CMFCShellListCtrl 和 CMFCShellTreeCtrl的时候老是报错。恳请大家分析分析看看如何解决。我试过模态对话框的情况下可以很容易进行关联CMFCShellListCtrl 和 CMFCShellTreeCtrl,没有任何问题。
以下是代码
#pragma once // CMyListView 视图 class CMyListView : public CView { DECLARE_DYNCREATE(CMyListView) protected: CMyListView(); // 动态创建所使用的受保护的构造函数 virtual ~CMyListView(); public: CMFCShellListCtrl m_ShellListCtrl; public: virtual void OnDraw(CDC* pDC); // 重写以绘制该视图 #ifdef _DEBUG virtual void AssertValid() const; #ifndef _WIN32_WCE virtual void Dump(CDumpContext& dc) const; #endif #endif protected: DECLARE_MESSAGE_MAP() public: afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct); afx_msg void OnSize(UINT nType, int cx, int cy); virtual void OnActivateView(BOOL bActivate, CView* pActivateView, CView* pDeactiveView); virtual void OnInitialUpdate(); afx_msg BOOL OnEraseBkgnd(CDC* pDC); };
// MyListView.cpp : 实现文件 // #include "stdafx.h" #include "My.h" #include "MyListView.h" #include "MainFrm.h" // CMyListView IMPLEMENT_DYNCREATE(CMyListView, CView) CMyListView::CMyListView() { } CMyListView::~CMyListView() { } BEGIN_MESSAGE_MAP(CMyListView, CView) ON_WM_CREATE() ON_WM_SIZE() ON_WM_ERASEBKGND() END_MESSAGE_MAP() // CMyListView 绘图 void CMyListView::OnDraw(CDC* pDC) { //CDocument* pDoc = GetDocument(); // TODO: 在此添加绘制代码 } // CMyListView 诊断 #ifdef _DEBUG void CMyListView::AssertValid() const { CView::AssertValid(); } #ifndef _WIN32_WCE void CMyListView::Dump(CDumpContext& dc) const { CView::Dump(dc); } #endif #endif //_DEBUG // CMyListView 消息处理程序 int CMyListView::OnCreate(LPCREATESTRUCT lpCreateStruct) { if (CView::OnCreate(lpCreateStruct) == -1) return -1; // TODO: 在此添加您专用的创建代码 CRect rectDummy (0, 0, 0, 0); m_ShellListCtrl.Create (WS_CHILD | WS_VISIBLE | LVS_REPORT, rectDummy, this, 1); return 0; } void CMyListView::OnSize(UINT nType, int cx, int cy) { CView::OnSize(nType, cx, cy); // TODO: 在此处添加消息处理程序代码 m_ShellListCtrl.SetWindowPos (NULL, -1, -1, cx, cy, SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE); } void CMyListView::OnActivateView(BOOL bActivate, CView* pActivateView, CView* pDeactiveView) { // TODO: 在此添加专用代码和/或调用基类 if (bActivate && AfxGetMainWnd () != NULL) { ((CMainFrame*) AfxGetMainWnd ())->GetFolders ().SetRelatedList (&m_ShellListCtrl); } CView::OnActivateView(bActivate, pActivateView, pDeactiveView); } void CMyListView::OnInitialUpdate() { CView::OnInitialUpdate(); // TODO: 在此添加专用代码和/或调用基类 } BOOL CMyListView::OnEraseBkgnd(CDC* pDC) { // TODO: 在此添加消息处理程序代码和/或调用默认值 return TRUE; }
#include "MyDoc.h" class CMyView : public CView { protected: // create from serialization only CMyView(); DECLARE_DYNCREATE(CMyView) // Attributes public: CMyDoc* GetDocument() const; // Operations public: CMFCShellTreeCtrl m_ShellTreeCtrl; ULONG m_ulRecycleBin; // Overrides public: virtual void OnDraw(CDC* pDC); // overridden to draw this view virtual BOOL PreCreateWindow(CREATESTRUCT& cs); protected: // Implementation public: virtual ~CMyView(); #ifdef _DEBUG virtual void AssertValid() const; virtual void Dump(CDumpContext& dc) const; #endif protected: // Generated message map functions protected: afx_msg void OnFilePrintPreview(); afx_msg void OnRButtonUp(UINT nFlags, CPoint point); afx_msg void OnContextMenu(CWnd* pWnd, CPoint point); DECLARE_MESSAGE_MAP() public: afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct); afx_msg void OnSize(UINT nType, int cx, int cy); afx_msg void OnSetFocus(CWnd* pOldWnd); afx_msg LRESULT OnNotifyRecycleBin(WPARAM wParam, LPARAM lParam); }; #ifndef _DEBUG // debug version in MyView.cpp inline CMyDoc* CMyView::GetDocument() const { return reinterpret_cast<CMyDoc*>(m_pDocument); } #endif
// MyView.cpp : implementation of the CMyView class // #include "stdafx.h" // SHARED_HANDLERS can be defined in an ATL project implementing preview, thumbnail // and search filter handlers and allows sharing of document code with that project. #ifndef SHARED_HANDLERS #include "My.h" #endif #include "MyDoc.h" #include "MyView.h" #ifdef _DEBUG #define new DEBUG_NEW #endif const int idTree = 1; #define SHCNF_ACCEPT_INTERRUPTS 0x0001 #define SHCNF_ACCEPT_NON_INTERRUPTS 0x0002 UINT UWM_NOTIFY_RECYCLE_BIN = ::RegisterWindowMessage(_T("UWM_NOTIFY_RECYCLE_BIN")); // CMyView IMPLEMENT_DYNCREATE(CMyView, CView) BEGIN_MESSAGE_MAP(CMyView, CView) ON_WM_CONTEXTMENU() ON_WM_RBUTTONUP() ON_WM_CREATE() ON_WM_SIZE() ON_WM_SETFOCUS() ON_REGISTERED_MESSAGE(UWM_NOTIFY_RECYCLE_BIN, OnNotifyRecycleBin) END_MESSAGE_MAP() // CMyView construction/destruction CMyView::CMyView() { // TODO: add construction code here } CMyView::~CMyView() { } BOOL CMyView::PreCreateWindow(CREATESTRUCT& cs) { // TODO: Modify the Window class or styles here by modifying // the CREATESTRUCT cs return CView::PreCreateWindow(cs); } // CMyView drawing void CMyView::OnDraw(CDC* /*pDC*/) { CMyDoc* pDoc = GetDocument(); ASSERT_VALID(pDoc); if (!pDoc) return; // TODO: add draw code for native data here } void CMyView::OnRButtonUp(UINT /* nFlags */, CPoint point) { ClientToScreen(&point); OnContextMenu(this, point); } void CMyView::OnContextMenu(CWnd* /* pWnd */, CPoint point) { #ifndef SHARED_HANDLERS theApp.GetContextMenuManager()->ShowPopupMenu(IDR_POPUP_EDIT, point.x, point.y, this, TRUE); #endif } // CMyView diagnostics #ifdef _DEBUG void CMyView::AssertValid() const { CView::AssertValid(); } void CMyView::Dump(CDumpContext& dc) const { CView::Dump(dc); } CMyDoc* CMyView::GetDocument() const // non-debug version is inline { ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CMyDoc))); return (CMyDoc*)m_pDocument; } #endif //_DEBUG // CMyView message handlers int CMyView::OnCreate(LPCREATESTRUCT lpCreateStruct) { if (CView::OnCreate(lpCreateStruct) == -1) return -1; CRect rectDummy (0, 0, 0, 0); const DWORD dwViewStyle = WS_CHILD | WS_VISIBLE | TVS_HASLINES | TVS_LINESATROOT | TVS_HASBUTTONS; m_ShellTreeCtrl.Create(dwViewStyle, rectDummy, this, idTree); LPITEMIDLIST ppidl; if (SHGetSpecialFolderLocation(GetSafeHwnd(),CSIDL_BITBUCKET, &ppidl) != NOERROR) { return 0; } SHChangeNotifyEntry scnIDL; scnIDL.pidl = ppidl; scnIDL.fRecursive = TRUE; m_ulRecycleBin = SHChangeNotifyRegister(m_hWnd, SHCNF_ACCEPT_INTERRUPTS | SHCNF_ACCEPT_NON_INTERRUPTS, SHCNE_ALLEVENTS, UWM_NOTIFY_RECYCLE_BIN, 1, &scnIDL); return 0; return 0; } void CMyView::OnSize(UINT nType, int cx, int cy) { CView::OnSize(nType, cx, cy); m_ShellTreeCtrl.SetWindowPos (NULL, 0, 0, cx, cy, SWP_NOACTIVATE | SWP_NOZORDER); // TODO: 在此处添加消息处理程序代码 } void CMyView::OnSetFocus(CWnd* pOldWnd) { CView::OnSetFocus(pOldWnd); // TODO: 在此处添加消息处理程序代码 m_ShellTreeCtrl.SetFocus (); } LRESULT CMyView::OnNotifyRecycleBin(WPARAM wParam, LPARAM lParam) { UNREFERENCED_PARAMETER(wParam); if (lParam == SHCNE_UPDATEIMAGE) { m_ShellTreeCtrl.Refresh(); } if (lParam == SHCNE_FREESPACE) { LPITEMIDLIST ppidl; if (SHGetSpecialFolderLocation(GetSafeHwnd(), CSIDL_BITBUCKET, &ppidl) != NOERROR) { return TRUE; } m_ShellTreeCtrl.SelectPath(ppidl); CMFCShellListCtrl* pList = m_ShellTreeCtrl.GetRelatedList(); ASSERT_VALID(pList); pList->Refresh(); } return TRUE; }
#include "MyView.h" #include "MyListView.h" #include "MyTreeView.h" #ifdef _DEBUG #define new DEBUG_NEW #endif // CMainFrame IMPLEMENT_DYNCREATE(CMainFrame, CFrameWndEx) BEGIN_MESSAGE_MAP(CMainFrame, CFrameWndEx) ON_WM_CREATE() ON_COMMAND(ID_VIEW_CUSTOMIZE, &CMainFrame::OnViewCustomize) ON_REGISTERED_MESSAGE(AFX_WM_CREATETOOLBAR, &CMainFrame::OnToolbarCreateNew) ON_COMMAND_RANGE(ID_VIEW_APPLOOK_WIN_2000, ID_VIEW_APPLOOK_WINDOWS_7, &CMainFrame::OnApplicationLook) ON_UPDATE_COMMAND_UI_RANGE(ID_VIEW_APPLOOK_WIN_2000, ID_VIEW_APPLOOK_WINDOWS_7, &CMainFrame::OnUpdateApplicationLook) 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 theApp.m_nAppLook = theApp.GetInt(_T("ApplicationLook"), ID_VIEW_APPLOOK_VS_2008); } CMainFrame::~CMainFrame() { } int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct) { if (CFrameWndEx::OnCreate(lpCreateStruct) == -1) return -1; BOOL bNameValid; // set the visual manager and style based on persisted value OnApplicationLook(theApp.m_nAppLook); CMFCVisualManager::SetDefaultManager (RUNTIME_CLASS (CMFCVisualManagerWindows)); if (!m_wndMenuBar.Create(this)) { TRACE0("Failed to create menubar\n"); return -1; // fail to create } m_wndMenuBar.SetPaneStyle(m_wndMenuBar.GetPaneStyle() | CBRS_SIZE_DYNAMIC | CBRS_TOOLTIPS | CBRS_FLYBY); // prevent the menu bar from taking the focus on activation CMFCPopupMenu::SetForceMenuFocus(FALSE); 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(theApp.m_bHiColorIcons ? IDR_MAINFRAME_256 : IDR_MAINFRAME)) { TRACE0("Failed to create toolbar\n"); return -1; // fail to create } CString strToolBarName; bNameValid = strToolBarName.LoadString(IDS_TOOLBAR_STANDARD); ASSERT(bNameValid); m_wndToolBar.SetWindowText(strToolBarName); CString strCustomize; bNameValid = strCustomize.LoadString(IDS_TOOLBAR_CUSTOMIZE); ASSERT(bNameValid); m_wndToolBar.EnableCustomizeButton(TRUE, ID_VIEW_CUSTOMIZE, strCustomize); if (!m_wndStatusBar.Create(this)) { TRACE0("Failed to create status bar\n"); return -1; // fail to create } m_wndStatusBar.SetIndicators(indicators, sizeof(indicators)/sizeof(UINT)); // TODO: Delete these five lines if you don't want the toolbar and menubar to be dockable m_wndMenuBar.EnableDocking(CBRS_ALIGN_ANY); m_wndToolBar.EnableDocking(CBRS_ALIGN_ANY); EnableDocking(CBRS_ALIGN_ANY); DockPane(&m_wndMenuBar); DockPane(&m_wndToolBar); // enable Visual Studio 2005 style docking window behavior CDockingManager::SetDockingMode(DT_SMART); // enable Visual Studio 2005 style docking window auto-hide behavior EnableAutoHidePanes(CBRS_ALIGN_ANY); // Enable toolbar and docking window menu replacement EnablePaneMenu(TRUE, ID_VIEW_CUSTOMIZE, strCustomize, ID_VIEW_TOOLBAR); // enable quick (Alt+drag) toolbar customization CMFCToolBar::EnableQuickCustomization(); return 0; } BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs) { if( !CFrameWndEx::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 { CFrameWndEx::AssertValid(); } void CMainFrame::Dump(CDumpContext& dc) const { CFrameWndEx::Dump(dc); } #endif //_DEBUG // CMainFrame message handlers void CMainFrame::OnViewCustomize() { CMFCToolBarsCustomizeDialog* pDlgCust = new CMFCToolBarsCustomizeDialog(this, TRUE /* scan menus */); pDlgCust->Create(); } LRESULT CMainFrame::OnToolbarCreateNew(WPARAM wp,LPARAM lp) { LRESULT lres = CFrameWndEx::OnToolbarCreateNew(wp,lp); if (lres == 0) { return 0; } CMFCToolBar* pUserToolbar = (CMFCToolBar*)lres; ASSERT_VALID(pUserToolbar); BOOL bNameValid; CString strCustomize; bNameValid = strCustomize.LoadString(IDS_TOOLBAR_CUSTOMIZE); ASSERT(bNameValid); pUserToolbar->EnableCustomizeButton(TRUE, ID_VIEW_CUSTOMIZE, strCustomize); return lres; } void CMainFrame::OnApplicationLook(UINT id) { CWaitCursor wait; theApp.m_nAppLook = id; switch (theApp.m_nAppLook) { case ID_VIEW_APPLOOK_WIN_2000: CMFCVisualManager::SetDefaultManager(RUNTIME_CLASS(CMFCVisualManager)); break; case ID_VIEW_APPLOOK_OFF_XP: CMFCVisualManager::SetDefaultManager(RUNTIME_CLASS(CMFCVisualManagerOfficeXP)); break; case ID_VIEW_APPLOOK_WIN_XP: CMFCVisualManagerWindows::m_b3DTabsXPTheme = TRUE; CMFCVisualManager::SetDefaultManager(RUNTIME_CLASS(CMFCVisualManagerWindows)); break; case ID_VIEW_APPLOOK_OFF_2003: CMFCVisualManager::SetDefaultManager(RUNTIME_CLASS(CMFCVisualManagerOffice2003)); CDockingManager::SetDockingMode(DT_SMART); break; case ID_VIEW_APPLOOK_VS_2005: CMFCVisualManager::SetDefaultManager(RUNTIME_CLASS(CMFCVisualManagerVS2005)); CDockingManager::SetDockingMode(DT_SMART); break; case ID_VIEW_APPLOOK_VS_2008: CMFCVisualManager::SetDefaultManager(RUNTIME_CLASS(CMFCVisualManagerVS2008)); CDockingManager::SetDockingMode(DT_SMART); break; case ID_VIEW_APPLOOK_WINDOWS_7: CMFCVisualManager::SetDefaultManager(RUNTIME_CLASS(CMFCVisualManagerWindows7)); CDockingManager::SetDockingMode(DT_SMART); break; default: switch (theApp.m_nAppLook) { case ID_VIEW_APPLOOK_OFF_2007_BLUE: CMFCVisualManagerOffice2007::SetStyle(CMFCVisualManagerOffice2007::Office2007_LunaBlue); break; case ID_VIEW_APPLOOK_OFF_2007_BLACK: CMFCVisualManagerOffice2007::SetStyle(CMFCVisualManagerOffice2007::Office2007_ObsidianBlack); break; case ID_VIEW_APPLOOK_OFF_2007_SILVER: CMFCVisualManagerOffice2007::SetStyle(CMFCVisualManagerOffice2007::Office2007_Silver); break; case ID_VIEW_APPLOOK_OFF_2007_AQUA: CMFCVisualManagerOffice2007::SetStyle(CMFCVisualManagerOffice2007::Office2007_Aqua); break; } CMFCVisualManager::SetDefaultManager(RUNTIME_CLASS(CMFCVisualManagerOffice2007)); CDockingManager::SetDockingMode(DT_SMART); } RedrawWindow(NULL, NULL, RDW_ALLCHILDREN | RDW_INVALIDATE | RDW_UPDATENOW | RDW_FRAME | RDW_ERASE); theApp.WriteInt(_T("ApplicationLook"), theApp.m_nAppLook); } void CMainFrame::OnUpdateApplicationLook(CCmdUI* pCmdUI) { pCmdUI->SetRadio(theApp.m_nAppLook == pCmdUI->m_nID); } BOOL CMainFrame::OnCreateClient(LPCREATESTRUCT lpcs, CCreateContext* pContext) { // TODO: 在此添加专用代码和/或调用基类 CRect rect; GetWindowRect(&rect); m_pTopWndSplitter = new CExSplitter3Wnd; m_pTopWndSplitter->SetStyle(WS_CHILD | WS_VISIBLE | WS_BORDER); m_pTopWndSplitter->SetFirstViewSize(CSize(rect.Height()/2,rect.Width())); m_pTopWndSplitter->SetSecondViewSize(CSize(rect.Height()/2,300)); m_pTopWndSplitter->SetThirdViewSize(CSize(rect.Height()/2,rect.Width()-300)); m_pTopWndSplitter->SetPattern(this,PATTERN_4,RUNTIME_CLASS(CMyTreeView),RUNTIME_CLASS(CMyView),RUNTIME_CLASS(CMyListView),pContext); return CFrameWndEx::OnCreateClient(lpcs, pContext); } CMFCShellTreeCtrl& CMainFrame::GetFolders () { return m_pTopWndSplitter->GetShellTreeCtrl(); }
// ExSplitter3Wnd.cpp: implementation of the CExSplitter3Wnd class. // ////////////////////////////////////////////////////////////////////// #include "stdafx.h" #include "ExSplitter3Wnd.h" #ifdef _DEBUG #undef THIS_FILE static char THIS_FILE[]=__FILE__; #define new DEBUG_NEW #endif ////////////////////////////////////////////////////////////////////// // Construction/Destruction ////////////////////////////////////////////////////////////////////// CExSplitter3Wnd::CExSplitter3Wnd() { CSplitterWndEx::CSplitterWndEx(); m_FirstViewSize = CSize(0,0); m_SecViewSize = CSize(0,0); m_ThirdViewSize= CSize(0,0); } CExSplitter3Wnd::~CExSplitter3Wnd() { CSplitterWndEx::~CSplitterWndEx(); if (m_pwndSplitter!=NULL) delete m_pwndSplitter; } void CExSplitter3Wnd ::SetPattern(CWnd* pParent,SPLIT_PATTERN SplitPattern,CRuntimeClass* pFirstView,CRuntimeClass* pSecView,CRuntimeClass* pThirdView,CCreateContext* pContext) { m_pFirstView = pFirstView; m_pSecView = pSecView; m_pThirdView = pThirdView; m_pContext = pContext; m_SplitPattern = SplitPattern ; switch (m_SplitPattern) { case PATTERN_1: SetPattern1(pParent); break; case PATTERN_2: SetPattern2(pParent); break; case PATTERN_3: SetPattern3(pParent); break; case PATTERN_4: SetPattern4(pParent); break; case PATTERN_5: SetPattern5(pParent); break; case PATTERN_6: SetPattern6(pParent); break; } } void CExSplitter3Wnd ::SetPattern1(CWnd* pParent) { CreateStatic(pParent,1,2); CreateView(0,0,m_pFirstView, m_FirstViewSize,m_pContext); m_pwndSplitter = new CSplitterWndEx; VERIFY(m_pwndSplitter->CreateStatic(this, 2, 1,m_dwStyle, // style, WS_BORDER is needed this->IdFromRowCol(0, 1))); // For portrait VERIFY(m_pwndSplitter->CreateView(0,0,m_pSecView,m_SecViewSize,m_pContext)); VERIFY(m_pwndSplitter->CreateView(1,0,m_pThirdView ,m_ThirdViewSize,m_pContext)); } void CExSplitter3Wnd ::SetPattern2(CWnd* pParent) { CreateStatic(pParent,1,2); m_pwndSplitter = new CSplitterWndEx; m_pwndSplitter->CreateStatic(this, 2, 1,m_dwStyle, // style, WS_BORDER is needed this->IdFromRowCol(0,0)); // For portrait VERIFY(CreateView(0,1,m_pFirstView, m_ThirdViewSize,m_pContext)); VERIFY(m_pwndSplitter->CreateView(0,0,m_pSecView,m_SecViewSize,m_pContext)); VERIFY(m_pwndSplitter->CreateView(1,0,m_pThirdView ,m_ThirdViewSize,m_pContext)); SetColumnInfo(0,m_SecViewSize.cx,10); RecalcLayout(); } void CExSplitter3Wnd ::SetPattern3(CWnd* pParent) { CreateStatic(pParent,2,1); m_pwndSplitter = new CSplitterWndEx; VERIFY(m_pwndSplitter->CreateStatic(this, 1, 2,m_dwStyle, // style, WS_BORDER is needed this->IdFromRowCol(1,0))); // For portrait VERIFY(CreateView(0,0,m_pFirstView, m_FirstViewSize,m_pContext)); VERIFY(m_pwndSplitter->CreateView(0,0,m_pSecView,m_SecViewSize,m_pContext)); VERIFY(m_pwndSplitter->CreateView(0,1,m_pThirdView ,m_ThirdViewSize,m_pContext)); } void CExSplitter3Wnd ::SetPattern4(CWnd* pParent) { CreateStatic(pParent,2,1); m_pwndSplitter = new CSplitterWndEx; m_pwndSplitter->CreateStatic(this, 1, 2,m_dwStyle, // style, WS_BORDER is needed this->IdFromRowCol(0,0)); // For portrait VERIFY(CreateView(1,0,m_pFirstView, m_FirstViewSize,m_pContext)); VERIFY(m_pwndSplitter->CreateView(0,0,m_pSecView,m_SecViewSize,m_pContext)); VERIFY(m_pwndSplitter->CreateView(0,1,m_pThirdView ,m_ThirdViewSize,m_pContext)); SetRowInfo(0,m_SecViewSize.cy,10); RecalcLayout(); } void CExSplitter3Wnd ::SetPattern5(CWnd* pParent) { CreateStatic(pParent,3,1,m_dwStyle); VERIFY(CreateView(0,0,m_pFirstView, m_FirstViewSize,m_pContext)); VERIFY(CreateView(1,0,m_pSecView,m_SecViewSize,m_pContext)); VERIFY(CreateView(2,0,m_pThirdView ,m_ThirdViewSize,m_pContext)); } void CExSplitter3Wnd ::SetPattern6(CWnd* pParent) { CreateStatic(pParent,1,3,m_dwStyle); VERIFY(CreateView(0,0,m_pFirstView, m_FirstViewSize,m_pContext)); VERIFY(CreateView(0,1,m_pSecView,m_SecViewSize,m_pContext)); VERIFY(CreateView(0,2,m_pThirdView ,m_ThirdViewSize,m_pContext)); } void CExSplitter3Wnd::GetFirsWndDim(int* nCurrDim,int* nMinDim) { int nRow = GetRowCount(); int nCol = GetColumnCount(); switch (m_SplitPattern) { case (PATTERN_1): GetColumnInfo(0,*nCurrDim,*nMinDim); break; case PATTERN_2: GetColumnInfo(1,*nCurrDim,*nMinDim); break; case (PATTERN_3): GetRowInfo(0,*nCurrDim,*nMinDim); break; case PATTERN_4: GetRowInfo(1,*nCurrDim,*nMinDim); break; case PATTERN_5: GetRowInfo(0,*nCurrDim,*nMinDim); break; case PATTERN_6: GetColumnInfo(0,*nCurrDim,*nMinDim); break; } } void CExSplitter3Wnd::GetSecWndDim(int* nCurrDim,int* nMinDim) { VERIFY(m_pwndSplitter !=NULL ) ; switch (m_SplitPattern) { case (PATTERN_1): m_pwndSplitter->GetRowInfo(0,*nCurrDim,*nMinDim); break; case PATTERN_2: m_pwndSplitter->GetRowInfo(0,*nCurrDim,*nMinDim); break; case (PATTERN_3): m_pwndSplitter->GetColumnInfo(0,*nCurrDim,*nMinDim); break; case PATTERN_4: m_pwndSplitter->GetColumnInfo(0,*nCurrDim,*nMinDim); break; case PATTERN_5: GetRowInfo(1,*nCurrDim,*nMinDim); break; case PATTERN_6: GetColumnInfo(1,*nCurrDim,*nMinDim); break; } } void CExSplitter3Wnd::GetThirdWndDim(int* nCurrDim,int* nMinDim) { VERIFY(m_pwndSplitter !=NULL ) ; switch (m_SplitPattern) { case (PATTERN_1): m_pwndSplitter->GetRowInfo(1,*nCurrDim,*nMinDim); break; case PATTERN_2: m_pwndSplitter->GetRowInfo(1,*nCurrDim,*nMinDim); break; case (PATTERN_3): m_pwndSplitter->GetColumnInfo(1,*nCurrDim,*nMinDim); break; case PATTERN_4: m_pwndSplitter->GetColumnInfo(1,*nCurrDim,*nMinDim); break; case PATTERN_5: GetRowInfo(2,*nCurrDim,*nMinDim); break; case PATTERN_6: GetColumnInfo(2,*nCurrDim,*nMinDim); break; } } CMFCShellListCtrl& CExSplitter3Wnd::GetShellListCtrl() { return ((CMyListView *)m_pThirdView)->m_ShellListCtrl; } CMFCShellTreeCtrl& CExSplitter3Wnd::GetShellTreeCtrl() { return ((CMyView *)m_pSecView)->m_ShellTreeCtrl; }
// ExSplitter3Wnd.h: interface for the CExSplitter3Wnd class. // ////////////////////////////////////////////////////////////////////// #if !defined(AFX_EXSPLITTER3WND_H__1D7C0013_4AE0_48B3_9688_D660B00D6CB9__INCLUDED_) #define AFX_EXSPLITTER3WND_H__1D7C0013_4AE0_48B3_9688_D660B00D6CB9__INCLUDED_ #if _MSC_VER > 1000 #pragma once #endif // _MSC_VER > 1000 #include "MyView.h" #include "MyListView.h" #include "MyTreeView.h" typedef enum { PATTERN_1 , PATTERN_2 , PATTERN_3 , PATTERN_4 , PATTERN_5 , PATTERN_6 , }SPLIT_PATTERN; ////pattern properties/////////////// /* PATTERN_1 PATTERN_2 *************** **************** first * sec * *sec *first * ******* ********* * *third* *third * * *************** **************** PATTERN_3 PATTERN_4 *************** **************** first * *sec * third* *************** **************** sec * third * * first * *************** **************** PATTERN_5 PATTERN 6 *************** **************** first * first*sec*third* *************** * * * * second * * * * * *************** * * * * third * * * * * *************** **************** */ class CExSplitter3Wnd : public CSplitterWndEx { public: CExSplitter3Wnd(); virtual ~CExSplitter3Wnd(); void SetStyle(DWORD dwStyle) {m_dwStyle = dwStyle ; } void SetPattern(CWnd* pParent,SPLIT_PATTERN SplitPattern,CRuntimeClass* pFirstView,CRuntimeClass* pSecView,CRuntimeClass* pThirdView,CCreateContext* pContext); void SetFirstViewSize(CSize FirstViewSize) {m_FirstViewSize = FirstViewSize ;} void SetSecondViewSize(CSize SecondViewSize) {m_SecViewSize = SecondViewSize ;} void SetThirdViewSize(CSize ThirdViewSize) {m_ThirdViewSize = ThirdViewSize ;} void GetFirsWndDim(int* nCurrDim,int* nMinDim); void GetSecWndDim(int* nCurrDim,int* nMinDim); void GetThirdWndDim(int* nCurrDim,int* nMinDim); CSplitterWndEx* GetSeconderySplitter() {return m_pwndSplitter;} CMFCShellListCtrl& GetShellListCtrl(); CMFCShellTreeCtrl& GetShellTreeCtrl(); CRuntimeClass* m_pFirstView; CRuntimeClass* m_pSecView; CRuntimeClass* m_pThirdView; protected: CSize m_FirstViewSize; CSize m_SecViewSize; CSize m_ThirdViewSize; CCreateContext* m_pContext; DWORD m_dwStyle; SPLIT_PATTERN m_SplitPattern; void SetPattern1(CWnd* pParent); void SetPattern2(CWnd* pParent); void SetPattern3(CWnd* pParent); void SetPattern4(CWnd* pParent); void SetPattern5(CWnd* pParent); void SetPattern6(CWnd* pParent); CSplitterWndEx* m_pwndSplitter ; }; #endif // !defined(AFX_EXSPLITTER3WND_H__1D7C0013_4AE0_48B3_9688_D660B00D6CB9__INCLUDED_)
- 已编辑 Benjamin Brook 2012年7月17日 11:04
全部回复
-
2012年7月17日 11:07
((CMainFrame*) AfxGetMainWnd ())->GetFolders ().SetRelatedList (&m_ShellListCtrl);
这句会造成断言错误,debug后显示是afxshelltreectrl.cpp第73行
void CMFCShellTreeCtrl::SetRelatedList(CMFCShellListCtrl* pShellList)
{
ASSERT_VALID(this); 这个地方断言错误。
m_hwndRelatedList = (pShellList == NULL) ? NULL : pShellList->GetSafeHwnd();
if (pShellList != NULL)
{
pShellList->m_hwndRelatedTree = GetSafeHwnd();
}
}Never give in or give up. Stay healthy and help others.
-
2012年7月18日 6:23
错误信息是什么?
还有,你用的是哪个版本的VS?
Please mark this reply as answer if it helps you! Thanks for your cooperation! Good Luck to you.
- 已编辑 Rebecca Liu 2012年7月18日 6:23
-
2012年7月18日 6:26
谢谢,问题已经搞定了。
问题出在MDI方式下各个View之间进行数据交换、互访方式上。通过DOC来互访就没有问题了。
Never give in or give up. Stay healthy and help others.
- 已标记为答案 Benjamin Brook 2012年7月18日 6:27

