📄 huffmantestdlg.cpp
字号:
// HuffmanTestDlg.cpp : implementation file
//
#include "stdafx.h"
#include "HuffmanTest.h"
#include "HuffmanTestDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CHuffmanTestDlg dialog
CHuffmanTestDlg::CHuffmanTestDlg(CWnd* pParent /*=NULL*/)
: CDialog(CHuffmanTestDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CHuffmanTestDlg)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
CoderTh=NULL;
CoderLog=NULL;
CoderListener=NULL;
}
void CHuffmanTestDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CHuffmanTestDlg)
DDX_Control(pDX, IDC_LOGBOX, m_LogBox);
DDX_Control(pDX, IDC_ENCPROGRESS, m_OpProgress);
DDX_Control(pDX, IDC_PROGRESSLAB, m_ProgressLab);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CHuffmanTestDlg, CDialog)
//{{AFX_MSG_MAP(CHuffmanTestDlg)
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_CODEINFILEBUTT, OnCodeInFileButt)
ON_BN_CLICKED(IDC_ENCODEBUTT, OnEncodeButt)
ON_BN_CLICKED(IDC_DECODEBUTT, OnDecodeButt)
ON_BN_CLICKED(IDC_ABORTBUTT, OnAbortButt)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CHuffmanTestDlg message handlers
BOOL CHuffmanTestDlg::OnInitDialog()
{
CDialog::OnInitDialog();
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon
// TODO: Add extra initialization here
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 CHuffmanTestDlg::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();
}
}
HCURSOR CHuffmanTestDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
bool CHuffmanTestDlg::ShowOpenDlg(CWnd *OwnerWnd, CString StartDir, CString &RetName)
{
OPENFILENAME OpenData;
char *FileNameBuff=new char[MAX_PATH];
FileNameBuff[0]='\0';
memset(&OpenData,0,sizeof(OPENFILENAME));
OpenData.Flags=OFN_FILEMUSTEXIST | OFN_HIDEREADONLY |
OFN_NOREADONLYRETURN | OFN_PATHMUSTEXIST | OFN_SHAREAWARE;
OpenData.hwndOwner=OwnerWnd->m_hWnd;
OpenData.lpstrFilter="All Files\0*\0\0";
OpenData.lpstrFile=FileNameBuff;
OpenData.nMaxFile=MAX_PATH;
OpenData.lStructSize=sizeof(OPENFILENAME);
OpenData.lpstrInitialDir=StartDir.GetBuffer(0);
GetOpenFileName(&OpenData);
RetName=FileNameBuff;
delete[] FileNameBuff;
return RetName.GetLength() ? true : false;
}
void CHuffmanTestDlg::OnOK()
{
//CDialog::OnOK();
}
void CHuffmanTestDlg::OnCancel()
{
CDialog::OnCancel();
}
void CHuffmanTestDlg::OnCodeInFileButt()
{
CString SelFileName;
if (ShowOpenDlg(this,"",SelFileName))
{
InFileName=SelFileName;
this->GetDlgItem(IDC_CODEINFILELAB)->SetWindowText(SelFileName);
}
}
void CHuffmanTestDlg::OnEncodeButt()
{
if (InFileName.GetLength())
{
delete CoderLog;
delete CoderListener;
CoderLog=new WinLog(&m_LogBox);
CoderListener=new ProgressListener(&m_OpProgress,&m_ProgressLab);
CString OutFileName=InFileName;
OutFileName+=".Huffy";
MyCoder.SetFileNames(InFileName,OutFileName);
MyCoder.SetUIHelpers(CoderListener,CoderLog);
delete CoderTh;
CoderTh=AfxBeginThread(&(MyCoder.ThreadEncoder),&MyCoder,0,0,CREATE_SUSPENDED,NULL);
CoderTh->m_bAutoDelete=false;
CoderTh->ResumeThread();
}
else
MessageBox("Select a file first!",NULL, MB_ICONERROR);
}
void CHuffmanTestDlg::OnDecodeButt()
{
if (InFileName.GetLength())
{
delete CoderLog;
delete CoderListener;
CoderLog=new WinLog(&m_LogBox);
CoderListener=new ProgressListener(&m_OpProgress,&m_ProgressLab);
CString OutFileName=InFileName;
OutFileName+=".Decoded";
MyCoder.SetFileNames(InFileName,OutFileName);
MyCoder.SetUIHelpers(CoderListener,CoderLog);
delete CoderTh;
CoderTh=AfxBeginThread(&(MyCoder.ThreadDecoder),&MyCoder,0,0,CREATE_SUSPENDED,NULL);
CoderTh->m_bAutoDelete=false;
CoderTh->ResumeThread();
}
else
MessageBox("Select a file first!",NULL, MB_ICONERROR);
}
void CHuffmanTestDlg::OnAbortButt()
{
if ((CoderTh) && (CoderTh->ResumeThread()==0))
{
CoderLog->LogText("Sorry, abort is not implemented yet :).");
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -