这些代码都是什么意思?

机器学习之禅 2009-07-05 09:03:24
// huffmanDlg.cpp : implementation file
//

#include "stdafx.h"
#include "huffman.h"
#include "huffmanDlg.h"
#include "compression.h"
#include <string>
using namespace std;

#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()

/////////////////////////////////////////////////////////////////////////////
// CHuffmanDlg dialog

CHuffmanDlg::CHuffmanDlg(CWnd* pParent /*=NULL*/)
: CDialog(CHuffmanDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CHuffmanDlg)
// 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 CHuffmanDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CHuffmanDlg)
// NOTE: the ClassWizard will add DDX and DDV calls here
//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CHuffmanDlg, CDialog)
//{{AFX_MSG_MAP(CHuffmanDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_OPENFILE, OnOpenfile)
ON_BN_CLICKED(IDC_SAVEFILE, OnSavefile)
ON_BN_CLICKED(IDC_COMPRESSION, OnCompression)
ON_BN_CLICKED(IDC_DECOMPRESSION, OnDecompression)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CHuffmanDlg message handlers

BOOL CHuffmanDlg::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

return TRUE; // return TRUE unless you set the focus to a control
}

void CHuffmanDlg::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 CHuffmanDlg::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 CHuffmanDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}

void CHuffmanDlg::OnOpenfile()
{
// TODO: Add your control notification handler code here
CFileDialog opDlg(TRUE, NULL, NULL, NULL, _T("所有文件 (*.*)|*.*||"), NULL);
opDlg.DoModal();
SetDlgItemText(IDC_OPENPATH,opDlg.GetPathName( ));
}

void CHuffmanDlg::OnSavefile()
{
// TODO: Add your control notification handler code here
CFileDialog saDlg(TRUE, NULL, NULL, NULL, _T("hfm文件 (*.hfm)|*.hfm|所有文件 (*.*)|*.*||"), NULL);
saDlg.DoModal();
SetDlgItemText(IDC_SAVEPATH,saDlg.GetPathName());
}

void CHuffmanDlg::OnCompression()
{
// TODO: Add your control notification handler code here
CString strTmp;
extern int codelen;
extern int textlen;
std::string fileadd;
compression huffman;
GetDlgItemText(IDC_OPENPATH,strTmp);
fileadd=strTmp;
if(huffman.Compression(fileadd))
{
float f=(float)codelen/(float)textlen;
strTmp.Format("%.2f%%",f*100);
SetDlgItemText(IDC_RATIO,strTmp);
MessageBox("压缩完成","提示",MB_OK|MB_ICONASTERISK);
}
}

void CHuffmanDlg::OnDecompression()
{
// TODO: Add your control notification handler code here
CString str;
std::string fileadd;
compression huffman;
GetDlgItemText(IDC_SAVEPATH,str);
fileadd=str;
if(huffman.Decompression(fileadd))
MessageBox("解压完成","提示",MB_OK|MB_ICONASTERISK);
}
...全文
92 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
Sandrer 2009-07-06
  • 打赏
  • 举报
回复
huffman 这个究竟叫“霍夫曼”,还是叫“哈弗曼”???

我记得我读书的时候,教科书上面写的是 霍夫曼....................
Sandrer 2009-07-06
  • 打赏
  • 举报
回复
我就奇怪,楼主在下载这些代码的时候,难道提供这些代码的地方就没有任何的说明吗?

还是说楼主的代码是从哪里偷来的?
blueink_200451 2009-07-05
  • 打赏
  • 举报
回复
哈弗曼算法的压缩和解压缩
xshydy 2009-07-05
  • 打赏
  • 举报
回复
哈弗曼算法的压缩和解压缩
Lin 2009-07-05
  • 打赏
  • 举报
回复
太长的代码俺一般不看
用户 昵称 2009-07-05
  • 打赏
  • 举报
回复
好像就是一个调用程序。
supconsupcon 2009-07-05
  • 打赏
  • 举报
回复
大概意思是一个哈弗曼压缩类的测试Demo
WaistCoat17 2009-07-05
  • 打赏
  • 举报
回复
...

16,472

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC相关问题讨论
社区管理员
  • 基础类社区
  • Web++
  • encoderlee
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……

试试用AI创作助手写篇文章吧