📄 z_filedlg.cpp
字号:
// z_fileDlg.cpp : implementation file
//
#include "stdafx.h"
#include "z_file.h"
#include "z_fileDlg.h"
#include "czip.h"
#include "bufferpipe.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About
class CAboutDlg : public CDialog
{
public:
CAboutDlg();
// Dialog Data
//{{AFX_DATA(CAboutDlg)
enum { IDD = IDD_ABOUTBOX };
//}}AFX_DATA
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CAboutDlg)
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//}}AFX_VIRTUAL
// Implementation
protected:
//{{AFX_MSG(CAboutDlg)
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
//{{AFX_DATA_INIT(CAboutDlg)
//}}AFX_DATA_INIT
}
void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CAboutDlg)
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
//{{AFX_MSG_MAP(CAboutDlg)
// No message handlers
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CZ_fileDlg dialog
CZ_fileDlg::CZ_fileDlg(CWnd* pParent /*=NULL*/)
: CDialog(CZ_fileDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CZ_fileDlg)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CZ_fileDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CZ_fileDlg)
DDX_Control(pDX, IDC_PROGRESS1, m_Progress);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CZ_fileDlg, CDialog)
//{{AFX_MSG_MAP(CZ_fileDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_BUTTON1, OnButton1)
ON_BN_CLICKED(IDC_BUTTON2, OnButton2)
ON_BN_CLICKED(IDC_BUTTON3, OnButton3)
ON_BN_CLICKED(IDC_BUTTON4, OnButton4)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CZ_fileDlg message handlers
BOOL CZ_fileDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// Add "About..." menu item to system menu.
// IDM_ABOUTBOX must be in the system command range.
ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
ASSERT(IDM_ABOUTBOX < 0xF000);
CMenu* pSysMenu = GetSystemMenu(FALSE);
if (pSysMenu != NULL)
{
CString strAboutMenu;
strAboutMenu.LoadString(IDS_ABOUTBOX);
if (!strAboutMenu.IsEmpty())
{
pSysMenu->AppendMenu(MF_SEPARATOR);
pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
}
}
// 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
// TODO: Add extra initialization here
this->m_Progress.SetRange32(0,100);
return TRUE; // return TRUE unless you set the focus to a control
}
void CZ_fileDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
if ((nID & 0xFFF0) == IDM_ABOUTBOX)
{
CAboutDlg dlgAbout;
dlgAbout.DoModal();
}
else
{
CDialog::OnSysCommand(nID, lParam);
}
}
// 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 CZ_fileDlg::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 CZ_fileDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CZ_fileDlg::OnButton1()
{
// TODO: Add your control notification handler code here
zlib_compress_filter<Z_BEST_COMPRESSION> lzip;
DWORD fsize,rsize;
BYTE buf[8192];
CFile ifile,ofile;
int readcount = 0;
if (ifile.Open("c:\\a.bmp",CFile::modeRead) && ofile.Open("c:\\b.cr", CFile::modeCreate|CFile::modeWrite)) {
fsize = ifile.GetLength();
rsize = 0;
while (rsize < fsize) {
memset(buf, 0 , 8192);
int ret = ifile.Read(buf, 8192);
int zcount;
BYTE* pzip;
zcount = 0;
pzip = NULL;
readcount++;
TRACE("read count is %d\n", readcount);
if (readcount == 54) {
int j = 100;
}
if (ret == 8192) {
pzip = lzip.Process(buf,ret,zcount);
}else {
pzip = lzip.ProcessLast(buf,ret,zcount);
}
if (pzip && zcount > 0) {
ofile.Write(pzip,zcount);
delete [] pzip;
}
rsize += ret;
double pro = (double)rsize * 100 / fsize;
m_Progress.SetPos((int)pro);
}
ifile.Close();
ofile.Close();
}
m_Progress.SetPos(0);
}
void CZ_fileDlg::OnButton2()
{
// TODO: Add your control notification handler code here
zlib_uncompress_filter<1> lunzip;
DWORD fsize,rsize;
BYTE buf[8192];
CFile ifile,ofile;
int readcount = 0;
if (ifile.Open("c:\\b.cr", CFile::modeRead) && ofile.Open("c:\\c.bmp", CFile::modeCreate|CFile::modeWrite)) {
fsize = ifile.GetLength();
rsize = 0;
while (rsize < fsize) {
memset(buf, 0 , 8192);
int ret = ifile.Read(buf, 8192);
int zcount;
BYTE* pzip;
zcount = 0;
pzip = NULL;
readcount++;
TRACE("read count is %d\n", readcount);
//if (ret == 8192) {
pzip = lunzip.Process(buf,ret,zcount);
//}else {
// pzip = lzip.ProcessLast(buf,ret,zcount);
//}
if (pzip && zcount > 0) {
ofile.Write(pzip,zcount);
delete [] pzip;
}
rsize += ret;
double pro = (double)rsize * 100 / fsize;
m_Progress.SetPos((int)pro);
}
ifile.Close();
ofile.Close();
}
m_Progress.SetPos(0);
}
void CZ_fileDlg::OnButton3()
{
// TODO: Add your control notification handler code here
//zlib_compress_filter<Z_BEST_COMPRESSION> lzip;
DWORD fsize,rsize;
BYTE buf[8192];
CFile ifile,ofile;
if (ifile.Open("c:\\a.bmp",CFile::modeRead) && ofile.Open("c:\\d.cr", CFile::modeCreate|CFile::modeWrite)) {
BufferPipe<zlib_compress_filter<Z_BEST_COMPRESSION>, buf_holder<BYTE, 8192>, CFile > lpipe(&ofile);
fsize = ifile.GetLength();
rsize = 0;
while (rsize < fsize) {
memset(buf, 0 , 8192);
int ret = ifile.Read(buf, 8192);
int zcount;
BYTE* pzip;
zcount = 0;
pzip = NULL;
lpipe.Write(buf, ret);
rsize += ret;
double pro = (double)rsize * 100 / fsize;
m_Progress.SetPos((int)pro);
}
lpipe.Close();
ifile.Close();
ofile.Close();
}
m_Progress.SetPos(0);
}
void CZ_fileDlg::OnButton4()
{
// TODO: Add your control notification handler code here
DWORD fsize,rsize;
BYTE buf[8192];
CFile ifile,ofile;
if (ifile.Open("c:\\a.bmp",CFile::modeRead) && ofile.Open("c:\\e.bmp", CFile::modeCreate|CFile::modeWrite)) {
BufferPipe<zlib_uncompress_filter<1>, buf_holder<BYTE, 8192>, CFile > dcpipe(&ofile);
BufferPipe<zlib_compress_filter<Z_BEST_COMPRESSION>, buf_holder<BYTE, 8192>,
BufferPipe<zlib_uncompress_filter<1>, buf_holder<BYTE, 8192>, CFile > > cmpipe(&dcpipe);
fsize = ifile.GetLength();
rsize = 0;
while (rsize < fsize) {
memset(buf, 0 , 8192);
int ret = ifile.Read(buf, 8192);
int zcount;
BYTE* pzip;
zcount = 0;
pzip = NULL;
cmpipe.Write(buf, ret);
rsize += ret;
double pro = (double)rsize * 100 / fsize;
m_Progress.SetPos((int)pro);
}
cmpipe.Close();
dcpipe.Close();
ifile.Close();
ofile.Close();
}
m_Progress.SetPos(0);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -