📄 ltyzipdlg.cpp
字号:
// ltyzipDlg.cpp : implementation file
//
#include "stdafx.h"
#include "ltyzip.h"
#include "ltyzipDlg.h"
#include "haffman.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
// CAboutDlg dialog used for App About
class CAboutDlg : public CDialog
{
public:
CAboutDlg();
// Dialog Data
enum { IDD = IDD_ABOUTBOX };
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
// Implementation
protected:
DECLARE_MESSAGE_MAP()
};
CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
}
void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
}
BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
END_MESSAGE_MAP()
// CltyzipDlg dialog
CltyzipDlg::CltyzipDlg(CWnd* pParent /*=NULL*/)
: CDialog(CltyzipDlg::IDD, pParent)
, m_yasuodizhi(_T(""))
, m_jieyadizhi(_T(""))
, m_message(_T("准备就绪"))
, m_compress(_T(""))
{
m_nMax = 0;
m_nStep = 0 ;
m_iFileFlag = 0;
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CltyzipDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
DDX_Control(pDX, IDC_PROGRESS1, m_progressctrl);
DDX_Text(pDX, IDC_EDIT1, m_yasuodizhi);
DDX_Text(pDX, IDC_EDIT2, m_jieyadizhi);
DDX_Text(pDX, IDC_MESSAGE, m_message);
DDX_Text(pDX, IDC_COMPRESS, m_compress);
DDX_Control(pDX, IDC_PROGRESS2, m_ProgressCtrlj);
}
BEGIN_MESSAGE_MAP(CltyzipDlg, CDialog)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
//}}AFX_MSG_MAP
ON_BN_CLICKED(IDC_BUTTON1, &CltyzipDlg::OnBnClickedOpen)
ON_BN_CLICKED(IDC_BUTTON2, &CltyzipDlg::OnBnClickedOpenHaf)
ON_BN_CLICKED(IDC_BUTTON3, &CltyzipDlg::OnBnClickedYaSuo)
ON_BN_CLICKED(IDC_BUTTON4, &CltyzipDlg::OnBnClickedJieYa)
END_MESSAGE_MAP()
// CltyzipDlg message handlers
BOOL CltyzipDlg::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
//CProgressCtrl *pProgCtrl=(CProgressCtrl*)GetDlgItem(IDC_PROGRESS1);
//pProgCtrl->SetRange(0,200);//设置进度条范围
// //......//其它代码
//m_nMax=200;
//m_nStep=10;
//SetTimer(1,1000,NULL);//设置进度条更新时钟
return TRUE; // return TRUE unless you set the focus to a control
}
void CltyzipDlg::OnTimer(UINT_PTR nIDEvent)
{
//TODO:Add your message handler?
//CProgressCtrl *pProgCtrl=(CProgressCtrl*)GetDlgItem(IDC_PROGRESS1);
//int nPrePos=pProgCtrl->StepIt();//取得更新前位置
//char test[10];
//int nPercent=(int)(((nPrePos - m_nStep)/m_nMax*100 - 0.5));
//wsprintf(test,?%d%%?,nPercent);
//GetDlgItem(IDC_PERCENT)->SetWindowText(text);
//Cdialog::OnTimer(nIDEvent);
}
void CltyzipDlg::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 CltyzipDlg::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this); // device context for painting
SendMessage(WM_ICONERASEBKGND, reinterpret_cast<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 function to obtain the cursor to display while the user drags
// the minimized window.
HCURSOR CltyzipDlg::OnQueryDragIcon()
{
return static_cast<HCURSOR>(m_hIcon);
}
void CltyzipDlg::OnBnClickedOpen()
{
// TODO: Add your control notification handler code here
CFileDialog CodeOpen(TRUE);
CodeOpen.m_ofn.lpstrTitle = _T("待压缩文件地址");
CodeOpen.m_ofn.lpstrFilter = _T("All Files(*.*)\0*.*\0\0");
CFileDialog CodeSave(FALSE);
CodeSave.m_ofn.lpstrTitle = _T("压缩文件另存为");
CodeSave.m_ofn.lpstrDefExt = _T("haf");
if(IDOK == CodeOpen.DoModal())
{
m_yasuodizhi = CodeOpen.GetPathName();
UpdateData(FALSE);
m_iFileFlag = 0;
if(IDOK == CodeSave.DoModal())
{
YaSuoSaveAddr = CodeSave.GetPathName();
m_iFileFlag = 1;
}
}
}
void CltyzipDlg::OnBnClickedOpenHaf()
{
// TODO: Add your control notification handler code here
CFileDialog DecodeOpen(TRUE);
DecodeOpen.m_ofn.lpstrTitle = _T("待解压文件");
DecodeOpen.m_ofn.lpstrFilter = _T("haf Files(*.haf)\0*.haf\0\0");
CFileDialog DecodeSave(FALSE);
DecodeSave.m_ofn.lpstrTitle = _T("解压文件另存为");
DecodeSave.m_ofn.lpstrFilter = _T("All Files(*.*)\0*.*\0\0");
if (IDOK == DecodeOpen.DoModal())
{
m_jieyadizhi = DecodeOpen.GetPathName();
UpdateData(FALSE);
m_iFileFlag = 10;
if (IDOK == DecodeSave.DoModal())
{
JieYaSaveAddr = DecodeSave.GetPathName();
m_iFileFlag = 11;
}
}
}
void CltyzipDlg::OnBnClickedYaSuo()// 压缩函数
{
// TODO: Add your control notification handler code here
float Compre = 0;
if (0 == m_iFileFlag)
{
MessageBox(_T("文件压缩时地址操作错误!"),_T("错误"),MB_OK | MB_ICONERROR);
}
else if(2 == m_iFileFlag)
{
MessageBox(_T("文件已压缩!"),_T("错误"),MB_OK | MB_ICONERROR);
}
else if(1 == m_iFileFlag)
{
m_message = "正在压缩文件,请稍候…";
UpdateData(FALSE);
Compre = OpenandCloseFile(m_yasuodizhi,YaSuoSaveAddr);
m_compress.Format(_T("%f"),Compre);
m_compress += "%";
if ("-1.#INF00%" == m_compress)
{
m_compress = "原文件为空,无法计算!";
}
m_message = "文件压缩完毕!";
UpdateData(FALSE);
m_compress = "";
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -