// GDItestView.h : interface of the CGDItestView class
//
/////////////////////////////////////////////////////////////////////////////#if !defined(AFX_GDITESTVIEW_H__27359140_7AD4_4241_88DB_A71F8867735E__INCLUDED_)
#define AFX_GDITESTVIEW_H__27359140_7AD4_4241_88DB_A71F8867735E__INCLUDED_
#define WM_MY_HUITU WM_USER+8#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000//typedef struct{
// int weight;
// int parent,lchild,rchild;
//}HTNode, *HuffmanTree; //动态分配数组存储哈夫曼树class CGDItestView : public CView
{
protected: // create from serialization only
CGDItestView();
DECLARE_DYNCREATE(CGDItestView)// Attributes
public:
CGDItestDoc* GetDocument();
// Operations
public:// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CGDItestView)
public:
virtual void OnDraw(CDC* pDC); // overridden to draw this view
virtual BOOL PreCreateWindow(CREATESTRUCT& cs);
protected:
virtual BOOL OnPreparePrinting(CPrintInfo* pInfo);
virtual void OnBeginPrinting(CDC* pDC, CPrintInfo* pInfo);
virtual void OnEndPrinting(CDC* pDC, CPrintInfo* pInfo);
//}}AFX_VIRTUAL// Implementation
public:
CRect rect;
int m_allnode;
int m_leafnum;
virtual ~CGDItestView();
#ifdef _DEBUG
virtual void AssertValid() const;
virtual void Dump(CDumpContext& dc) const;
#endifprotected:// Generated message map functions
protected:
//{{AFX_MSG(CGDItestView)
afx_msg void OnCeshi();
afx_msg void OnSaveDlg();
afx_msg LRESULT HuiTu(int iParam1,int iParam2);
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
private:
int i;
};#ifndef _DEBUG // debug version in GDItestView.cpp
inline CGDItestDoc* CGDItestView::GetDocument()
{ return (CGDItestDoc*)m_pDocument; }
#endif///////////////////////////////////////////////////////////////////////////////{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.#endif // !defined(AFX_GDITESTVIEW_H__27359140_7AD4_4241_88DB_A71F8867735E__INCLUDED_)#if !defined(AFX_INPUTDLG_H__CDFE1FC0_8438_47DA_9460_43DC71122826__INCLUDED_)
#define AFX_INPUTDLG_H__CDFE1FC0_8438_47DA_9460_43DC71122826__INCLUDED_
#define WM_MY_HUITU WM_USER+8#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
// InputDlg.h : header file
///////////////////////////////////////////////////////////////////////////////
// CInputDlg dialogclass CInputDlg : public CDialog
{
// Construction
public:
CInputDlg(CWnd* pParent = NULL); // standard constructor// Dialog Data
//{{AFX_DATA(CInputDlg)
enum { IDD = IDD_SAVE };
int leafdata;
int leafnum;
//}}AFX_DATA
// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CInputDlg)
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//}}AFX_VIRTUAL// Implementation
protected: // Generated message map functions
//{{AFX_MSG(CInputDlg)
afx_msg void OnSave();
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.#endif // !defined(AFX_INPUTDLG_H__CDFE1FC0_8438_47DA_9460_43DC71122826__INCLUDED_)
// InputDlg.cpp : implementation file
//#include "stdafx.h"
#include "GDItest.h"
#include "InputDlg.h"
//#include "GDItestView.h"#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif/////////////////////////////////////////////////////////////////////////////
// CInputDlg dialog
CInputDlg::CInputDlg(CWnd* pParent /*=NULL*/)
: CDialog(CInputDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CInputDlg)
leafdata = 0;
leafnum = 0;
//}}AFX_DATA_INIT
}
void CInputDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CInputDlg)
DDX_Text(pDX, IDC_LEAFDATA, leafdata);
DDX_Text(pDX, IDC_LEAFNUM, leafnum);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CInputDlg, CDialog)
//{{AFX_MSG_MAP(CInputDlg)
ON_BN_CLICKED(IDC_SAVE, OnSave)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()/////////////////////////////////////////////////////////////////////////////
// CInputDlg message handlers
void CInputDlg::OnSave()
{
// TODO: Add your control notification handler code here
::SendMessage(this->m_hWnd,WM_MY_HUITU,GetDlgItemInt(IDC_LEAFNUM),GetDlgItemInt(IDC_LEAFDATA));
}
// 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_MESSAGE(WM_MY_HUITU,HuiTu)
//}}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;
}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 handlers
LRESULT CGDItestView::HuiTu(int iParam1,int iParam2)
{
if(m_leafnum != iParam1)
{
m_leafnum = iParam1; //获取叶子数
m_allnode = 2 * m_leafnum - 1; //构成哈夫曼树节点总数
GetClientRect(&rect);
}
static HuffmanTree HT = (HuffmanTree)malloc((m_allnode + 1) * sizeof(HTNode)); //0号单元未用
i++;
//初始化叶子节点
HT[i].weight = iParam2;
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);
return 0;
}void 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 Dlg;
Dlg.DoModal();
}
//
/////////////////////////////////////////////////////////////////////////////#if !defined(AFX_GDITESTVIEW_H__27359140_7AD4_4241_88DB_A71F8867735E__INCLUDED_)
#define AFX_GDITESTVIEW_H__27359140_7AD4_4241_88DB_A71F8867735E__INCLUDED_
#define WM_MY_HUITU WM_USER+8#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000//typedef struct{
// int weight;
// int parent,lchild,rchild;
//}HTNode, *HuffmanTree; //动态分配数组存储哈夫曼树class CGDItestView : public CView
{
protected: // create from serialization only
CGDItestView();
DECLARE_DYNCREATE(CGDItestView)// Attributes
public:
CGDItestDoc* GetDocument();
// Operations
public:// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CGDItestView)
public:
virtual void OnDraw(CDC* pDC); // overridden to draw this view
virtual BOOL PreCreateWindow(CREATESTRUCT& cs);
protected:
virtual BOOL OnPreparePrinting(CPrintInfo* pInfo);
virtual void OnBeginPrinting(CDC* pDC, CPrintInfo* pInfo);
virtual void OnEndPrinting(CDC* pDC, CPrintInfo* pInfo);
//}}AFX_VIRTUAL// Implementation
public:
CRect rect;
int m_allnode;
int m_leafnum;
virtual ~CGDItestView();
#ifdef _DEBUG
virtual void AssertValid() const;
virtual void Dump(CDumpContext& dc) const;
#endifprotected:// Generated message map functions
protected:
//{{AFX_MSG(CGDItestView)
afx_msg void OnCeshi();
afx_msg void OnSaveDlg();
afx_msg LRESULT HuiTu(int iParam1,int iParam2);
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
private:
int i;
};#ifndef _DEBUG // debug version in GDItestView.cpp
inline CGDItestDoc* CGDItestView::GetDocument()
{ return (CGDItestDoc*)m_pDocument; }
#endif///////////////////////////////////////////////////////////////////////////////{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.#endif // !defined(AFX_GDITESTVIEW_H__27359140_7AD4_4241_88DB_A71F8867735E__INCLUDED_)#if !defined(AFX_INPUTDLG_H__CDFE1FC0_8438_47DA_9460_43DC71122826__INCLUDED_)
#define AFX_INPUTDLG_H__CDFE1FC0_8438_47DA_9460_43DC71122826__INCLUDED_
#define WM_MY_HUITU WM_USER+8#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
// InputDlg.h : header file
///////////////////////////////////////////////////////////////////////////////
// CInputDlg dialogclass CInputDlg : public CDialog
{
// Construction
public:
CInputDlg(CWnd* pParent = NULL); // standard constructor// Dialog Data
//{{AFX_DATA(CInputDlg)
enum { IDD = IDD_SAVE };
int leafdata;
int leafnum;
//}}AFX_DATA
// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CInputDlg)
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//}}AFX_VIRTUAL// Implementation
protected: // Generated message map functions
//{{AFX_MSG(CInputDlg)
afx_msg void OnSave();
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.#endif // !defined(AFX_INPUTDLG_H__CDFE1FC0_8438_47DA_9460_43DC71122826__INCLUDED_)
// InputDlg.cpp : implementation file
//#include "stdafx.h"
#include "GDItest.h"
#include "InputDlg.h"
//#include "GDItestView.h"#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif/////////////////////////////////////////////////////////////////////////////
// CInputDlg dialog
CInputDlg::CInputDlg(CWnd* pParent /*=NULL*/)
: CDialog(CInputDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CInputDlg)
leafdata = 0;
leafnum = 0;
//}}AFX_DATA_INIT
}
void CInputDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CInputDlg)
DDX_Text(pDX, IDC_LEAFDATA, leafdata);
DDX_Text(pDX, IDC_LEAFNUM, leafnum);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CInputDlg, CDialog)
//{{AFX_MSG_MAP(CInputDlg)
ON_BN_CLICKED(IDC_SAVE, OnSave)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()/////////////////////////////////////////////////////////////////////////////
// CInputDlg message handlers
void CInputDlg::OnSave()
{
// TODO: Add your control notification handler code here
::SendMessage(this->m_hWnd,WM_MY_HUITU,GetDlgItemInt(IDC_LEAFNUM),GetDlgItemInt(IDC_LEAFDATA));
}
// 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_MESSAGE(WM_MY_HUITU,HuiTu)
//}}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;
}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 handlers
LRESULT CGDItestView::HuiTu(int iParam1,int iParam2)
{
if(m_leafnum != iParam1)
{
m_leafnum = iParam1; //获取叶子数
m_allnode = 2 * m_leafnum - 1; //构成哈夫曼树节点总数
GetClientRect(&rect);
}
static HuffmanTree HT = (HuffmanTree)malloc((m_allnode + 1) * sizeof(HTNode)); //0号单元未用
i++;
//初始化叶子节点
HT[i].weight = iParam2;
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);
return 0;
}void 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 Dlg;
Dlg.DoModal();
}
解决方案 »
- 向一个文本写入数据有时候会失败??
- 如何用vc写出能够连接asp服务器的程序?
- 这样设置setsockopt可以防止接收粘包吗
- 紧急求救,怎样在VC下将word和powerpoint等文件进行导入数据库和导出数据库,请大家帮个忙。
- 怎么得到VC应用程序的路径
- variant关于VT_CY类型如何读取转换?
- 哪里有VSS下载?我的安装盘有问题.
- DAO、RDO、ADO、ODBC有什么区别?
- 如何得到当前鼠标的位置?
- 奇怪为什么打不开文件???
- DEClARE_DYNCREATE/IMPLEMENT_DYNCREATE是为了“动态创建"类的实例而定义的宏//有啥用处???
- 用VC++设计串口调试工具
::SendMessage(this->m_hWnd,WM_COMMAND,WM_MY_HUITU)
对话框的parent不一定是View,popup的对话框没有parent,child的才有Parent。
可能要GetActiveView才行。
pMain->GetActiveView();