⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 leftview.cpp

📁 《Windows多媒体编程基础》书第五章源代码SimpleBrowse一款简单易用的图片浏览器。其他目录中都是编译时需要的库和包含文件等(Bin是调试输出)。该工程较好的演示了一个工程中个要素之间的关
💻 CPP
字号:
// LeftView.cpp : implementation of the CLeftView class
//

#include "stdafx.h"
#include "SimpleBrowse.h"

#include "MainFrm.h"
#include "SimpleBrowseDoc.h"
#include "SimpleBrowseView.h"
#include "LeftView.h"

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

/////////////////////////////////////////////////////////////////////////////
// CLeftView

IMPLEMENT_DYNCREATE(CLeftView, CView)

BEGIN_MESSAGE_MAP(CLeftView, CView)
	//{{AFX_MSG_MAP(CLeftView)
	ON_WM_CREATE()
	ON_WM_SIZE()
	ON_NOTIFY(TVN_ITEMEXPANDING, IDC_SHELL_TREE, OnItemexpanding)
	ON_NOTIFY(TVN_SELCHANGED, IDC_SHELL_TREE, OnSelchanged)
	ON_NOTIFY(NM_RCLICK, IDC_SHELL_TREE, OnRclick)
	ON_NOTIFY(TVN_DELETEITEM, IDC_SHELL_TREE, OnDeleteitem)
	//}}AFX_MSG_MAP
	// Standard printing commands
	ON_COMMAND(ID_FILE_PRINT, CView::OnFilePrint)
	ON_COMMAND(ID_FILE_PRINT_DIRECT, CView::OnFilePrint)
	ON_COMMAND(ID_FILE_PRINT_PREVIEW, CView::OnFilePrintPreview)
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CLeftView construction/destruction

CLeftView::CLeftView()
{
	// TODO: add construction code here

}

CLeftView::~CLeftView()
{
}

BOOL CLeftView::PreCreateWindow(CREATESTRUCT& cs)
{
	// TODO: Modify the Window class or styles here by modifying
	//  the CREATESTRUCT cs

	return CView::PreCreateWindow(cs);
}

/////////////////////////////////////////////////////////////////////////////
// CLeftView drawing

void CLeftView::OnDraw(CDC* pDC)
{
	CSimpleBrowseDoc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);

	// TODO: add draw code for native data here
}


/////////////////////////////////////////////////////////////////////////////
// CLeftView printing

BOOL CLeftView::OnPreparePrinting(CPrintInfo* pInfo)
{
	// default preparation
	return DoPreparePrinting(pInfo);
}

void CLeftView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
	// TODO: add extra initialization before printing
}

void CLeftView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
	// TODO: add cleanup after printing
}

void CLeftView::OnInitialUpdate()
{
	CView::OnInitialUpdate();

	// TODO: You may populate your TreeView with items by directly accessing
	//  its tree control through a call to GetTreeCtrl().
}

/////////////////////////////////////////////////////////////////////////////
// CLeftView diagnostics

#ifdef _DEBUG
void CLeftView::AssertValid() const
{
	CView::AssertValid();
}

void CLeftView::Dump(CDumpContext& dc) const
{
	CView::Dump(dc);
}

CSimpleBrowseDoc* CLeftView::GetDocument() // non-debug version is inline
{
	ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CSimpleBrowseDoc)));
	return (CSimpleBrowseDoc*)m_pDocument;
}
#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// CLeftView message handlers

int CLeftView::OnCreate(LPCREATESTRUCT lpCreateStruct) 
{
	if (CView::OnCreate(lpCreateStruct) == -1)
		return -1;
	
	// TODO: Add your specialized creation code here
	// Create the shell tree control.
	if (!m_TreeCtrl.Create(
		WS_VISIBLE|TVS_HASLINES|TVS_LINESATROOT|TVS_HASBUTTONS,
		CRect(0,0,0,0), this, IDC_SHELL_TREE))
	{
		TRACE0("Unable to create tree view control.\n");
		return -1;
	}

	m_TreeCtrl.ModifyStyleEx(0, WS_EX_STATICEDGE);
	
	// Create and associate the tree image list.
	m_TreeCtrl.EnableImages();
	m_TreeCtrl.PopulateTree();
	
	return 0;
}

void CLeftView::OnSize(UINT nType, int cx, int cy) 
{
	CView::OnSize(nType, cx, cy);
	
	// TODO: Add your message handler code here
	if (m_TreeCtrl.GetSafeHwnd())
		m_TreeCtrl.MoveWindow(0,0,cx,cy);
	
}

void CLeftView::OnItemexpanding(NMHDR* pNMHDR, LRESULT* pResult) 
{
	NM_TREEVIEW* pNMTreeView = (NM_TREEVIEW*)pNMHDR;
	// TODO: Add your control notification handler code here
	m_TreeCtrl.OnFolderExpanding(pNMHDR,pResult);
	m_TreeCtrl.Invalidate();
	
	*pResult = 0;
}

void CLeftView::OnSelchanged(NMHDR* pNMHDR, LRESULT* pResult) 
{
	NM_TREEVIEW* pNMTreeView = (NM_TREEVIEW*)pNMHDR;

	CMainFrame *pFrame = (CMainFrame*)AfxGetApp()->m_pMainWnd;
	if (!pFrame)
		return;

	CSimpleBrowseView *pView = (CSimpleBrowseView*)pFrame->GetRightPane();

	CString szPath;
	if(m_TreeCtrl.OnFolderSelected(pNMHDR,pResult,szPath))
	{
		pView->FormatList(szPath);
	}
	else 
	{
		pView->m_ThumbListCtrl.DeleteAllItems();
	}

	*pResult = 0;
}

void CLeftView::OnRclick(NMHDR* pNMHDR, LRESULT* pResult) 
{
	// TODO: Add your control notification handler code here
	m_TreeCtrl.GetContextMenu(pNMHDR,pResult);
	*pResult = 0;
}

void CLeftView::OnDeleteitem(NMHDR* pNMHDR, LRESULT* pResult) 
{
	NM_TREEVIEW* pNMTreeView = (NM_TREEVIEW*)pNMHDR;
	// TODO: Add your control notification handler code here
	m_TreeCtrl.OnDeleteShellItem(pNMHDR,pResult);
	*pResult = 0;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -