// MFC绘图版View.cpp : implementation of the CMFCView class
//
#include "stdafx.h"
#include "MFC绘图版.h"
#include "MFC绘图版Doc.h"
#include "MFC绘图版View.h"
#include "Stroke.h"
#include "Graph.h"
#include "MainFrm.h"
#include "SettingDlg.h"
#include "math.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CMFCView
IMPLEMENT_DYNCREATE(CMFCView, CView)
BEGIN_MESSAGE_MAP(CMFCView, CView)
//{{AFX_MSG_MAP(CMFCView)
ON_WM_LBUTTONDOWN()
ON_WM_LBUTTONUP()
ON_WM_MOUSEMOVE()
ON_WM_RBUTTONDOWN()
ON_COMMAND_RANGE(
IDM_DRAW_NOTHING, // ID范围的最小值
IDM_DRAW_RECT, // ID范围的最大值
OnDrawChange) //消息处理函数
ON_UPDATE_COMMAND_UI_RANGE(IDM_DRAW_NOTHING,IDM_DRAW_RECT,OnUpdateOperDrawChange)
ON_COMMAND(ID_EDIT_UNDO, OnEditUndo)
ON_COMMAND(IDM_CLEAR, OnClear)
ON_COMMAND(IDM_SET_LINE_STYLE_WIDTH,OnSetLineStyleWidth)
ON_COMMAND(IDM_SET_COLOR,OnSetColor)
ON_COMMAND(IDM_SET_FONT,OnSetFont)
ON_COMMAND(IDM_OPEN_BMP,OnOpenBmp)
//}}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)
ON_COMMAND(ID_recover, &CMFCView::Onrecover)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CMFCView construction/destruction
CMFCView::CMFCView()
{
// TODO: add construction code here
m_bDraw = false;
m_nLineStyle = 0;
m_nLineWidth = 1;
m_DrawIndex = 0;
m_color = RGB(0,0,0);
}
CMFCView::~CMFCView()
{
}
BOOL CMFCView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CView::PreCreateWindow(cs);
}
/////////////////////////////////////////////////////////////////////////////
// CMFCView drawing
void CMFCView::OnDraw(CDC* pDC)
{
CMFCDoc* pDoc = GetDocument();
//---------------------重绘时显示任意曲线-----------------------------------//
CTypedPtrList<CObList,CStroke*>& strokeList = pDoc->m_strokeList;
POSITION pos = strokeList.GetHeadPosition();
while (pos != NULL)
{
CStroke* pStroke = strokeList.GetNext(pos);
pStroke->DrawStroke(pDC);
}
//-------------------重绘时显示保存在m_graph中的图形------------------//
int pCount = m_graph.GetSize();
for(int j=0;j<m_graph.GetSize();j++)
{
((CGraph*)m_graph.GetAt(j))->Draw(pDC);
}
//-----------------------绘制有橡皮条功能的图形----------------//
if(m_bDraw == true)
{
switch(m_DrawIndex)
{
case 1:
DrawLine(m_start,m_end);
break;
case 3:
DrawArrowLine(m_start,m_end);
break;
case 4:
DrawCircle(m_start,m_end);
break;
case 5:
DrawEllipse(m_start,m_end);
break;
case 6:
DrawRect(m_start,m_end);
break;
}
}
//-------------------------------文本文件重绘的代码--------------------//
if(m_txt == true && m_DrawIndex == 0)
{
CRect Rect;
GetClientRect(&Rect);
pDC->SelectObject(m_font);
pDC->DrawText(pBuf,Rect,DT_WORDBREAK);
}
//----------------------------图片重绘的代码----------------------------------//
if(m_bmp == true && m_DrawIndex == 0)
{
pDC->SetStretchBltMode(COLORONCOLOR);
StretchDIBits(pDC->GetSafeHdc(),0,0,BmpInfo.biWidth,
BmpInfo.biHeight,0,0,BmpInfo.biWidth,
BmpInfo.biHeight,pBmpData,pBmpInfo,DIB_RGB_COLORS,SRCCOPY);
}
ASSERT_VALID(pDoc);
// TODO: add draw code for native data here
}
/////////////////////////////////////////////////////////////////////////////
// CMFCView printing
BOOL CMFCView::OnPreparePrinting(CPrintInfo* pInfo)
{
// default preparation
return DoPreparePrinting(pInfo);
}
void CMFCView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add extra initialization before printing
}
void CMFCView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add cleanup after printing
}
/////////////////////////////////////////////////////////////////////////////
// CMFCView diagnostics
#ifdef _DEBUG
void CMFCView::AssertValid() const
{
CView::AssertValid();
}
void CMFCView::Dump(CDumpContext& dc) const
{
CView::Dump(dc);
}
CMFCDoc* CMFCView::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CMFCDoc)));
return (CMFCDoc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CMFCView message handlers
void CMFCView::OnLButtonDown(UINT nFlags, CPoint point)
{//鼠标左键按下消息响应函数
// TODO: Add your message handler code here and/or call default
switch(m_DrawIndex)
{
case 1:
m_bDraw = true;
m_start = point;
break;
case 2:
{
m_bDraw = true;
m_pStrokeCur = GetDocument()->NewStroke();// Add first point to the new stroke
m_pStrokeCur->m_pointArray.Add(point);
m_random_start = point; // Serves as the MoveTo() anchor point for the
// LineTo() the next point, as the user drags the
// mouse.
}
break;
case 3:
m_bDraw = true;
m_start = point;
break;
case 4:
m_bDraw = true;
m_start = point;
break;
case 5:
m_bDraw = true;
m_start = point;
break;
case 6:
m_bDraw = true;
m_start = point;
break;
}
m_end = point;
CView::OnLButtonDown(nFlags, point);
}
void CMFCView::OnLButtonUp(UINT nFlags, CPoint point)
{//鼠标左键弹起消息响应函数
// TODO: Add your message handler code here and/or call default
m_bDraw = false;
CClientDC dc(this);
CMFCDoc * pDoc = GetDocument();
CPen* pOldPen = dc.SelectObject(pDoc->GetCurrentPen());
switch(m_DrawIndex)
{
case 1:
{
m_end = point;
DrawLine(m_start,m_end);
CGraph *graph = new CGraph(m_DrawIndex,m_start,m_end,m_color,m_nLineWidth,m_nLineStyle);
m_graph.Add(graph);
}
break;
case 2:
{
//m_bDraw = false;
dc.MoveTo(m_random_start);
dc.LineTo(point);
dc.SelectObject(pOldPen);
m_pStrokeCur->m_pointArray.Add(point);
m_graph.Add(m_pStrokeCur);
// ReleaseCapture();
}
break;
case 3:
{
m_end = point;
DrawArrowLine(m_start,m_end);
CGraph *graph = new CGraph(m_DrawIndex,m_start,m_end,m_color,m_nLineWidth,m_nLineStyle);
m_graph.Add(graph);
}
break;
case 4:
{
m_end = point;
DrawCircle(m_start,m_end);
CGraph *graph = new CGraph(m_DrawIndex,m_start,m_end,m_color,m_nLineWidth,m_nLineStyle);
m_graph.Add(graph);
}
break;
case 5:
{
m_end = point;
DrawEllipse(m_start,m_end);
CGraph *graph = new CGraph(m_DrawIndex,m_start,m_end,m_color,m_nLineWidth,m_nLineStyle);
m_graph.Add(graph);
}
break;
case 6:
{
m_end = point;
DrawRect(m_start,m_end);
CGraph *graph = new CGraph(m_DrawIndex,m_start,m_end,m_color,m_nLineWidth,m_nLineStyle);
m_graph.Add(graph);
}
break;
}
CView::OnLButtonUp(nFlags, point);
}
void CMFCView::OnMouseMove(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
//-------------------------------------------------------------//
//在状态栏上显示时间
CString str;
str.Format("x=%d,y=%d",point.x,point.y);
//得到框架类窗口的指针GetParent(),然后指针强制转换为框架类的类型(CMainFrame*)
//调用状态栏类的成员函数setWidnowText
((CMainFrame*)GetParent())->m_wndStatusBar.SetWindowText(str);
//------------------------------------------------------------//
CClientDC dc(this);
CPen* pOldPen;
CPen pen(m_nLineStyle,m_nLineWidth,m_color);
switch(m_DrawIndex)
{
case 1:
if(m_bDraw == true)
{
m_end = point;
InvalidateRect(NULL,TRUE);
break;
}
case 2:
if(m_bDraw == true)
{
pOldPen= dc.SelectObject(&pen);
m_pStrokeCur->m_pointArray.Add(point);
dc.MoveTo(m_random_start);
dc.LineTo(point);
m_random_
没有合适的资源?快使用搜索试试~ 我知道了~
MFCopencv绘图板源码MFCopencv绘图板源码
共39个文件
h:9个
cpp:8个
plg:3个
1 下载量 157 浏览量
2024-08-05
22:26:47
上传
评论
收藏 140KB ZIP 举报
温馨提示
opencv,MFCopencv绘图板源码
资源推荐
资源详情
资源评论
收起资源包目录
MFCopencv绘图板.zip (39个子文件)
绘图板
可执行文件
MFC绘图版.exe 161KB
源码
MFC绘图版.plg 7KB
Graph.h 1KB
MFC绘图版View.ncb 33KB
MFC绘图版Doc.plg 1KB
Stroke.cpp 1KB
MFC绘图版Doc.cpp 3KB
MFC绘图版.vcxproj 12KB
MainFrm.cpp 3KB
MFC绘图版View.plg 2KB
MFC绘图版.vcproj 10KB
res
MFC绘图版.ico 1KB
MFC绘图版.rc2 401B
Toolbar.bmp 1KB
toolbar1.bmp 1KB
MFC绘图版Doc.ico 1KB
Resource.h 2KB
MFC绘图版.dsp 6KB
SettingDlg.h 1006B
MFC绘图版Doc.h 2KB
MFC绘图版.cpp 4KB
MainFrm.h 1KB
MFC绘图版.dsw 543B
StdAfx.cpp 211B
MFC绘图版.aps 504KB
Graph.cpp 4KB
MFC绘图版.opt 49KB
MFC绘图版.rc 14KB
Stroke.h 966B
MFC绘图版.h 1KB
SettingDlg.cpp 1KB
MFC绘图版Doc.ncb 33KB
MFC绘图版.clw 4KB
MFC绘图版View.opt 48KB
StdAfx.h 1KB
MFC绘图版View.h 4KB
MFC绘图版.sln 889B
MFC绘图版Doc.opt 48KB
MFC绘图版View.cpp 16KB
共 39 条
- 1
资源评论
codemami
- 粉丝: 1362
- 资源: 1894
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功