c++系统开发实例精粹内附的80例源代码 环境:windows2000,c++6.0

源代码在线查看: view.cpp

软件大小: 21089 K
上传用户: likefunv
关键词: windows 2000 6.0
下载地址: 免注册下载 普通下载 VIP

相关代码

				// $$root$$View.cpp : implementation of the C$$Safe_root$$View class
				//
				
				#include "stdafx.h"
				#include "$$root$$.h"
				
				#include "$$root$$Doc.h"
				#include "$$root$$View.h"
				#include "SHFileInfo.h"
				#include "resource.h"
				
				#ifdef _DEBUG
				#define new DEBUG_NEW
				#undef THIS_FILE
				static char THIS_FILE[] = __FILE__;
				#endif
				
				/////////////////////////////////////////////////////////////////////////////
				// C$$Safe_root$$View
				
				IMPLEMENT_DYNCREATE(C$$Safe_root$$View, CListView)
				
				BEGIN_MESSAGE_MAP(C$$Safe_root$$View, CListView)
					ON_WM_CONTEXTMENU()
					//{{AFX_MSG_MAP(C$$Safe_root$$View)
					ON_WM_CREATE()
					ON_COMMAND(ID_BACK, OnBlank)
					ON_COMMAND(ID_FORWARD, OnBlank)
					ON_COMMAND(ID_UP, OnBlank)
					ON_COMMAND(ID_CUT, OnBlank)
					ON_COMMAND(ID_COPY, OnBlank)
					ON_COMMAND(ID_PASTE, OnBlank)
					ON_COMMAND(ID_UNDO, OnBlank)
					ON_COMMAND(ID_DELETE, OnBlank)
					ON_COMMAND(ID_PROPERTIES, OnBlank)
					//}}AFX_MSG_MAP
					// Standard printing commands
					ON_COMMAND(ID_FILE_PRINT, CListView::OnFilePrint)
					ON_COMMAND(ID_FILE_PRINT_DIRECT, CListView::OnFilePrint)
					ON_COMMAND(ID_FILE_PRINT_PREVIEW, CListView::OnFilePrintPreview)
				END_MESSAGE_MAP()
				
				/////////////////////////////////////////////////////////////////////////////
				// C$$Safe_root$$View construction/destruction
				
				C$$Safe_root$$View::C$$Safe_root$$View()
				{
					// TODO: add construction code here
				
				}
				
				C$$Safe_root$$View::~C$$Safe_root$$View()
				{
					m_SmallIcons.Detach();
					m_LargeIcons.Detach();
				}
				
				BOOL C$$Safe_root$$View::PreCreateWindow(CREATESTRUCT& cs)
				{
					// TODO: Modify the Window class or styles here by modifying
					//  the CREATESTRUCT cs
					cs.style |= LVS_EDITLABELS | LVS_REPORT;
					return CListView::PreCreateWindow(cs);
				}
				
				/////////////////////////////////////////////////////////////////////////////
				// C$$Safe_root$$View drawing
				
				void C$$Safe_root$$View::OnDraw(CDC* pDC)
				{
					C$$Safe_root$$Doc* pDoc = GetDocument();
					ASSERT_VALID(pDoc);
					// TODO: add draw code for native data here
				}
				
				void C$$Safe_root$$View::OnInitialUpdate()
				{
					CListView::OnInitialUpdate();
				
					// TODO: You may populate your ListView with items by directly accessing
					//  its list control through a call to GetListCtrl().
					int nCols = 4;
					int nColSize[] = { 150, 80, 125, 150 };
					CString strColText[] = { 	_T("Name"), _T("Size"), _T("Type"), _T("Modified") };
				
					m_pListCtrl = &GetListCtrl();
				
					// Get the log font.
					NONCLIENTMETRICS ncm;
					ncm.cbSize = sizeof(NONCLIENTMETRICS);
					VERIFY(::SystemParametersInfo(SPI_GETNONCLIENTMETRICS,
						sizeof(NONCLIENTMETRICS), &ncm, 0));
					m_Font.CreateFontIndirect(&ncm.lfMessageFont);
				    SetFont(&m_Font);
				
					BuildColumns(nCols, nColSize, strColText);
				}
				
				void C$$Safe_root$$View::BuildColumns(int nCols, int * nWidth, CString * csCol)
				{
					//insert columns
					int i;
					LV_COLUMN lvc;
				
					lvc.mask = LVCF_FMT | LVCF_WIDTH | LVCF_TEXT | LVCF_SUBITEM;
					CString	strTemp;
					for(i = 0; i < nCols; i++)
					{
						lvc.iSubItem = i;
						lvc.pszText = (char*)(LPCTSTR)csCol[i];
						lvc.cx = nWidth[i];
						lvc.fmt = LVCFMT_LEFT;
						m_pListCtrl->InsertColumn(i,&lvc);
					}
				}
				
				void C$$Safe_root$$View::FormatList(CString csPath)
				{
					int nDir = 0;
				
					m_strCurDirectory = csPath;
				
					if (csPath.GetAt(csPath.GetLength()-1) == '\\')
						csPath += "*.*";
					else
						csPath += "\\*.*";
				
					// Clear the list control.
					m_pListCtrl->DeleteAllItems();
				
					// Instanciate a CFileFind object.
					CFileFind FoundFiles;
				
					// Do the first check, pass in full path + filter.
					BOOL bContinue = FoundFiles.FindFile(csPath);
				
					while (bContinue == TRUE)
					{
						// Call FindNextFile so we can use the class member to get
						// the results of the FindFile call above (you _MUST_ call
						// FindNextFile before the CFileFind class members return 
						// valid info
						bContinue = FoundFiles.FindNextFile();
						CSHFileInfo file(&FoundFiles);
				
						// Get the icon and list index.
						int nIcon = file.GetIconIndex();
						int nIndx = m_pListCtrl->GetItemCount();
				
						if (FoundFiles.IsDirectory())
						{
							if (FoundFiles.IsDots())
									continue;
				
							nIndx = nDir;
							nDir++;
						}
				
						// Add the found item to the list control.
						m_pListCtrl->InsertItem(nIndx, file.GetDisplayName(), nIcon);
						
						if (!FoundFiles.IsDirectory()) {
							// If not a directory, insert size in bytes.
							m_pListCtrl->SetItem(nIndx, 1, LVIF_TEXT | LVIF_STATE, file.GetFileSize(),
								0, INDEXTOSTATEIMAGEMASK(1), LVIS_STATEIMAGEMASK, NULL);
						}
				
						// Insert the document title.
						m_pListCtrl->SetItem(nIndx, 2, LVIF_TEXT | LVIF_STATE, file.GetDescription(),
							0, INDEXTOSTATEIMAGEMASK(1), LVIS_STATEIMAGEMASK, NULL);
				
						// Insert the last time modified.
						m_pListCtrl->SetItem(nIndx, 3, LVIF_TEXT | LVIF_STATE, file.GetLastWriteTime(),
							0, INDEXTOSTATEIMAGEMASK(1), LVIS_STATEIMAGEMASK, NULL);
					}
				
					// Must call close to make sure system resources are freed
					FoundFiles.Close();
				}
				
				/////////////////////////////////////////////////////////////////////////////
				// C$$Safe_root$$View printing
				
				BOOL C$$Safe_root$$View::OnPreparePrinting(CPrintInfo* pInfo)
				{
					// default preparation
					return DoPreparePrinting(pInfo);
				}
				
				void C$$Safe_root$$View::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
				{
					// TODO: add extra initialization before printing
				}
				
				void C$$Safe_root$$View::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
				{
					// TODO: add cleanup after printing
				}
				
				/////////////////////////////////////////////////////////////////////////////
				// C$$Safe_root$$View diagnostics
				
				#ifdef _DEBUG
				void C$$Safe_root$$View::AssertValid() const
				{
					CListView::AssertValid();
				}
				
				void C$$Safe_root$$View::Dump(CDumpContext& dc) const
				{
					CListView::Dump(dc);
				}
				
				C$$Safe_root$$Doc* C$$Safe_root$$View::GetDocument() // non-debug version is inline
				{
					ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(C$$Safe_root$$Doc)));
					return (C$$Safe_root$$Doc*)m_pDocument;
				}
				#endif //_DEBUG
				
				/////////////////////////////////////////////////////////////////////////////
				// C$$Safe_root$$View message handlers
				
				
				int C$$Safe_root$$View::OnCreate(LPCREATESTRUCT lpCreateStruct) 
				{
					if (CListView::OnCreate(lpCreateStruct) == -1)
						return -1;
					
					CSHFileInfo sfi;
					sfi.GetSystemImageList(&m_SmallIcons, &m_LargeIcons);
					GetListCtrl().SetImageList(&m_SmallIcons, LVSIL_SMALL);
					GetListCtrl().SetImageList(&m_LargeIcons, LVSIL_NORMAL);
					
					return 0;
				}
				
				
				void C$$Safe_root$$View::OnContextMenu(CWnd*, CPoint point)
				{
					if (point.x == -1 && point.y == -1){
						//keystroke invocation
						CRect rect;
						GetClientRect(rect);
						ClientToScreen(rect);
						
						point = rect.TopLeft();
						point.Offset(5, 5);
					}
					
					CMenu menu;
					VERIFY(menu.LoadMenu(IDR_POPDOWN));
					
					CMenu* pPopup = menu.GetSubMenu(1);
					ASSERT(pPopup != NULL);
					CWnd* pWndPopupOwner = this;
					
					while (pWndPopupOwner->GetStyle() & WS_CHILD)
						pWndPopupOwner = pWndPopupOwner->GetParent();
					
					pPopup->TrackPopupMenu(TPM_LEFTALIGN | TPM_RIGHTBUTTON, point.x, point.y,
						pWndPopupOwner);
				}
				
				void C$$Safe_root$$View::OnBlank() 
				{
					// TODO: Add your command handler code here
					
				}
							

相关资源