📄 unzipdlg.cpp
字号:
// UnzipDlg.cpp : implementation file
//
#include "stdafx.h"
#include "Unzipapp.h"
#include "UnzipDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CUnzipDlg dialog
CUnzipDlg::CUnzipDlg(CWnd* pParent /*=NULL*/)
: CDialog(CUnzipDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CUnzipDlg)
m_sZipPath = _T("");
m_nFileCount = 0;
m_nFolderCount = 0;
m_nTotalCompSize = 0;
m_nTotalUncompSize = 0;
m_sFileExt = _T("");
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CUnzipDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CUnzipDlg)
DDX_Control(pDX, IDC_DETAILS, m_lcDetails);
DDX_Text(pDX, IDC_ZIPFILE, m_sZipPath);
DDX_Text(pDX, IDC_FILECOUNT, m_nFileCount);
DDX_Text(pDX, IDC_FOLDERCOUNT, m_nFolderCount);
DDX_Text(pDX, IDC_TOTALCOMPSIZE, m_nTotalCompSize);
DDX_Text(pDX, IDC_TOTALUNCOMPSIZE, m_nTotalUncompSize);
DDX_Text(pDX, IDC_FILEEXT, m_sFileExt);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CUnzipDlg, CDialog)
//{{AFX_MSG_MAP(CUnzipDlg)
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_BROWSE, OnBrowse)
ON_BN_CLICKED(IDC_UNZIP, OnUnzip)
ON_BN_CLICKED(IDC_UPDATEDETAILS, OnUpdatedetails)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CUnzipDlg message handlers
BOOL CUnzipDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// Set the icon for this dialog. The framework does this automatically
// when the application's main window is not a dialog
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon
// setup the details columns
m_lcDetails.InsertColumn(0, "Filename", LVCFMT_LEFT, 200);
m_lcDetails.InsertColumn(1, "Type", LVCFMT_LEFT, 80);
m_lcDetails.InsertColumn(2, "Compressed Size", LVCFMT_LEFT, 80);
m_lcDetails.InsertColumn(3, "Uncompressed Size", LVCFMT_LEFT, 80);
m_lcDetails.InsertColumn(4, "CRC", LVCFMT_LEFT, 80);
return TRUE; // return TRUE unless you set the focus to a control
}
// If you add a minimize button to your dialog, you will need the code below
// to draw the icon. For MFC applications using the document/view model,
// this is automatically done for you by the framework.
void CUnzipDlg::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this); // device context for painting
SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
// Center icon in client rectangle
int cxIcon = GetSystemMetrics(SM_CXICON);
int cyIcon = GetSystemMetrics(SM_CYICON);
CRect rect;
GetClientRect(&rect);
int x = (rect.Width() - cxIcon + 1) / 2;
int y = (rect.Height() - cyIcon + 1) / 2;
// Draw the icon
dc.DrawIcon(x, y, m_hIcon);
}
else
{
CDialog::OnPaint();
}
}
// The system calls this to obtain the cursor to display while the user drags
// the minimized window.
HCURSOR CUnzipDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CUnzipDlg::OnBrowse()
{
UpdateData();
CFileDialog dialog(TRUE, "zip", m_sZipPath, 0, "Zip Files (*.zip)|*.zip||", this);
if (dialog.DoModal() == IDOK)
{
if (!m_uz.OpenZip(dialog.GetPathName()))
{
AfxMessageBox("Not a valid zip file");
return;
}
m_sZipPath = dialog.GetPathName();
UpdateData(FALSE);
}
ShowDetails();
}
void CUnzipDlg::OnUnzip()
{
DWORD dwTick = GetTickCount();
if (!m_uz.Unzip())
AfxMessageBox("Unable to unzip file");
else
TRACE ("Unzip took %.02f s for %d files", (GetTickCount() - dwTick) / 1000.0f, m_nFileCount);
}
void CUnzipDlg::ShowDetails()
{
UpdateData();
m_lcDetails.DeleteAllItems();
m_lcDetails.SetItemCount(m_uz.GetFileCount());
m_lcDetails.UpdateWindow();
m_nTotalCompSize = 0;
m_nTotalUncompSize = 0;
m_nFileCount = 0;
m_nFolderCount = 0;
if (m_uz.GotoFirstFile(m_sFileExt))
{
do
{
UZ_FileInfo info;
m_uz.GetFileInfo(info);
CString sText(info.szFileName);
sText.MakeLower();
int nIndex = m_lcDetails.InsertItem(m_lcDetails.GetItemCount(), sText);
m_lcDetails.SetItemText(nIndex, 1, info.bFolder ? "Folder" : "File");
if (!info.bFolder)
{
sText.Format("%d", info.dwCompressedSize);
m_lcDetails.SetItemText(nIndex, 2, sText);
sText.Format("%d", info.dwUncompressedSize);
m_lcDetails.SetItemText(nIndex, 3, sText);
sText.Format("%08x", info.dwCRC);
m_lcDetails.SetItemText(nIndex, 4, sText);
m_nFileCount++;
}
else
m_nFolderCount++;
m_lcDetails.UpdateWindow();
m_nTotalCompSize += info.dwCompressedSize;
m_nTotalUncompSize += info.dwUncompressedSize;
UpdateData(FALSE);
UpdateWindow();
}
while (m_uz.GotoNextFile(m_sFileExt));
}
}
void CUnzipDlg::OnUpdatedetails()
{
UpdateData();
ShowDetails();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -