📄 mainfrm.cpp
字号:
void CMainFrame::OnUpdateViewShowdirectory(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
pCmdUI->SetCheck(m_bShowDirectory);
}
void CMainFrame::OnUpdateViewFiletree(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
OnUpdateControlBarMenu(pCmdUI);
pCmdUI->Enable(m_bShowDirectory);
}
void CMainFrame::OnViewLargeicons()
{
// TODO: Add your command handler code here
m_ViewStyleID=ID_VIEW_LARGEICONS;
m_ListView.ModifyStyle(LVS_TYPEMASK, LVS_ICON);
}
void CMainFrame::OnViewSmallicons()
{
// TODO: Add your command handler code here
m_ViewStyleID=ID_VIEW_SMALLICONS;
m_ListView.ModifyStyle(LVS_TYPEMASK, LVS_SMALLICON);
}
void CMainFrame::OnViewList()
{
// TODO: Add your command handler code here
m_ViewStyleID=ID_VIEW_LIST;
m_ListView.ModifyStyle(LVS_TYPEMASK, LVS_LIST);
}
void CMainFrame::OnViewDetails()
{
// TODO: Add your command handler code here
m_ViewStyleID=ID_VIEW_DETAILS;
m_ListView.ModifyStyle(LVS_TYPEMASK, LVS_REPORT);
}
void CMainFrame::OnUpdateViewLargeicons(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
pCmdUI->SetRadio(m_ViewStyleID==ID_VIEW_LARGEICONS);
pCmdUI->Enable(m_bShowDirectory);
}
void CMainFrame::OnUpdateViewDetails(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
pCmdUI->SetRadio(m_ViewStyleID==ID_VIEW_DETAILS);
}
void CMainFrame::OnUpdateViewList(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
pCmdUI->SetRadio(m_ViewStyleID==ID_VIEW_LIST);
pCmdUI->Enable(m_bShowDirectory);
}
void CMainFrame::OnUpdateViewSmallicons(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
pCmdUI->SetRadio(m_ViewStyleID==ID_VIEW_SMALLICONS);
pCmdUI->Enable(m_bShowDirectory);
}
BOOL CMainFrame::OnNotify(WPARAM wParam, LPARAM lParam, LRESULT* pResult)
{
// TODO: Add your specialized code here and/or call the base class
NMHDR *pnmh=(NMHDR*)lParam;
if (pnmh->hwndFrom==m_TreeView.m_TreeCtrl.m_hWnd)
{
switch(pnmh->code)
{
case TVN_SELCHANGED:
m_szCurFolder=m_TreeView.GetCurFolder();
m_ListView.ReloadList(m_szCurFolder);
break;
}
}
else if (pnmh->hwndFrom==m_ListView.GetListCtrl().m_hWnd)
{
CListCtrl *pList=&m_ListView.GetListCtrl();
switch(pnmh->code)
{
case NM_DBLCLK:
OnCmdOpen();
break;
case NM_RCLICK:
OnPopupMenu();
break;
}
}
return CCJFrameWnd::OnNotify(wParam, lParam, pResult);
}
void CMainFrame::OnViewGoup()
{
// TODO: Add your command handler code here
if (!m_szCurFolder.IsEmpty())
{
int n=m_szCurFolder.GetLength();
m_szCurFolder.Delete(n-1);
int i=m_szCurFolder.ReverseFind('\\');
if (i>0) m_szCurFolder.Delete(i+1,n-i-2);
else m_szCurFolder.Empty();
m_TreeView.SetCurFolder(m_szCurFolder);
}
}
void CMainFrame::OnCmdInfo()
{
// TODO: Add your command handler code here
CListCtrl *pList=&m_ListView.GetListCtrl();
POSITION pos=pList->GetFirstSelectedItemPosition();
if (pos!=NULL)
{
int nItem=pList->GetNextSelectedItem(pos);
LPARAM lParam=pList->GetItemData(nItem);
if (lParam)
{
CFileInfoDlg dlgFileInfo;
CCompressDoc *pDoc=THEAPP->m_pDoc;
FILEINDEXLISTNODE *p=(FILEINDEXLISTNODE*)lParam;
int iIcon=GetFileIcon(p->szFileName,0,0);
dlgFileInfo.m_hIcon=m_LargeIcons.ExtractIcon(iIcon);
dlgFileInfo.m_szFilename=GetFileName(p->szFileName);
dlgFileInfo.m_szFullname=p->szFileName;
dlgFileInfo.m_szTypename=GetFileTypeName(p->szFileName,0);
dlgFileInfo.m_szSize.Format("%d 字节",p->dwFileSize);
dlgFileInfo.m_szPackedsize.Format("%d 字节",p->dwPackedSize);
dlgFileInfo.m_szRatio.Format("%d%%",p->dwPackedSize*100/p->dwFileSize);
dlgFileInfo.m_szCRC.Format("%x",p->dwCRC32);
dlgFileInfo.m_szComment=pDoc->GetComment(p->nIndex);
if (dlgFileInfo.DoModal()==IDOK)
pDoc->SetComment(p->nIndex,dlgFileInfo.m_szComment);
}
}
}
void CMainFrame::OnUpdateCmdDelete(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
CCompressDoc *pDoc=THEAPP->m_pDoc;
pCmdUI->Enable(!pDoc->IsClosed() && pDoc->m_FnInfo.lpfnDeleteFiles);
}
void CMainFrame::OnUpdateCmdInfo(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
pCmdUI->Enable(!THEAPP->m_pDoc->IsClosed());
}
void CMainFrame::OnUpdateCmdAdd(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
CCompressDoc *pDoc=THEAPP->m_pDoc;
pCmdUI->Enable(!pDoc->IsClosed() && pDoc->m_FnInfo.lpfnAddNewFile);
}
void CMainFrame::OnUpdateCmdExtract(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
CCompressDoc *pDoc=THEAPP->m_pDoc;
pCmdUI->Enable(!pDoc->IsClosed() && pDoc->m_FnInfo.lpfnExtractFile);
}
void CMainFrame::OnUpdateCmdOpen(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
CCompressDoc *pDoc=THEAPP->m_pDoc;
pCmdUI->Enable(!pDoc->IsClosed() && pDoc->m_FnInfo.lpfnExtractFile);
}
void CMainFrame::OnUpdateCmdPassword(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
CCompressDoc *pDoc=THEAPP->m_pDoc;
pCmdUI->Enable(!pDoc->IsClosed() && pDoc->m_FnInfo.lpfnSetPassword);
}
void CMainFrame::OnCmdExtract()
{
// TODO: Add your command handler code here
CExtractDlg ExtractDlg;
ExtractDlg.m_bNoPath=FALSE;
ExtractDlg.m_FileOption=0;
if (ExtractDlg.DoModal()==IDOK)
{
CCompressDoc *pDoc=THEAPP->m_pDoc;
CWordArray files;
CStringArray folders;
if (ExtractDlg.m_FileOption==1)
{
folders.Add("");
pDoc->ExtractFolders(folders,ExtractDlg.m_DestPath);
}
else
{
CListCtrl *pList=&m_ListView.GetListCtrl();
FILEINDEXLISTNODE *p;
POSITION pos=pList->GetFirstSelectedItemPosition();
while (pos)
{
int nItem=pList->GetNextSelectedItem(pos);
if (p=(FILEINDEXLISTNODE*)pList->GetItemData(nItem))
files.Add(p->nIndex);
else
folders.Add(m_szCurFolder+pList->GetItemText(nItem,0)+'\\');
}
pDoc->ExtractFiles(files,ExtractDlg.m_DestPath);
pDoc->ExtractFolders(folders,ExtractDlg.m_DestPath);
}
if (ExtractDlg.m_bOpenFolder)
ShellExecute(NULL,"open",ExtractDlg.m_DestPath,NULL,NULL,SW_SHOW);
}
}
void CMainFrame::OnCmdDelete()
{
// TODO: Add your command handler code here
CCompressDoc *pDoc=THEAPP->m_pDoc;
CWordArray files;
CStringArray folders;
CListCtrl *pList=&m_ListView.GetListCtrl();
FILEINDEXLISTNODE *p;
int nItem;CString Info;
POSITION pos=pList->GetFirstSelectedItemPosition();
if (pos)
{
while (pos)
{
nItem=pList->GetNextSelectedItem(pos);
if (p=(FILEINDEXLISTNODE*)pList->GetItemData(nItem))
files.Add(p->nIndex);
else
folders.Add(m_szCurFolder+pList->GetItemText(nItem,0)+'\\');
}
Info.Format(IDS_DELETEFILE_INFO,files.GetSize(),folders.GetSize());
if (MessageBox(Info,NULL,MB_YESNO|MB_ICONWARNING)==IDYES)
{
pDoc->DeleteFiles(files);
pDoc->DeleteFolders(folders);
if (m_bShowDirectory)
{
m_TreeView.ReloadTree();
m_TreeView.SetCurFolder(m_szCurFolder);
}
else
m_ListView.ReloadList(NULL);
}
}
}
void CMainFrame::OnCmdOpen()
{
// TODO: Add your command handler code here
CListCtrl *pList=&m_ListView.GetListCtrl();
POSITION pos=pList->GetFirstSelectedItemPosition();
if (pos)
{
int nItem=pList->GetNextSelectedItem(pos);
FILEINDEXLISTNODE *p=(FILEINDEXLISTNODE*)pList->GetItemData(nItem);
CCompressDoc *pDoc=THEAPP->m_pDoc;
CString fname=THEAPP->m_UserData.m_szTempPath;
if (!p)
{
m_szCurFolder+=pList->GetItemText(nItem,0)+'\\';
m_TreeView.SetCurFolder(m_szCurFolder);
}
else if (!p->bIsDirectory)
{
CWordArray ar;
ar.Add(p->nIndex);
fname+="~Zipall.tmp\\";
pDoc->ExtractFiles(ar,fname);
fname+=p->szFileName;
ShellExecute(NULL,"open",fname,NULL,NULL,SW_SHOW);
}
}
}
void CMainFrame::OnCmdAdd()
{
// TODO: Add your command handler code here
CAddFileDlg AddDlg;
CCompressDoc *pDoc=THEAPP->m_pDoc;
if (AddDlg.DoModal()==IDOK)
{
int mode=AddDlg.m_nCompressPath;
int iLevel=AddDlg.m_iCompressLevel;
pDoc->AddFiles(mode,AddDlg.m_Files,m_szCurFolder,iLevel);
pDoc->AddFolders(mode,AddDlg.m_Folders,m_szCurFolder,iLevel);
m_TreeView.ReloadTree();
m_TreeView.SetCurFolder(m_szCurFolder);
}
}
void CMainFrame::Refrash()
{
m_TreeView.ReloadTree();
if (m_bShowDirectory)
m_TreeView.SetCurFolder(m_szCurFolder);
else
m_ListView.ReloadList(NULL);
}
void CMainFrame::OnOptionSet()
{
// TODO: Add your command handler code here
}
void CMainFrame::OnActiveListview()
{
// TODO: Add your command handler code here
m_ListView.SetFocus();
}
void CMainFrame::OnChangeActive()
{
// TODO: Add your command handler code here
if (m_TreeView.IsWindowVisible() &&
m_ListView.m_hWnd==GetFocus()->m_hWnd)
m_TreeView.m_TreeCtrl.SetFocus();
else
m_ListView.SetFocus();
}
void CMainFrame::OnPopupMenu()
{
// TODO: Add your command handler code here
CMenu menu,*pPopup;
POINT pt;
menu.LoadMenu(IDR_POPUP_MENU);
pPopup=menu.GetSubMenu(0);
GetCursorPos(&pt);
pPopup->TrackPopupMenu(TPM_RIGHTBUTTON,pt.x,pt.y,this);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -