📄 mainfrm.cpp
字号:
// MainFrm.cpp : implementation of the CMainFrame class
//
#include "stdafx.h"
#include "Compress.h"
#include "MainFrm.h"
#include "fileinfodlg.h"
#include "fileinfo.h"
#include "openfiledlg.h"
#include "addfiledlg.h"
#include "extractdlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CMainFrame
IMPLEMENT_DYNAMIC(CMainFrame, CCJFrameWnd)
BEGIN_MESSAGE_MAP(CMainFrame, CCJFrameWnd)
//{{AFX_MSG_MAP(CMainFrame)
ON_WM_CREATE()
ON_WM_SETFOCUS()
ON_COMMAND(ID_FILE_NEW, OnFileNew)
ON_COMMAND(ID_FILE_OPEN, OnFileOpen)
ON_WM_CLOSE()
ON_COMMAND(ID_FILE_CLOSE, OnFileClose)
ON_UPDATE_COMMAND_UI(ID_FILE_CLOSE, OnUpdateFileClose)
ON_COMMAND(ID_VIEW_SHOWDIRECTORY, OnViewShowdirectory)
ON_UPDATE_COMMAND_UI(ID_VIEW_SHOWDIRECTORY, OnUpdateViewShowdirectory)
ON_UPDATE_COMMAND_UI(ID_VIEW_FILETREE, OnUpdateViewFiletree)
ON_COMMAND(ID_VIEW_LARGEICONS, OnViewLargeicons)
ON_COMMAND(ID_VIEW_SMALLICONS, OnViewSmallicons)
ON_COMMAND(ID_VIEW_LIST, OnViewList)
ON_COMMAND(ID_VIEW_DETAILS, OnViewDetails)
ON_UPDATE_COMMAND_UI(ID_VIEW_LARGEICONS, OnUpdateViewLargeicons)
ON_UPDATE_COMMAND_UI(ID_VIEW_DETAILS, OnUpdateViewDetails)
ON_UPDATE_COMMAND_UI(ID_VIEW_LIST, OnUpdateViewList)
ON_UPDATE_COMMAND_UI(ID_VIEW_SMALLICONS, OnUpdateViewSmallicons)
ON_COMMAND(ID_VIEW_GOUP, OnViewGoup)
ON_COMMAND(ID_CMD_INFO, OnCmdInfo)
ON_COMMAND(ID_CMD_DELETE, OnCmdDelete)
ON_UPDATE_COMMAND_UI(ID_CMD_DELETE, OnUpdateCmdDelete)
ON_UPDATE_COMMAND_UI(ID_CMD_INFO, OnUpdateCmdInfo)
ON_UPDATE_COMMAND_UI(ID_CMD_ADD, OnUpdateCmdAdd)
ON_UPDATE_COMMAND_UI(ID_CMD_EXTRACT, OnUpdateCmdExtract)
ON_UPDATE_COMMAND_UI(ID_CMD_OPEN, OnUpdateCmdOpen)
ON_UPDATE_COMMAND_UI(ID_CMD_PASSWORD, OnUpdateCmdPassword)
ON_COMMAND(ID_CMD_EXTRACT, OnCmdExtract)
ON_COMMAND(ID_CMD_OPEN, OnCmdOpen)
ON_COMMAND(ID_CMD_ADD, OnCmdAdd)
ON_COMMAND(ID_OPTION_SET, OnOptionSet)
ON_COMMAND(ID_ACTIVE_LISTVIEW, OnActiveListview)
ON_COMMAND(ID_CHANGE_ACTIVE, OnChangeActive)
ON_COMMAND(ID_POPUP_MENU, OnPopupMenu)
//}}AFX_MSG_MAP
ON_COMMAND_EX(ID_VIEW_FILETREE, OnBarCheck)
END_MESSAGE_MAP()
static UINT indicators[] =
{
ID_SEPARATOR, // status line indicator
ID_INDICATOR_CAPS,
ID_INDICATOR_NUM,
ID_INDICATOR_SCRL,
};
/////////////////////////////////////////////////////////////////////////////
// CMainFrame construction/destruction
CMainFrame::CMainFrame()
{
// TODO: add member initialization code here
}
CMainFrame::~CMainFrame()
{
}
int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CCJFrameWnd::OnCreate(lpCreateStruct) == -1)
return -1;
// create a view to occupy the client area of the frame
if (!m_ListView.Create(NULL, NULL, AFX_WS_DEFAULT_VIEW,
CRect(0, 0, 0, 0), this, AFX_IDW_PANE_FIRST, NULL))
{
TRACE0("Failed to create view window\n");
return -1;
}
if (!m_wndToolBar.Create(this)||
!m_wndToolBar.LoadToolBar(IDR_MAINFRAME))
{
TRACE0("Failed to create rebar\n");
return -1; // fail to create
}
::SetWindowText(m_wndToolBar.m_hWnd,_T("工具栏"));
m_wndToolBar.SetBarStyle(m_wndToolBar.GetBarStyle() |
CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC);
if (!m_wndStatusBar.Create(this) ||
!m_wndStatusBar.SetIndicators(indicators,
sizeof(indicators)/sizeof(UINT)))
{
TRACE0("Failed to create status bar\n");
return -1; // fail to create
}
if (!m_TreeView.Create(this,ID_VIEW_FILETREE,_T("目录树"),CSize(300,200)))
{
TRACE0("Failed to create tree view\n");
return -1; // fail to create
}
SetInitialSize(125,125,225,225);
m_wndToolBar.EnableDocking(CBRS_ALIGN_ANY);
m_TreeView.EnableDockingOnSizeBar(CBRS_ALIGN_ANY);
EnableDocking(CBRS_ALIGN_ANY);
EnableDockingSizeBar(CBRS_ALIGN_ANY);
DockControlBar(&m_wndToolBar);
DockSizeBar(&m_TreeView);
m_MenuMgr.Install(this);
m_MenuMgr.LoadToolbar(IDR_MAINFRAME);
LoadBarState(REGISTRYKEYNAME);
//set tree and list images
CSHFileInfo sfi;
sfi.GetSystemImageList(&m_SmallIcons,&m_LargeIcons);
::SendMessage(m_TreeView.m_TreeCtrl.m_hWnd, TVM_SETIMAGELIST,
(WPARAM) TVSIL_NORMAL,(LPARAM)m_SmallIcons.m_hImageList);
CListCtrl *pListCtrl=&m_ListView.GetListCtrl();
pListCtrl->SetImageList(&m_SmallIcons, LVSIL_SMALL);
pListCtrl->SetImageList(&m_LargeIcons, LVSIL_NORMAL);
CUserData *pUserData=&(THEAPP->m_UserData);
m_bShowDirectory=pUserData->m_bShowDirectory;
switch (m_ViewStyleID=pUserData->m_ViewStyleID)
{
case ID_VIEW_LARGEICONS: OnViewLargeicons(); break;
case ID_VIEW_SMALLICONS: OnViewSmallicons(); break;
case ID_VIEW_LIST: OnViewList(); break;
default: OnViewDetails();
}
return 0;
}
BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)
{
if( !CCJFrameWnd::PreCreateWindow(cs) )
return FALSE;
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
cs.dwExStyle &= ~WS_EX_CLIENTEDGE;
cs.lpszClass = AfxRegisterWndClass(0);
return TRUE;
}
/////////////////////////////////////////////////////////////////////////////
// CMainFrame diagnostics
#ifdef _DEBUG
void CMainFrame::AssertValid() const
{
CCJFrameWnd::AssertValid();
}
void CMainFrame::Dump(CDumpContext& dc) const
{
CCJFrameWnd::Dump(dc);
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CMainFrame message handlers
void CMainFrame::OnSetFocus(CWnd* pOldWnd)
{
// forward focus to the view window
m_ListView.SetFocus();
}
BOOL CMainFrame::OnCmdMsg(UINT nID, int nCode, void* pExtra, AFX_CMDHANDLERINFO* pHandlerInfo)
{
// let the view have first crack at the command
if (m_ListView.OnCmdMsg(nID, nCode, pExtra, pHandlerInfo))
return TRUE;
// otherwise, do default handling
return CCJFrameWnd::OnCmdMsg(nID, nCode, pExtra, pHandlerInfo);
}
void CMainFrame::OnFileNew()
{
// TODO: Add your command handler code here
CCompressDoc *pDoc=THEAPP->m_pDoc;
CString lpszFilter;
CStringArray libs;
CLibManager *pLibmgr=THEAPP->m_pLibmgr;
int i,n=pLibmgr->GetNoCDL();
LPCODECLIBINFO pLibInfo;
for(i=0;i<n;i++)
{
pLibInfo=pLibmgr->GetCDLInfo(i);
lpszFilter=pLibInfo->szFileType;
lpszFilter+=" (";
lpszFilter+=pLibInfo->szFileFilter;
lpszFilter+=")|";
lpszFilter+=pLibInfo->szFileFilter;
lpszFilter+='|';
libs.Add(pLibInfo->szLibName);
}
lpszFilter+="所有文件 (*.*)|*.*||";
COpenFileDlg dlgNewOpen(FALSE,NULL,NULL,
OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,
lpszFilter);
dlgNewOpen.m_pLibNames=&libs;
dlgNewOpen.m_ofn.lpstrTitle=_T("新建");
if (dlgNewOpen.DoModal()==IDOK)
{
OnFileClose();
if (pDoc->New(dlgNewOpen.GetFileName(),dlgNewOpen.m_LibIndex))
{
m_TreeView.LoadTree();
if (m_bShowDirectory)
m_ListView.LoadList("");
else
m_ListView.LoadList(NULL);
}
else
MessageBox("不能创建该文件!");
}
}
void CMainFrame::OnFileOpen()
{
// TODO: Add your command handler code here
CCompressDoc *pDoc=THEAPP->m_pDoc;
CString lpszFilter;
CStringArray libs;
CLibManager *pLibmgr=THEAPP->m_pLibmgr;
int i,n=pLibmgr->GetNoCDL();
LPCODECLIBINFO pLibInfo;
for(i=0;i<n;i++)
{
pLibInfo=pLibmgr->GetCDLInfo(i);
lpszFilter=pLibInfo->szFileType;
lpszFilter+=" (";
lpszFilter+=pLibInfo->szFileFilter;
lpszFilter+=")|";
lpszFilter+=pLibInfo->szFileFilter;
lpszFilter+='|';
libs.Add(pLibInfo->szLibName);
}
lpszFilter+="所有文件 (*.*)|*.*||";
COpenFileDlg dlgFileOpen(lpszFilter);
dlgFileOpen.m_pLibNames=&libs;
if (dlgFileOpen.DoModal()==IDOK)
{
OnFileClose();
if (pDoc->Open(dlgFileOpen.GetFileName(),dlgFileOpen.m_LibIndex))
{
m_TreeView.LoadTree();
if (m_bShowDirectory)
m_ListView.LoadList("");
else
m_ListView.LoadList(NULL);
}
else
MessageBox("不能打开该文件!");
}
}
void CMainFrame::OnClose()
{
// TODO: Add your message handler code here and/or call default
OnFileClose();
SaveBarState(REGISTRYKEYNAME);
CUserData *pUserData=&(THEAPP->m_UserData);
pUserData->m_bShowDirectory=m_bShowDirectory;
pUserData->m_ViewStyleID=m_ViewStyleID;
WINDOWPLACEMENT pos;
GetWindowPlacement(&pos);
pUserData->m_WndPos.left=pos.rcNormalPosition.left;
pUserData->m_WndPos.right=pos.rcNormalPosition.right;
pUserData->m_WndPos.top=pos.rcNormalPosition.top;
pUserData->m_WndPos.bottom=pos.rcNormalPosition.bottom;
pUserData->m_ShowCmd=pos.showCmd;
CCJFrameWnd::OnClose();
}
void CMainFrame::OnFileClose()
{
// TODO: Add your command handler code here
CCompressDoc *pDoc=THEAPP->m_pDoc;
pDoc->Close();
m_szCurFolder.Empty();
m_TreeView.DeleteTree();
m_ListView.DeleteList();
}
void CMainFrame::OnUpdateFileClose(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
CCompressDoc *pDoc=THEAPP->m_pDoc;
if (pDoc) pCmdUI->Enable(!pDoc->IsClosed());
}
void CMainFrame::OnViewShowdirectory()
{
// TODO: Add your command handler code here
if (m_bShowDirectory)
{
m_bShowDirectory=FALSE;
m_ListView.ReloadList();
ShowControlBar(&m_TreeView,FALSE,FALSE);
OnViewDetails();
m_szCurFolder.Empty();
}
else
{
m_bShowDirectory=TRUE;
m_ListView.ReloadList(m_szCurFolder);
ShowControlBar(&m_TreeView,TRUE,FALSE);
OnViewLargeicons();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -