// SketcherView.cpp : implementation of the CSketcherView class
//
#include "stdafx.h"
#include "Sketcher.h"
#include "SketcherDoc.h"
#include "Elements.h"
#include "SketcherView.h"
#include "ChildFrm.h"
#include "ScaleDialog.h"
#include "TextDialog.h"
#include "PrintData.h"
#include <cmath>
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
// CSketcherView
IMPLEMENT_DYNCREATE(CSketcherView, CScrollView)
BEGIN_MESSAGE_MAP(CSketcherView, CScrollView)
// 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)
ON_WM_LBUTTONUP()
ON_WM_LBUTTONDOWN()
ON_WM_MOUSEMOVE()
ON_WM_CONTEXTMENU()
ON_COMMAND(ID_ELEMENT_MOVE, &CSketcherView::OnElementMove)
ON_COMMAND(ID_ELEMENT_DELETE, &CSketcherView::OnElementDelete)
ON_WM_RBUTTONDOWN()
ON_COMMAND(ID_ELEMENT_SENDTOBACK, &CSketcherView::OnElementSendtoback)
ON_COMMAND(ID_VIEW_SCALE, &CSketcherView::OnViewScale)
END_MESSAGE_MAP()
// CSketcherView construction/destruction
CSketcherView::CSketcherView()
: m_FirstPoint(0,0)
, m_SecondPoint(0,0)
, m_pTempElement(NULL)
, m_pSelected(NULL)
, m_MoveMode(FALSE)
, m_CursorPos(CPoint(0,0))
, m_FirstPos(CPoint(0,0))
,m_Scale(1)
{
SetScrollSizes(MM_TEXT, CSize(0,0)); // Set arbitrary scrollers
}
CSketcherView::~CSketcherView()
{
}
BOOL CSketcherView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CView::PreCreateWindow(cs);
}
// CSketcherView drawing
void CSketcherView::OnDraw(CDC* pDC)
{
CSketcherDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
if(!pDoc)
return;
POSITION aPos = pDoc->GetListHeadPosition();
CElement* pElement = 0; // Store for an element pointer
while(aPos) // Loop while aPos is not null
{
pElement = pDoc->GetNext(aPos); // Get the current element pointer
// If the element is visible...
if(pDC->RectVisible(pElement->GetBoundRect()))
pElement->Draw(pDC, m_pSelected);// ...draw it
}
}
// CSketcherView printing
BOOL CSketcherView::OnPreparePrinting(CPrintInfo* pInfo)
{
pInfo->m_lpUserData = new CPrintData; // Create a print data object
CSketcherDoc* pDoc = GetDocument(); // Get a document pointer
// Get the whole document area
CRect DocExtent = pDoc->GetDocExtent();
// Save the reference point for the whole document
((CPrintData*)(pInfo->m_lpUserData))->m_DocRefPoint =
CPoint(DocExtent.left, DocExtent.bottom);
// Get the name of the document file and save it
((CPrintData*)(pInfo->m_lpUserData))->m_DocTitle = pDoc->GetTitle();
// Calculate how many printed page widths of 600 units are required
// to accommodate the width of the document
((CPrintData*)(pInfo->m_lpUserData))->m_nWidths =
static_cast<UINT>(ceil((static_cast<double>(DocExtent.Width()))/600.0));
// Calculate how many printed page lengths of 900 units are required
// to accommodate the document length
((CPrintData*)(pInfo->m_lpUserData))->m_nLengths =
static_cast<UINT>(ceil((static_cast<double>(DocExtent.Height()))/900.0));
// Set the first page number as 1 and
// set the last page number as the total number of pages
pInfo->SetMinPage(1);
pInfo->SetMaxPage((static_cast<CPrintData*>(pInfo->m_lpUserData))->m_nWidths *
(static_cast<CPrintData*>(pInfo->m_lpUserData))->m_nLengths);
return DoPreparePrinting(pInfo);
}
void CSketcherView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add extra initialization before printing
}
void CSketcherView::OnEndPrinting(CDC* pDC, CPrintInfo* pInfo)
{
// Delete our print data object
delete static_cast<CPrintData*>(pInfo->m_lpUserData);
}
// CSketcherView diagnostics
#ifdef _DEBUG
void CSketcherView::AssertValid() const
{
CView::AssertValid();
}
void CSketcherView::Dump(CDumpContext& dc) const
{
CView::Dump(dc);
}
CSketcherDoc* CSketcherView::GetDocument() const // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CSketcherDoc)));
return (CSketcherDoc*)m_pDocument;
}
#endif //_DEBUG
// CSketcherView message handlers
void CSketcherView::OnLButtonUp(UINT nFlags, CPoint point)
{
if(this == GetCapture())
ReleaseCapture(); // Stop capturing mouse messages
// If there is an element, add it to the document
if(m_pTempElement)
{
GetDocument()->AddElement(m_pTempElement);
GetDocument()->UpdateAllViews(0,0,m_pTempElement); // Tell all the views
m_pTempElement = 0; // Reset the element pointer
}
}
void CSketcherView::OnLButtonDown(UINT nFlags, CPoint point)
{
CClientDC aDC(this); // Create a device context
OnPrepareDC(&aDC); // Get origin adjusted
aDC.DPtoLP(&point); // convert point to Logical
// In moving mode, so drop the element
if(m_MoveMode)
{
m_MoveMode = FALSE; // Kill move mode
m_pSelected = 0; // De-select element
GetDocument()->UpdateAllViews(0); // Redraw all the views
GetDocument()->SetModifiedFlag(); // Set the modified flag
}
else
{
CSketcherDoc* pDoc = GetDocument();// Get a document pointer
if(pDoc->GetElementType() == TEXT)
{
CTextDialog aDlg;
if(aDlg.DoModal() == IDOK)
{
// Exit OK so create a text element
CFont aFont;
aFont.CreatePointFont(100, _T(""));
CFont* pOldFont = aDC.SelectObject(&aFont);
CSketcherDoc* pDoc = GetDocument();
CSize TextExtent = aDC.GetTextExtent(aDlg.m_TextString);
// Get bottom right of text rectangle - MM_LOENGLISH
CPoint BottomRt(point.x+TextExtent.cx, point.y-TextExtent.cy);
CText* pTextElement = new CText(point, BottomRt,
aDlg.m_TextString, pDoc->GetElementColor());
// Add the element to the document
pDoc->AddElement(pTextElement);
// Get all views updated
pDoc->UpdateAllViews(0,0,pTextElement);
aDC.SelectObject(pOldFont);
}
return;
}
m_FirstPoint = point; // Record the cursor position
SetCapture(); // Capture subsequent mouse messages
}
}
void CSketcherView::OnMouseMove(UINT nFlags, CPoint point)
{
// Define a Device Context object for the view
CClientDC aDC(this); // DC is for this view
OnPrepareDC(&aDC); // Get origin adjusted
// If we are in move mode, move the selected element and return
if(m_MoveMode)
{
aDC.DPtoLP(&point); // Convert to logical coordinatess
MoveElement(aDC, point); // Move the element
return;
}
aDC.SetROP2(R2_NOTXORPEN); // Set the drawing mode
if((nFlags&MK_LBUTTON) && (this==GetCapture()))
{
aDC.DPtoLP(&point); // convert point to Logical
m_SecondPoint = point; // Save the current cursor position
if(m_pTempElement)
{
if(CURVE == GetDocument()->GetElementType()) // Is it a curve?
{ // We are drawing a curve
// so add a segment to the existing curve
static_cast<CCurve*>(m_pTempElement)->AddSegment(m_SecondPoint);
m_pTempElement->Draw(&aDC); // Now draw it
return; // We are done
}
aDC.SetROP2(R2_NOTXORPEN); // Set drawing mode
// Redraw the old element so it disappears from the view
m_pTempElement->Draw(&aDC);
delete m_pTempElement; // Delete the old element
m_pTempElement = 0;
没有合适的资源?快使用搜索试试~ 我知道了~
VC++2008入门经典代码大全
共1098个文件
cpp:537个
h:430个
bmp:88个
5星 · 超过95%的资源 需积分: 0 20 下载量 196 浏览量
2012-05-24
22:05:34
上传
评论
收藏 1.14MB RAR 举报
温馨提示
VC++2008入门经典代码大全,包含书中代码和练习答案(补全的中文版书籍见我上传的其他资料)
资源推荐
资源详情
资源评论
收起资源包目录
VC++2008入门经典代码大全 (1098个子文件)
app.aps 43KB
app.aps 22KB
app.aps 7KB
app.aps 6KB
ellipse.bmp 1KB
text.bmp 246B
curve.bmp 246B
penwidth.bmp 246B
rectangle.bmp 246B
red.bmp 246B
blue.bmp 246B
line.bmp 246B
font.bmp 246B
circle.bmp 246B
green.bmp 246B
black.bmp 246B
curve.bmp 246B
rectangle.bmp 246B
red.bmp 246B
blue.bmp 246B
line.bmp 246B
circle.bmp 246B
green.bmp 246B
black.bmp 246B
curve.bmp 246B
rectangle.bmp 246B
red.bmp 246B
blue.bmp 246B
line.bmp 246B
circle.bmp 246B
green.bmp 246B
black.bmp 246B
text.bmp 246B
curve.bmp 246B
penwidth.bmp 246B
rectangle.bmp 246B
red.bmp 246B
blue.bmp 246B
line.bmp 246B
font.bmp 246B
circle.bmp 246B
green.bmp 246B
black.bmp 246B
curve.bmp 246B
rectangle.bmp 246B
red.bmp 246B
blue.bmp 246B
line.bmp 246B
circle.bmp 246B
green.bmp 246B
black.bmp 246B
text.bmp 246B
curve.bmp 246B
penwidth.bmp 246B
rectangle.bmp 246B
red.bmp 246B
blue.bmp 246B
line.bmp 246B
font.bmp 246B
circle.bmp 246B
green.bmp 246B
black.bmp 246B
curve.bmp 246B
rectangle.bmp 246B
red.bmp 246B
blue.bmp 246B
line.bmp 246B
circle.bmp 246B
green.bmp 246B
black.bmp 246B
curve.bmp 246B
rectangle.bmp 246B
red.bmp 246B
blue.bmp 246B
line.bmp 246B
circle.bmp 246B
green.bmp 246B
black.bmp 246B
curve.bmp 246B
dashed.bmp 246B
rectangle.bmp 246B
red.bmp 246B
blue.bmp 246B
line.bmp 246B
bitmap1.bmp 246B
dotted.bmp 246B
solid.bmp 246B
circle.bmp 246B
green.bmp 246B
bitmap2.bmp 246B
black.bmp 246B
ellipse.bmp 238B
SketcherView.cpp 20KB
SketcherView.cpp 20KB
SketcherView.cpp 20KB
SketcherView.cpp 19KB
SketcherView.cpp 16KB
SketcherView.cpp 16KB
SketcherView.cpp 16KB
SketcherView.cpp 16KB
共 1098 条
- 1
- 2
- 3
- 4
- 5
- 6
- 11
资源评论
- coldstarorchid2012-11-27真是帮了大忙了,非常好的资源。谢谢分享。
ljw910_00
- 粉丝: 2
- 资源: 9
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 课程设计-基于SpringBoot + Mybatis+python爬虫NBA球员数据爬取可视化+源代码+文档+sql+效果图
- 软件品质管理系列二项目策划规范.doc
- 基于TensorFlow+PyQt+GUI的酒店评论情感分析,支持分析本地数据文件和网络爬取数据分析+源代码+文档说明+安装教程
- 软件定义无线电中的模拟电路测试技术.pptx
- 软件开发协议(作为技术开发合同附件).doc
- 软件开发和咨询行业技术趋势分析.pptx
- 软件测试题详解及答案.doc
- 软件漏洞生命周期管理策略.pptx
- 毕业设计-基于Python实现的的简易气温爬虫,可以爬取全国各市的近7日气温数据
- 软件系统测试报告(实用版).doc
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功