📄 resexplorerview.cpp
字号:
// resExplorerView.cpp : implementation of the CResExplorerView class
//
#include "stdafx.h"
#include "resExplorer.h"
#include "resExplorerDoc.h"
#include "resExplorerView.h"
#include "ResExplorerTree.h"
#include "MainFrm.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CResExplorerView
IMPLEMENT_DYNCREATE(CResExplorerView, CView)
BEGIN_MESSAGE_MAP(CResExplorerView, CView)
//{{AFX_MSG_MAP(CResExplorerView)
ON_WM_CREATE()
ON_WM_SIZE()
//}}AFX_MSG_MAP
// Standard printing commands
ON_NOTIFY(NM_RCLICK, IDC_LIST_VIEW, OnRclickListView)
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()
/////////////////////////////////////////////////////////////////////////////
// CResExplorerView construction/destruction
CResExplorerView::CResExplorerView()
{
// TODO: add construction code here
}
CResExplorerView::~CResExplorerView()
{
}
BOOL CResExplorerView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CView::PreCreateWindow(cs);
}
/////////////////////////////////////////////////////////////////////////////
// CResExplorerView drawing
void CResExplorerView::OnDraw(CDC* pDC)
{
CResExplorerDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// TODO: add draw code for native data here
}
/////////////////////////////////////////////////////////////////////////////
// CResExplorerView printing
BOOL CResExplorerView::OnPreparePrinting(CPrintInfo* pInfo)
{
// default preparation
return DoPreparePrinting(pInfo);
}
void CResExplorerView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add extra initialization before printing
}
void CResExplorerView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add cleanup after printing
}
/////////////////////////////////////////////////////////////////////////////
// CResExplorerView diagnostics
#ifdef _DEBUG
void CResExplorerView::AssertValid() const
{
CView::AssertValid();
}
void CResExplorerView::Dump(CDumpContext& dc) const
{
CView::Dump(dc);
}
CResExplorerDoc* CResExplorerView::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CResExplorerDoc)));
return (CResExplorerDoc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CResExplorerView message handlers
int CResExplorerView::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CView::OnCreate(lpCreateStruct) == -1)
return -1;
// TODO: Add your specialized creation code here
//创建ListCtrl列表控件
if (!this->m_ListCtrl.Create(WS_VISIBLE | WS_CHILD | WS_CLIPCHILDREN
| LVS_REPORT | LVS_SHAREIMAGELISTS | LVS_EDITLABELS|LVS_AUTOARRANGE|LVS_SINGLESEL,
CRect(0,0,0,0), this, IDC_LIST_VIEW))
{
TRACE0("Failed to create list control.\n");
return -1;
}
//设置图标列表对象
CMainFrame* MainFrame1=(CMainFrame*)this->GetParent()->GetParent();
CResExplorerTree* pTree=(CResExplorerTree*)(MainFrame1->m_wndSplitter.GetPane(0,0));
m_pSmallImageList=&(pTree->m_smallImageList);
m_pLargeImageList=&(pTree->m_largeImageList);
m_ListCtrl.SetImageList(m_pSmallImageList,LVSIL_SMALL);
m_ListCtrl.SetImageList(m_pLargeImageList,LVSIL_NORMAL);
LV_COLUMN lvColumn;
int i;
TCHAR szString[5][20] = {"名称", "大小", "类型", "修改时间","标识"};
//清空数据
m_ListCtrl.DeleteAllItems();
//初始化列
lvColumn.mask = LVCF_FMT | LVCF_WIDTH | LVCF_TEXT | LVCF_SUBITEM;
lvColumn.fmt = LVCFMT_LEFT;
lvColumn.cx = 120;
for(i = 0; i < 5; i++)
{
lvColumn.pszText = szString[i];
this->m_ListCtrl.InsertColumn(i, &lvColumn);
}
return 0;
}
void CResExplorerView::OnSize(UINT nType, int cx, int cy)
{
CView::OnSize(nType, cx, cy);
// TODO: Add your message handler code here
if(this->m_ListCtrl.GetSafeHwnd()) {
this->m_ListCtrl.MoveWindow(0,0,cx,cy);
}
}
BOOL CResExplorerView::InsertXMLItem(MSXML::IXMLDOMElement *node)
{
MSXML::IXMLDOMNodeListPtr pNodeList;
pNodeList=node->getElementsByTagName("item");
long count=pNodeList->Getlength();
m_ListCtrl.DeleteAllItems();
m_ListCtrl.SetItemCount(count);
LV_ITEM lvItem;
TCHAR szString[MAX_PATH];
lvItem.mask= LVIF_TEXT|LVIF_IMAGE ;
//if(j){
//lvItem.mask= LVIF_TEXT|LVIF_INDENT ;
//}
for(long i=0;i<count;i++){
MSXML::IXMLDOMNodePtr pNode=pNodeList->Getitem(i);
MSXML::IXMLDOMNamedNodeMap* namedNodeMap = NULL;
HRESULT hr = S_OK;
hr = pNode->get_attributes(&namedNodeMap);
if (SUCCEEDED(hr) && namedNodeMap != NULL) {
MSXML::IXMLDOMNodePtr pTextNode=namedNodeMap->getNamedItem("text");
BSTR text;
hr=pTextNode->get_text(&text);
MSXML::IXMLDOMNodePtr pIDNode=namedNodeMap->getNamedItem("id");
BSTR id;
hr=pIDNode->get_text(&id);
MSXML::IXMLDOMNodePtr pPIDNode=namedNodeMap->getNamedItem("pid");
BSTR pid;
hr=pPIDNode->get_text(&pid);
MSXML::IXMLDOMNodePtr pIconNode=namedNodeMap->getNamedItem("icon");
BSTR icon;
hr=pIconNode->get_text(&icon);
MSXML::IXMLDOMNodePtr pSizeNode=namedNodeMap->getNamedItem("size");
BSTR size;
hr=pSizeNode->get_text(&size);
MSXML::IXMLDOMNodePtr pModifyTimeNode=namedNodeMap->getNamedItem("modifyTime");
BSTR modifyTime;
hr=pModifyTimeNode->get_text(&modifyTime);
MSXML::IXMLDOMNodePtr pTypeNode=namedNodeMap->getNamedItem("type");
BSTR type;
hr=pTypeNode->get_text(&type);
lvItem.iItem=i;
lvItem.iSubItem=0;
//lstrcpy(lvItem.pszText,CString(text));
//lvItem.pszText=(char *)(text);
wsprintf(szString, "%s", CString(text));
lvItem.pszText=szString;
lvItem.iImage=this->GetIconIndex(CString(icon));
m_ListCtrl.InsertItem(&lvItem);
lvItem.iItem=i;
lvItem.iSubItem=1;
wsprintf(szString, "%s", CString(size));
lvItem.pszText=szString;
m_ListCtrl.SetItem(&lvItem);
lvItem.iItem=i;
lvItem.iSubItem=2;
//lstrcpy(lvItem.pszText,CString(type));
wsprintf(szString, "%s", CString(type));
lvItem.pszText=szString;
m_ListCtrl.SetItem(&lvItem);
lvItem.iItem=i;
lvItem.iSubItem=3;
//lstrcpy(lvItem.pszText,CString(modifyTime));
wsprintf(szString, "%s", CString(modifyTime));
lvItem.pszText=szString;
m_ListCtrl.SetItem(&lvItem);
lvItem.iItem=i;
lvItem.iSubItem=4;
//lstrcpy(lvItem.pszText,CString(modifyTime));
wsprintf(szString, "%s", CString(id));
lvItem.pszText=szString;
m_ListCtrl.SetItem(&lvItem);
}
}
return TRUE;
}
int CResExplorerView::GetIconIndex(const CString &csFileName)
{
CMainFrame* MainFrame1=(CMainFrame*)this->GetParent()->GetParent();
CResExplorerTree* pTree=(CResExplorerTree*)(MainFrame1->m_wndSplitter.GetPane(0,0));
return pTree->GetIconIndex(csFileName);
}
DWORD CResExplorerView::GetViewType()
{
return(m_ListCtrl.GetStyle() & LVS_TYPEMASK);
}
BOOL CResExplorerView::SetViewType(DWORD dwViewType)
{
return(m_ListCtrl.ModifyStyle(LVS_TYPEMASK,dwViewType & LVS_TYPEMASK));
}
BOOL CResExplorerView::SwitchView(DWORD dwViewType)
{
if (GetViewType() !=dwViewType){
return SetViewType(dwViewType);
}
return true;
}
void CResExplorerView::OnRclickListView(NMHDR* pNMHDR, LRESULT* pResult)
{
// TODO: Add your control notification handler code here
CMenu t_Menu;
CMenu* t_pSubMenu;
CPoint m_Point;
GetCursorPos(&m_Point);
m_ListCtrl.ScreenToClient(&m_Point);//转换为Client
UINT flag;
int item=m_ListCtrl.HitTest(m_Point,&flag);
if(flag&LVHT_ONITEM){
//右键选中
//增加文件操作菜单
t_Menu.LoadMenu (IDR_LISTCTRL_VIEWSTYLE);
t_pSubMenu=t_Menu.GetSubMenu(1);
}else{
t_Menu.LoadMenu (IDR_LISTCTRL_VIEWSTYLE);
t_pSubMenu=t_Menu.GetSubMenu(0);
}
m_ListCtrl.ClientToScreen(&m_Point);
CMainFrame* MainFrame1=(CMainFrame*)this->GetParent()->GetParent();
HWND safeHwnd=(MainFrame1->GetSafeHwnd());
t_pSubMenu->TrackPopupMenu(TPM_RIGHTBUTTON, m_Point.x,m_Point.y,MainFrame1);
*pResult = 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -