⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 haffmanview.cpp

📁 这个也是哈夫曼编码译码      这个是基于文档类的
💻 CPP
字号:
// HaffmanView.cpp : implementation of the CHaffmanView class
//
#include "Globe.h"
#include "stdafx.h"
#include "Haffman.h"
#include "MainFrm.h"
#include "HaffmanDoc.h"
#include "HaffmanView.h"
#include "resource.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CHaffmanView

IMPLEMENT_DYNCREATE(CHaffmanView, CEditView)

BEGIN_MESSAGE_MAP(CHaffmanView, CEditView)
	ON_WM_CONTEXTMENU()
	//{{AFX_MSG_MAP(CHaffmanView)
	ON_COMMAND(IDM_SHOW_CODE, OnShowCode)
	ON_MESSAGE(WM_SHOW, OnShow)

	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CHaffmanView construction/destruction

CHaffmanView::CHaffmanView()
{
	// TODO: add construction code here
	m_pIn = NULL;

}

CHaffmanView::~CHaffmanView()
{

}

BOOL CHaffmanView::PreCreateWindow(CREATESTRUCT& cs)
{
	// TODO: Modify the Window class or styles here by modifying
	//  the CREATESTRUCT cs

	BOOL bPreCreated = CEditView::PreCreateWindow(cs);
	cs.style &= ~(ES_AUTOHSCROLL|WS_HSCROLL);	// Enable word-wrapping

	return bPreCreated;
}

/////////////////////////////////////////////////////////////////////////////
// CHaffmanView drawing

void CHaffmanView::OnDraw(CDC* pDC)
{
	CHaffmanDoc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);
	// TODO: add draw code for native data here
}

/////////////////////////////////////////////////////////////////////////////
// CHaffmanView diagnostics

#ifdef _DEBUG
void CHaffmanView::AssertValid() const
{
	CEditView::AssertValid();
}

void CHaffmanView::Dump(CDumpContext& dc) const
{
	CEditView::Dump(dc);
}

CHaffmanDoc* CHaffmanView::GetDocument() // non-debug version is inline
{
	ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CHaffmanDoc)));
	return (CHaffmanDoc*)m_pDocument;
}
#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// CHaffmanView message handlers

void CHaffmanView::OnContextMenu(CWnd*, CPoint point)
{
	// CG: This block was added by the Pop-up Menu component	{		if (point.x == -1 && point.y == -1){			//keystroke invocation			CRect rect;			GetClientRect(rect);			ClientToScreen(rect);			point = rect.TopLeft();			point.Offset(5, 5);		}		CMenu menu;		VERIFY(menu.LoadMenu(CG_IDR_POPUP_HAFFMAN_VIEW));		CMenu* pPopup = menu.GetSubMenu(0);		ASSERT(pPopup != NULL);		CWnd* pWndPopupOwner = this;		while (pWndPopupOwner->GetStyle() & WS_CHILD)			pWndPopupOwner = pWndPopupOwner->GetParent();		pPopup->TrackPopupMenu(TPM_LEFTALIGN | TPM_RIGHTBUTTON, point.x, point.y,			pWndPopupOwner);	}
}


void CHaffmanView::OnInitialUpdate() 
{
	CEditView::OnInitialUpdate();
	// TODO: Add your specialized code here and/or call the base class 

    m_l=  new Clist(this);
	if(m_l != NULL)
	{
		m_l->Create(IDD_DIALOG, this);
		m_l->m_List.InsertColumn(1,"   Letter",LVCFMT_CENTER,70,0);
		m_l->m_List.InsertColumn(2,"   Weight",LVCFMT_CENTER,74,1);
		m_l->m_List.InsertColumn(3,"         Code",LVCFMT_LEFT,110,2);
	}
	else 
		MessageBox(" 创建失败!","错误",0);

}



void CHaffmanView::OnShowCode() 
{
	// TODO: Add your command handler code here
	LVITEM it;
	CHaffmanDoc* pDoc = GetDocument();
	CString ss1 = "asdfasd", ss2 = "asdf", ss3 = "rtqwe";
	m_l->m_List.DeleteAllItems();
	if(m_l != NULL)
	{
		
		for(int i = 1; i<= pDoc->m; i++)
		{
			ss3.Format("%c",(char)pDoc->HT[i].id);
			ss1.Format("%d",pDoc->HT[i].weight);
			it.mask = LVIF_TEXT;
			it.iItem =i;
			it.iSubItem = 0;
			it.pszText = ss3.GetBuffer(0); 
			it.iImage = 0;
			it.lParam = 0;
			int pos= m_l->m_List.InsertItem(&it);
			it.iItem = pos;
			it.iSubItem = 1;
			it.pszText = ss1.GetBuffer(0);  
			it.lParam = 0;
			m_l->m_List.SetItem(&it);
			it.iItem = pos;
			it.iSubItem = 2;
			it.pszText = pDoc->ss[i].GetBuffer(0);
			it.lParam = 0;
			m_l->m_List.SetItem(&it);
		}
		if(m_l->IsWindowVisible())
			m_l->ShowWindow(SW_HIDE);
		else
			m_l->ShowWindow(SW_SHOW);
		m_l->CenterWindow();
		
	}
}

void CHaffmanView::OnUpdateShowCode(CCmdUI* pCmdUI) 
{
	// TODO: Add your command update UI handler code here
	pCmdUI->SetCheck(m_l !=NULL && m_l->IsWindowVisible());
}


void CHaffmanView::OnShow()
{
	LVITEM it;
	CHaffmanDoc* pDoc = GetDocument();
	CString ss1 = "asdfasd", ss2 = "asdf", ss3 = "rtqwe";
	m_l->m_List.DeleteAllItems();
	if(m_l != NULL)
	{
		UpdateData(TRUE);
		for(int i = 1; i<= pDoc->m; i++)
		{
			ss3.Format("%c",(char)pDoc->HT[i].id);
			ss1.Format("%d",pDoc->HT[i].weight);
			it.mask = LVIF_TEXT;
			it.iItem =i;
			it.iSubItem = 0;
			it.pszText = ss3.GetBuffer(0); 
			it.iImage = 0;
			it.lParam = 0;
			int pos= m_l->m_List.InsertItem(&it);
			it.iItem = pos;
			it.iSubItem = 1;
			it.pszText = ss1.GetBuffer(0);  
			it.lParam = 0;
			m_l->m_List.SetItem(&it);
			it.iItem = pos;
			it.iSubItem = 2;
			it.pszText = pDoc->ss[i].GetBuffer(0);
			it.lParam = 0;
			m_l->m_List.SetItem(&it);
		}
		UpdateData(FALSE);
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -