📄 lstviewfolder.cpp
字号:
// LSTViewFolder.cpp : implementation file
//
#include "stdafx.h"
#include "gstools.h"
#include "LSTViewFolder.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// LSTViewFolder
IMPLEMENT_DYNCREATE(LSTViewFolder, CListViewEx)
LSTViewFolder::LSTViewFolder()
{
m_bUp = false;
}
LSTViewFolder::~LSTViewFolder()
{
// m_font.DeleteObject();
}
BEGIN_MESSAGE_MAP(LSTViewFolder, CListViewEx)
//{{AFX_MSG_MAP(LSTViewFolder)
ON_WM_CREATE()
ON_NOTIFY_REFLECT(NM_DBLCLK, OnDblclk)
ON_COMMAND(ID_LIST_VIEW_DETAILS, OnListViewDetails)
ON_COMMAND(ID_LIST_VIEW_LARGEICONS, OnListViewLargeicons)
ON_COMMAND(ID_LIST_VIEW_LIST, OnListViewList)
ON_COMMAND(ID_LIST_VIEW_SMALLICONS, OnListViewSmallicons)
ON_UPDATE_COMMAND_UI(ID_LIST_VIEW_DETAILS, OnUpdateListViewDetails)
ON_UPDATE_COMMAND_UI(ID_LIST_VIEW_LARGEICONS, OnUpdateListViewLargeicons)
ON_UPDATE_COMMAND_UI(ID_LIST_VIEW_LIST, OnUpdateListViewList)
ON_UPDATE_COMMAND_UI(ID_LIST_VIEW_SMALLICONS, OnUpdateListViewSmallicons)
ON_WM_SHOWWINDOW()
ON_COMMAND(ID_MANAGER_DELETE, OnManagerDelete)
ON_WM_CONTEXTMENU()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// LSTViewFolder drawing
void LSTViewFolder::OnDraw(CDC* pDC)
{
CDocument* pDoc = GetDocument();
// TODO: add draw code here
}
/////////////////////////////////////////////////////////////////////////////
// LSTViewFolder diagnostics
#ifdef _DEBUG
void LSTViewFolder::AssertValid() const
{
CListViewEx::AssertValid();
}
void LSTViewFolder::Dump(CDumpContext& dc) const
{
CListViewEx::Dump(dc);
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// LSTViewFolder message handlers
int LSTViewFolder::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CListViewEx::OnCreate(lpCreateStruct) == -1)
return -1;
// TODO: Add your specialized creation code here
//GetListCtrl().ModifyListCtrlStyleEx(0, LVS_EX_HEADERDRAGDROP|LVS_EX_GRIDLINES|LVS_EX_FULLROWSELECT);
// LOGFONT lf;
// memset(&lf,0,sizeof(LOGFONT));
// lf.lfWeight=500;
// lf.lfHeight=20;
// m_font.CreateFontIndirect(&lf);
// m_font.CreatePointFont(120, "宋体");
// GetListCtrl().SetFont(&m_font);
GetListCtrl().SetExtendedStyle(LVS_EX_HEADERDRAGDROP|LVS_EX_GRIDLINES|LVS_EX_FULLROWSELECT);
m_bClientWidthSel = true;
GetListCtrl().SetImageList(&g_icon_list_large, LVSIL_NORMAL);
GetListCtrl().SetImageList(&g_icon_list_small, LVSIL_SMALL);
// GetListCtrl().SetImageList(&g_icon_list_state, LVSIL_STATE);
GetListCtrl().InsertColumn(0,"名称",LVCFMT_LEFT,130);
GetListCtrl().InsertColumn(1,"类型",LVCFMT_CENTER,50);
GetListCtrl().InsertColumn(2,"大小",LVCFMT_RIGHT,70);
GetListCtrl().InsertColumn(3,"路径",LVCFMT_LEFT,150);
GetListCtrl().InsertColumn(4,"修改时间",LVCFMT_LEFT,120);
GetListCtrl().InsertColumn(5,"资源位置",LVCFMT_LEFT,300);
GetListCtrl().InsertItem(0,"test");
GetListCtrl().DeleteAllItems();
// GetListCtrl().SetItemText(0,1,"aaaaaaaaaaaa");
// GetListCtrl().InsertItem(1,"test");
// GetListCtrl().SetItemText(1,1,"aaaaaaaaaaaa");
// GetListCtrl().InsertItem(2,"test");
// GetListCtrl().SetItemText(2,1,"aaaaaaaaaaaa");
return 0;
}
BOOL LSTViewFolder::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Add your specialized code here and/or call the base class
// cs.style |= TVXS_HEADERDRAGDROP|LVS_EX_HEADERDRAGDROP|LVS_EX_GRIDLINES|LVS_EX_FULLROWSELECT|LVS_REPORT;
// cs.style &= ~LVS_TYPEMASK;
// cs.style |= LVS_REPORT ;//| LVS_OWNERDRAWFIXED;
return CListViewEx::PreCreateWindow(cs);
}
void LSTViewFolder::UpdateItems()
{
CListCtrl& ListCtrl = GetListCtrl();
ListCtrl.DeleteAllItems();
HTREEITEM hti_root;
int i=0;
char szTemp[PATH_SIZE];
m_bUp = false;
if(g_szWizardPath[0]==0)
{
hti_root = g_pWizard->GetChildItem(g_pWizard->GetRoot());
}
else
{
hti_root = g_pWizard->GetChildItem(g_pWizard->FindPath(g_szWizardPath));
//CGsFunc::Path_GetParentPath(szTemp, g_szWizardPath);
//if(szTemp[0]!=0)
//{
ListCtrl.InsertItem(i, "..", 1);
m_bUp = true;
i++;
//}
}
HTREEITEM hti = hti_root;
while(hti!=NULL)
{
CString str = g_pWizard->GetItemPath(hti);
if(g_pWizard->GetPathFFT((LPCSTR)str)==GSF_FOLDER)
{
char szStr[PATH_SIZE];
CGsFunc::Path_RectifyPath(szStr, (LPCSTR)str);
CGsFunc::Path_GetPathFile(szTemp, szStr);
ListCtrl.InsertItem(i, szTemp, GetFFTIcon(g_pWizard->GetPathFFT((LPCSTR)str)));
ListCtrl.SetItemText(i, 1, (LPCSTR)GetFFTName(g_pWizard->GetPathFFT((LPCSTR)str)));
ListCtrl.SetItemText(i, 3, (LPCSTR)str);
i++;
}
hti = g_pWizard->GetNextSiblingItem(hti);
}
hti = hti_root;
while(hti!=NULL)
{
CString str = g_pWizard->GetItemPath(hti);
if(g_pWizard->GetPathFFT((LPCSTR)str)!=GSF_FOLDER)
{
char szStr[PATH_SIZE];
CGsFunc::Path_RectifyPath(szStr, (LPCSTR)str);
CGsFunc::Path_GetPathFile(szTemp, szStr);
ListCtrl.InsertItem(i, szTemp, GetFFTIcon(g_pWizard->GetPathFFT((LPCSTR)str)));
ListCtrl.SetItemText(i, 1, (LPCSTR)GetFFTName(g_pWizard->GetPathFFT((LPCSTR)str)));
ListCtrl.SetItemText(i, 3, (LPCSTR)str);
struct _stat file_stat;
GSFILE_INFO* pfi = g_source.FindSource(str);
if(pfi)
{
ListCtrl.SetItemText(i, 5, pfi->strFile);
if(-1!=_stat(pfi->strFile, &file_stat))
{
char strSize[255];
sprintf(strSize, "%ld", file_stat.st_size);
ListCtrl.SetItemText(i, 2, strSize);
strftime(strSize, 255, "%Y-%m-%d", gmtime(&file_stat.st_mtime));
char ttime[100];
sprintf(ttime, "%s", ctime( &file_stat.st_mtime) );
ttime[16]=0;
sprintf(strSize, "%s %s", strSize, ttime+11);
ListCtrl.SetItemText(i, 4, strSize);
}
}
i++;
}
hti = g_pWizard->GetNextSiblingItem(hti);
}
}
void LSTViewFolder::OnDblclk(NMHDR* pNMHDR, LRESULT* pResult)
{
// TODO: Add your control notification handler code here
// if(g_szWizardPath[0]==0)
// return;
int nItem = -1;
CListCtrl& ListCtrl = GetListCtrl();
POSITION pos = ListCtrl.GetFirstSelectedItemPosition();
while (pos)
{
nItem = ListCtrl.GetNextSelectedItem(pos);
}
if(nItem<0)
return;
if(nItem==0 && m_bUp)
{
char szTemp[PATH_SIZE];
CGsFunc::Path_GetParentPath(szTemp, (LPCSTR)g_pWizard->GetCurrentItemPath());
g_pWizard->SelectPath(szTemp);
}
else
{
if(g_szWizardPath[0]==0)
{
if(ListCtrl.GetItemText(nItem, 1)==_T("文件夹"))
{
g_pWizard->SelectPath((LPCSTR)(ListCtrl.GetItemText(nItem, 0)));
}
else
{
g_pWizard->SelectFile((LPCSTR)ListCtrl.GetItemText(nItem, 3));
}
}
else
{
if(ListCtrl.GetItemText(nItem, 1)==_T("文件夹"))
{
g_pWizard->SelectPath( (LPCSTR)ListCtrl.GetItemText(nItem, 3) );//(CString(g_szWizardPath) + CString("\\") + ListCtrl.GetItemText(nItem, 0)) );
}
else
{
g_pWizard->SelectFile( (LPCSTR)ListCtrl.GetItemText(nItem, 3) );//(CString(g_szWizardPath) + CString("\\") + ListCtrl.GetItemText(nItem, 0)) );
}
}
}
g_pWizard->UpdateSelect();
*pResult = 0;
}
void LSTViewFolder::OnListViewDetails()
{
// TODO: Add your command handler code here
if ((GetViewType() != LVS_REPORT))
{
SetViewType(LVS_REPORT);
}
}
void LSTViewFolder::OnListViewLargeicons()
{
// TODO: Add your command handler code here
if (GetViewType() != LVS_ICON)
SetViewType(LVS_ICON);
}
void LSTViewFolder::OnListViewList()
{
// TODO: Add your command handler code here
if (GetViewType() != LVS_LIST)
SetViewType(LVS_LIST);
}
void LSTViewFolder::OnListViewSmallicons()
{
// TODO: Add your command handler code here
if (GetViewType() != LVS_SMALLICON)
SetViewType(LVS_SMALLICON);
}
void LSTViewFolder::OnUpdateListViewDetails(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
pCmdUI->SetCheck((GetViewType() == LVS_REPORT));
}
void LSTViewFolder::OnUpdateListViewLargeicons(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
pCmdUI->SetCheck(GetViewType() == LVS_ICON);
}
void LSTViewFolder::OnUpdateListViewList(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
pCmdUI->SetCheck(GetViewType() == LVS_LIST);
}
void LSTViewFolder::OnUpdateListViewSmallicons(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
pCmdUI->SetCheck(GetViewType() == LVS_SMALLICON);
}
void LSTViewFolder::OnShowWindow(BOOL bShow, UINT nStatus)
{
CListViewEx::OnShowWindow(bShow, nStatus);
// TODO: Add your message handler code here
//if(bShow)
// SetFocus();
if(!g_pMainFrame)
return;
CControlBar* pBar = g_pMainFrame->GetControlBar(ID_TOOLBAR_LIST_VIEW);
ASSERT(pBar != NULL);
ASSERT_KINDOF(SECControlBar, pBar);
g_pMainFrame->ShowControlBar(pBar, bShow, FALSE);
}
void LSTViewFolder::OnManagerDelete()
{
// TODO: Add your command handler code here
if(NULL==g_pWizard)
return;
// CString str = g_pWizard->GetCurrentItemPath();
// char strTemp[PATH_SIZE];
int nItem = -1;
CListCtrl& ListCtrl = GetListCtrl();
POSITION pos = ListCtrl.GetFirstSelectedItemPosition();
while (pos)
{
nItem = ListCtrl.GetNextSelectedItem(pos);
if(nItem==0 && m_bUp)
{
continue;
}
CString strItem = ListCtrl.GetItemText(nItem, 3);
g_pWizard->DeleteItems((LPCSTR)strItem);
g_source.DeleteFile((LPCSTR)strItem);
}
UpdateItems();
// CGsFunc::Path_GetParentPath(strTemp, (LPCSTR)str);
// g_pWizard->SelectPath(strTemp);
// g_pWizard->DeleteItems((LPCSTR)str);
// g_source.DeleteFile((LPCSTR)str);
// g_pWizard->UpdateSelect();
}
void LSTViewFolder::OnContextMenu(CWnd* pWnd, CPoint point)
{
// TODO: Add your message handler code here
CMenu menu;
CMenu *pop_up_menu;
int sel_count = GetListCtrl().GetSelectedCount();
menu.LoadMenu(IDR_MANAGER_MENU);
if(sel_count==0)
{
pop_up_menu = menu.GetSubMenu(1);
}
else if(sel_count==1)
{
pop_up_menu = menu.GetSubMenu(2);
}
else
{
pop_up_menu = menu.GetSubMenu(3);
}
ASSERT(pop_up_menu != NULL);
BOOL bPopRet = pop_up_menu->TrackPopupMenu(TPM_LEFTALIGN | TPM_LEFTBUTTON
, point.x, point.y, AfxGetMainWnd());
if (FALSE == bPopRet)
{
TRACE(_T("ERROR: can not pop-up a menu, CWizardWnd::OnRClickInvVwTree()"));
return;
}
}
VOID LSTViewFolder::Clear()
{
GetListCtrl().DeleteAllItems();
}
CString LSTViewFolder::GetSelectPath()
{
CListCtrl& ListCtrl = GetListCtrl();
int sel_count = ListCtrl.GetSelectedCount();
if(sel_count!=1)
return CString("");
int nItem = -1;
POSITION pos = ListCtrl.GetFirstSelectedItemPosition();
nItem = ListCtrl.GetNextSelectedItem(pos);
return ListCtrl.GetItemText(nItem, 3);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -