几何尺寸与公差论坛------致力于产品几何量公差标准GD&T (GDT:ASME)|New GPS(ISO)研究/CAD设计/CAM加工/CMM测量  


返回   几何尺寸与公差论坛------致力于产品几何量公差标准GD&T (GDT:ASME)|New GPS(ISO)研究/CAD设计/CAM加工/CMM测量 » 仿射空间:CAX软件开发(三)二次开发与程序设计 » 程序设计 » vc编程
用户名
密码
注册 帮助 会员 日历 银行 搜索 今日新帖 标记论坛为已读


回复
 
主题工具 搜索本主题 显示模式
旧 2007-07-22, 04:26 PM   #1
yogy
高级会员
 
注册日期: 06-11
帖子: 1527
精华: 15
现金: 6353 标准币
资产: 6353 标准币
yogy 向着好的方向发展
默认 Draw line sample

1.DrawLineView.cpp
// DrawLineView.cpp : implementation of the CDrawLineView class
//
#include "stdafx.h"
#include "DrawLine.h"

#include "DrawLineDoc.h"
#include "DrawLineView.h"

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

/////////////////////////////////////////////////////////////////////////////
// CDrawLineView

IMPLEMENT_DYNCREATE(CDrawLineView, CView)

BEGIN_MESSAGE_MAP(CDrawLineView, CView)
//{{AFX_MSG_MAP(CDrawLineView)
ON_WM_LBUTTONDOWN()
ON_WM_MOUSEMOVE()
ON_WM_LBUTTONUP()
//}}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()

/////////////////////////////////////////////////////////////////////////////
// CDrawLineView construction/destruction

CDrawLineView::CDrawLineView()
{
// TODO: add construction code here
m_Drag = 0;
m_HCursor = AfxGetApp()->LoadStandardCursor(IDC_CROSS);
}

CDrawLineView::~CDrawLineView()
{
}

BOOL CDrawLineView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
cs.lpszClass = AfxRegisterWndClass(CS_HREDRAW|CS_VREDRAW,0,
(HBRUSH)::GetStockObject(WHITE_BRUSH),0);

return CView::PreCreateWindow(cs);
}

/////////////////////////////////////////////////////////////////////////////
// CDrawLineView drawing

void CDrawLineView::OnDraw(CDC* pDC)
{
CDrawLineDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// TODO: add draw code for native data here
COLORREF cr0;
cr0 = RGB(255,0,0);
CPen *pen=new CPen(PS_SOLID,1,cr0);
CBrush *brush=new CBrush(cr0);
CPen *oldpen=pDC->SelectObject(pen);
CBrush *oldBrush=pDC->SelectObject(brush);
pDC->MoveTo(50,50);
pDC->LineTo(750,50);
pDC->LineTo(750,550);
pDC->LineTo(50,550);
pDC->LineTo(50,50);
pDC->SelectObject(oldpen);
pDC->SelectObject(oldBrush);
delete pen;
delete brush;

}

/////////////////////////////////////////////////////////////////////////////
// CDrawLineView printing

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

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

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

/////////////////////////////////////////////////////////////////////////////
// CDrawLineView diagnostics

#ifdef _DEBUG
void CDrawLineView::AssertValid() const
{
CView::AssertValid();
}

void CDrawLineView::Dump(CDumpContext& dc) const
{
CView::Dump(dc);
}

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

/////////////////////////////////////////////////////////////////////////////
// CDrawLineView message handlers

void CDrawLineView::OnLButtonDown(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
m_pPrev = point; //当前位置
m_pOrigin = point; //起点位置
SetCapture(); //保证鼠标信息发送到视窗
m_Drag = 1; //拖动状态标识
RECT rect;
GetClientRect(&rect); //获取客户区坐标
ClientToScreen(&rect); //客户区坐标转换为屏幕坐标
ClipCursor(&rect); //光标限定在客户区内

// CView::OnLButtonDown(nFlags, point);
}

void CDrawLineView::OnMouseMove(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
SetCursor(m_HCursor);
if(m_Drag)
{
CClientDC dc(this);
dc.SetROP2(R2_NOT); //设置异或绘图模式
dc.MoveTo(m_pOrigin);
dc.LineTo(m_pPrev);
dc.MoveTo(m_pOrigin);
dc.LineTo(point);
m_pPrev = point;
}

// CView::OnMouseMove(nFlags, point);
}

void CDrawLineView::OnLButtonUp(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
if(m_Drag)
{
m_Drag = 0; //设置非拖动状态
ReleaseCapture(); //释放鼠标恢复正常
ClipCursor(NULL); //让鼠标任意移动
}

// CView::OnLButtonUp(nFlags, point);
}
yogy离线中   回复时引用此帖
GDT自动化论坛(仅游客可见)
旧 2007-07-22, 04:27 PM   #2
yogy
高级会员
 
注册日期: 06-11
帖子: 1527
精华: 15
现金: 6353 标准币
资产: 6353 标准币
yogy 向着好的方向发展
默认 回复: Draw line sample

2.DrawLineView.h
// DrawLineView.h : interface of the CDrawLineView class
//
/////////////////////////////////////////////////////////////////////////////
#if !defined(AFX_DRAWLINEVIEW_H__92BA1170_1137_4E72_A93C_9FBD819536CA__INCLUDED_)
#define AFX_DRAWLINEVIEW_H__92BA1170_1137_4E72_A93C_9FBD819536CA__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000


class CDrawLineView : public CView
{
protected: // create from serialization only
int m_Drag;
HCURSOR m_HCursor;
CPoint m_pPrev;
CPoint m_pOrigin;

CDrawLineView();
DECLARE_DYNCREATE(CDrawLineView)

// Attributes
public:
CDrawLineDoc* GetDocument();

// Operations
public:

// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CDrawLineView)
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:
virtual ~CDrawLineView();
#ifdef _DEBUG
virtual void AssertValid() const;
virtual void Dump(CDumpContext& dc) const;
#endif

protected:

// Generated message map functions
protected:
//{{AFX_MSG(CDrawLineView)
afx_msg void OnLButtonDown(UINT nFlags, CPoint point);
afx_msg void OnMouseMove(UINT nFlags, CPoint point);
afx_msg void OnLButtonUp(UINT nFlags, CPoint point);
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};

#ifndef _DEBUG // debug version in DrawLineView.cpp
inline CDrawLineDoc* CDrawLineView::GetDocument()
{ return (CDrawLineDoc*)m_pDocument; }
#endif

/////////////////////////////////////////////////////////////////////////////

//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.

#endif // !defined(AFX_DRAWLINEVIEW_H__92BA1170_1137_4E72_A93C_9FBD819536CA__INCLUDED_)
yogy离线中   回复时引用此帖
回复


主题工具 搜索本主题
搜索本主题:

高级搜索
显示模式

发帖规则
不可以发表新主题
不可以回复主题
不可以上传附件
不可以编辑您的帖子

vB 代码开启
[IMG]代码开启
HTML代码关闭

相似的主题
主题 主题发起者 论坛 回复 最后发表
【原创】我自己编写的一段程序大家看看 hanweisheng 标准件库 0 2006-05-08 09:27 PM


所有的时间均为北京时间。 现在的时间是 10:38 AM.


于2004年创办,几何尺寸与公差论坛"致力于产品几何量公差标准GD&T | GPS研究/CAD设计/CAM加工/CMM测量"。免责声明:论坛严禁发布色情反动言论及有关违反国家法律法规内容!情节严重者提供其IP,并配合相关部门进行严厉查处,若內容有涉及侵权,请立即联系我们QQ:44671734。注:此论坛须管理员验证方可发帖。
沪ICP备06057009号-2
更多