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

📄 testview.cpp

📁 这个例子中,控件随窗口大小一起变
💻 CPP
字号:
// testView.cpp : implementation of the CTestView class
//

#include "stdafx.h"
#include "test.h"

#include "testSet.h"
#include "testDoc.h"
#include "testView.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CTestView

IMPLEMENT_DYNCREATE(CTestView, CRecordView)

BEGIN_MESSAGE_MAP(CTestView, CRecordView)
	//{{AFX_MSG_MAP(CTestView)
	ON_WM_SIZE()
	//}}AFX_MSG_MAP
	// Standard printing commands
	ON_COMMAND(ID_FILE_PRINT, CRecordView::OnFilePrint)
	ON_COMMAND(ID_FILE_PRINT_DIRECT, CRecordView::OnFilePrint)
	ON_COMMAND(ID_FILE_PRINT_PREVIEW, CRecordView::OnFilePrintPreview)
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CTestView construction/destruction

CTestView::CTestView()
	: CRecordView(CTestView::IDD)
{
	//{{AFX_DATA_INIT(CTestView)
		// NOTE: the ClassWizard will add member initialization here
	m_pSet = NULL;
	//}}AFX_DATA_INIT
	// TODO: add construction code here
    m_flag=FALSE;
}

CTestView::~CTestView()
{
}

void CTestView::DoDataExchange(CDataExchange* pDX)
{
	CRecordView::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CTestView)
	DDX_Control(pDX, IDC_TREE, m_Tree);
	//}}AFX_DATA_MAP
}

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

	return CRecordView::PreCreateWindow(cs);
}

void CTestView::OnInitialUpdate()
{
	m_pSet = &GetDocument()->m_testSet;
	CRecordView::OnInitialUpdate();
	GetParentFrame()->RecalcLayout();
	ResizeParentToFit();

}

/////////////////////////////////////////////////////////////////////////////
// CTestView printing

BOOL CTestView::OnPreparePrinting(CPrintInfo* pInfo)
{
	// default preparation
	return DoPreparePrinting(pInfo);
}

void CTestView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
	// TODO: add extra initialization before printing
}

void CTestView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
	// TODO: add cleanup after printing
}

/////////////////////////////////////////////////////////////////////////////
// CTestView diagnostics

#ifdef _DEBUG
void CTestView::AssertValid() const
{
	CRecordView::AssertValid();
}

void CTestView::Dump(CDumpContext& dc) const
{
	CRecordView::Dump(dc);
}

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

/////////////////////////////////////////////////////////////////////////////
// CTestView database support
CRecordset* CTestView::OnGetRecordset()
{
	return m_pSet;
}


/////////////////////////////////////////////////////////////////////////////
// CTestView message handlers

void CTestView::OnDraw(CDC* pDC) 
{
	// TODO: Add your specialized code here and/or call the base class
	
	CTestDoc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);

	//if(m_nDrawIndex >= 0)
	//{
		DrawCurve(pDC);
	//}
}

void CTestView::DrawCurve(CDC *pDC)
{
    int i,j;
	CRect rect;
	GetClientRect(&rect);
	rect.SetRect(rect.left+240, rect.top+20, rect.right-20, rect.bottom-20);
		
	pPen.CreatePen(PS_SOLID, 2, RGB(40, 44, 187));
	pOldPen = pDC->SelectObject(&pPen);
	
	//x
	
	pDC->MoveTo(rect.right-21, rect.bottom-21);
	pDC->LineTo(rect.right-21, rect.bottom-19);
	pDC->MoveTo(rect.right-23, rect.bottom-22);
	pDC->LineTo(rect.right-23, rect.bottom-18);
	pDC->MoveTo(rect.right-25, rect.bottom-23);
	pDC->LineTo(rect.right-25, rect.bottom-17);

	pDC->MoveTo(rect.left+20, rect.bottom-20);
	pDC->LineTo(rect.right-20, rect.bottom-20);
	pDC->TextOut(rect.right-33, rect.bottom-15, "Day");

	//y
	pDC->MoveTo(rect.left+18, rect.top+21);
	pDC->LineTo(rect.left+20, rect.top+21);
	pDC->MoveTo(rect.left+17, rect.top+23);
	pDC->LineTo(rect.left+21, rect.top+23);
	pDC->MoveTo(rect.left+16, rect.top+25);
	pDC->LineTo(rect.left+22, rect.top+25);

	pDC->MoveTo(rect.left+20, rect.bottom-20);
	pDC->LineTo(rect.left+20, rect.top+20);
	pDC->TextOut(rect.left, rect.top+20, "%");

	pDC->SelectObject(pOldPen);
	pPen.DeleteObject();
}

void CTestView::OnSize(UINT nType, int cx, int cy) 
{
	CRecordView::OnSize(nType, cx, cy);
	
	if(m_Tree)
	{
		m_Tree.MoveWindow(CRect(0,0,cx,cy),TRUE);
	}
	// TODO: Add your message handler code here 
}

⌨️ 快捷键说明

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