谁能帮我看下代码?
// GDItestView.cpp : implementation of the CGDItestView class
//#include "stdafx.h"
#include "GDItest.h"
#include "GDItestDoc.h"
#include "GDItestView.h"
#include "InputDlg.h"#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endiftypedef struct{
int weight;
int parent,lchild,rchild;
}HTNode, *HuffmanTree; //动态分配数组存储哈夫曼树
/////////////////////////////////////////////////////////////////////////////
// CGDItestViewIMPLEMENT_DYNCREATE(CGDItestView, CView)BEGIN_MESSAGE_MAP(CGDItestView, CView)
//{{AFX_MSG_MAP(CGDItestView)
ON_COMMAND(IDM_CESHI, OnCeshi)
ON_COMMAND(IDM_SAVE, OnSaveDlg)
ON_BN_CLICKED(IDC_SAVE, OnSave)
//}}AFX_MSG_MAP
// Standard printing commands
ON_COMMAND(ID_FILE_PRINT, CView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_DIRECT, CView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_PREVIEW, CView::OnFilePrintPreview)
END_MESSAGE_MAP()/////////////////////////////////////////////////////////////////////////////
// CGDItestView construction/destructionCGDItestView::CGDItestView()
{
// TODO: add construction code here
m_allnode = 0;
m_leafnum = 0;
i = 0;
GetClientRect(&rect); //获取客户区大小
}CGDItestView::~CGDItestView()
{}BOOL CGDItestView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs return CView::PreCreateWindow(cs);
}/////////////////////////////////////////////////////////////////////////////
// CGDItestView drawingvoid CGDItestView::OnDraw(CDC* pDC)
{
CGDItestDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// TODO: add draw code for native data here
}/////////////////////////////////////////////////////////////////////////////
// CGDItestView printingBOOL CGDItestView::OnPreparePrinting(CPrintInfo* pInfo)
{
// default preparation
return DoPreparePrinting(pInfo);
}void CGDItestView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add extra initialization before printing
}void CGDItestView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add cleanup after printing
}/////////////////////////////////////////////////////////////////////////////
// CGDItestView diagnostics#ifdef _DEBUG
void CGDItestView::AssertValid() const
{
CView::AssertValid();
}void CGDItestView::Dump(CDumpContext& dc) const
{
CView::Dump(dc);
}CGDItestDoc* CGDItestView::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CGDItestDoc)));
return (CGDItestDoc*)m_pDocument;
}
#endif //_DEBUG/////////////////////////////////////////////////////////////////////////////
// CGDItestView message handlersvoid CGDItestView::OnCeshi() //用作测试画笔、画刷等情况,此函数无其他意义
{
// TODO: Add your command handler code here
CClientDC dc(this);
CPen pen(PS_SOLID,5,RGB(255,0,0));
dc.SelectObject(&pen);
CBrush *pBrush=CBrush::FromHandle((HBRUSH)GetStockObject(NULL_BRUSH));
dc.SelectObject(pBrush);
dc.Ellipse(10,20,50,60);
CString str="15";
dc.TextOut(25,30,str);}void CGDItestView::OnSaveDlg()
{
// TODO: Add your command handler code here
CInputDlg *pDlg = new CInputDlg();
pDlg->Create(IDD_SAVE,this);
pDlg->ShowWindow(SW_SHOW);
}void CGDItestView::OnSave()
{
// TODO: Add your control notification handler code here
// static CInputDlg Dlg;
// m_leafnum = Dlg.leafnum;
// m_allnode = 2 * m_leafnum - 1; m_leafnum = this->GetDlgItemInt(IDC_LEAFNUM); //获取叶子数
m_allnode = 2 * m_leafnum - 1; //构成哈夫曼树节点总数
static HuffmanTree HT = (HuffmanTree)malloc((m_allnode + 1) * sizeof(HTNode)); //0号单元未用
// static HTNode *HT = new HTNode[(m_allnode + 1) * sizeof(HTNode)];
//初始化叶子结点
i++;
// HT[i].weight = Dlg.leafdata;
HT[i].weight = this->GetDlgItemInt(IDC_LEAFDATA);
HT[i].lchild = 0;
HT[i].rchild = 0;
HT[i].parent = 0;
//定义画笔、画刷绘图
CClientDC dc(this);
CPen pen(PS_SOLID,5,RGB(255,0,0));
dc.SelectObject(&pen);
CBrush *pBrush=CBrush::FromHandle((HBRUSH)GetStockObject(NULL_BRUSH));
dc.SelectObject(pBrush);
dc.Ellipse(rect.right / m_leafnum * (i - 1),rect.bottom - (rect.bottom / m_leafnum),rect.right / m_leafnum * i,rect.bottom);
CString str;
itoa(HT[i].weight,(char*)&str,10);
dc.TextOut(rect.right / m_leafnum * (i - 1)+(rect.right / m_leafnum) / 2,rect.bottom - (rect.bottom / m_leafnum)+(rect.bottom / m_leafnum) / 2,str); }
// GDItestView.cpp : implementation of the CGDItestView class
//#include "stdafx.h"
#include "GDItest.h"
#include "GDItestDoc.h"
#include "GDItestView.h"
#include "InputDlg.h"#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endiftypedef struct{
int weight;
int parent,lchild,rchild;
}HTNode, *HuffmanTree; //动态分配数组存储哈夫曼树
/////////////////////////////////////////////////////////////////////////////
// CGDItestViewIMPLEMENT_DYNCREATE(CGDItestView, CView)BEGIN_MESSAGE_MAP(CGDItestView, CView)
//{{AFX_MSG_MAP(CGDItestView)
ON_COMMAND(IDM_CESHI, OnCeshi)
ON_COMMAND(IDM_SAVE, OnSaveDlg)
ON_BN_CLICKED(IDC_SAVE, OnSave)
//}}AFX_MSG_MAP
// Standard printing commands
ON_COMMAND(ID_FILE_PRINT, CView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_DIRECT, CView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_PREVIEW, CView::OnFilePrintPreview)
END_MESSAGE_MAP()/////////////////////////////////////////////////////////////////////////////
// CGDItestView construction/destructionCGDItestView::CGDItestView()
{
// TODO: add construction code here
m_allnode = 0;
m_leafnum = 0;
i = 0;
GetClientRect(&rect); //获取客户区大小
}CGDItestView::~CGDItestView()
{}BOOL CGDItestView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs return CView::PreCreateWindow(cs);
}/////////////////////////////////////////////////////////////////////////////
// CGDItestView drawingvoid CGDItestView::OnDraw(CDC* pDC)
{
CGDItestDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// TODO: add draw code for native data here
}/////////////////////////////////////////////////////////////////////////////
// CGDItestView printingBOOL CGDItestView::OnPreparePrinting(CPrintInfo* pInfo)
{
// default preparation
return DoPreparePrinting(pInfo);
}void CGDItestView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add extra initialization before printing
}void CGDItestView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add cleanup after printing
}/////////////////////////////////////////////////////////////////////////////
// CGDItestView diagnostics#ifdef _DEBUG
void CGDItestView::AssertValid() const
{
CView::AssertValid();
}void CGDItestView::Dump(CDumpContext& dc) const
{
CView::Dump(dc);
}CGDItestDoc* CGDItestView::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CGDItestDoc)));
return (CGDItestDoc*)m_pDocument;
}
#endif //_DEBUG/////////////////////////////////////////////////////////////////////////////
// CGDItestView message handlersvoid CGDItestView::OnCeshi() //用作测试画笔、画刷等情况,此函数无其他意义
{
// TODO: Add your command handler code here
CClientDC dc(this);
CPen pen(PS_SOLID,5,RGB(255,0,0));
dc.SelectObject(&pen);
CBrush *pBrush=CBrush::FromHandle((HBRUSH)GetStockObject(NULL_BRUSH));
dc.SelectObject(pBrush);
dc.Ellipse(10,20,50,60);
CString str="15";
dc.TextOut(25,30,str);}void CGDItestView::OnSaveDlg()
{
// TODO: Add your command handler code here
CInputDlg *pDlg = new CInputDlg();
pDlg->Create(IDD_SAVE,this);
pDlg->ShowWindow(SW_SHOW);
}void CGDItestView::OnSave()
{
// TODO: Add your control notification handler code here
// static CInputDlg Dlg;
// m_leafnum = Dlg.leafnum;
// m_allnode = 2 * m_leafnum - 1; m_leafnum = this->GetDlgItemInt(IDC_LEAFNUM); //获取叶子数
m_allnode = 2 * m_leafnum - 1; //构成哈夫曼树节点总数
static HuffmanTree HT = (HuffmanTree)malloc((m_allnode + 1) * sizeof(HTNode)); //0号单元未用
// static HTNode *HT = new HTNode[(m_allnode + 1) * sizeof(HTNode)];
//初始化叶子结点
i++;
// HT[i].weight = Dlg.leafdata;
HT[i].weight = this->GetDlgItemInt(IDC_LEAFDATA);
HT[i].lchild = 0;
HT[i].rchild = 0;
HT[i].parent = 0;
//定义画笔、画刷绘图
CClientDC dc(this);
CPen pen(PS_SOLID,5,RGB(255,0,0));
dc.SelectObject(&pen);
CBrush *pBrush=CBrush::FromHandle((HBRUSH)GetStockObject(NULL_BRUSH));
dc.SelectObject(pBrush);
dc.Ellipse(rect.right / m_leafnum * (i - 1),rect.bottom - (rect.bottom / m_leafnum),rect.right / m_leafnum * i,rect.bottom);
CString str;
itoa(HT[i].weight,(char*)&str,10);
dc.TextOut(rect.right / m_leafnum * (i - 1)+(rect.right / m_leafnum) / 2,rect.bottom - (rect.bottom / m_leafnum)+(rect.bottom / m_leafnum) / 2,str); }
解决方案 »
- 求救!对于类似QQ的一个软件,修改好友的备注,进行好友搜索以后,又回到了原来没有修改的状态
- CrichEditView禁止OLe托拽?急...............
- 内存分配问题
- 我有摄像头和麦克风,请问哪个软件能同时抓取视频和音频,即录制有声视频文件?
- 关于位图的一个问题,大侠帮帮手!!
- 现在公司要求我学e vc++,请问怎样学好它?应该按怎样的步骤学习?
- 请问能不能在两个程序之间共享同一个类?
- 为什么我编译的对话框上显示的是乱码啊,Help~~~~~~~~~
- 在vc中怎么在文件一行的结尾处加一个字符?(内空)
- joke100
- MFC中当改变对话框大小时怎么让控件自动调整大小
- 问一个关于擦除透明背景上画出来的东西的问题
{
// TODO: add construction code here
m_allnode = 0;
m_leafnum = 0;
i = 0;
GetClientRect(&rect); //获取客户区大小
}
----------------
你在构造函数里调用GetClientRect不觉得早了点吗?