zoukankan
html css js c++ java
鼠标绘图读取所有点
int
m_NumStrokes
=
0
;
//
笔画数
int
m_NumPoints
=
0
;
//
所有点数
int
m_strokePoint
=
0
;
//
每一笔画的点数
int
PixelHandXY[
320
*
240
*
2
];
//
存放点的坐标
#define
LINE_END_CONST_X (9999)
//
每一笔画开始的标志,X坐标
#define
LINE_END_CONST_Y (9999)
//
每一笔画开始的标志,Y坐标
#define
MAXPOINT 100
//
每一笔画最多点数
bool
BIsLButtonDown
=
false
;
//
有没有按下鼠标
void
CHandDrawDialog::OnLButtonDown(UINT nFlags, CPoint point)
{
//
TODO: Add your message handler code here and/or call default
CWnd
*
Pwnd
=
GetDlgItem(IDC_STATIC_HAND_SHOW);
this
->
ClientToScreen(
&
point);
Pwnd
->
ScreenToClient(
&
point);
Pwnd
->
GetClientRect(
&
m_ShowRect);
if
(m_ShowRect.PtInRect(point))
{
m_ptOrigin
=
point;
BIsLButtonDown
=
true
;
m_NumStrokes
++
;
m_strokePoint
=
1
;
PixelHandXY[m_NumPoints
++
]
=
LINE_END_CONST_X;
PixelHandXY[m_NumPoints
++
]
=
LINE_END_CONST_Y;
PixelHandXY[m_NumPoints
++
]
=
m_ptOrigin.x;
PixelHandXY[m_NumPoints
++
]
=
m_ptOrigin.y;
CString strInfo;
strInfo.Format(
"
笔画数目:%d
"
,m_NumStrokes);
SetDlgItemText(IDC_STATIC_SHOW,strInfo);
}
CDialog::OnLButtonDown(nFlags, point);
}
void
CHandDrawDialog::OnMouseMove(UINT nFlags, CPoint point)
{
//
TODO: Add your message handler code here and/or call default
CWnd
*
Pwnd
=
GetDlgItem(IDC_STATIC_HAND_SHOW);
CDC
*
pDC
=
Pwnd
->
GetDC();
this
->
ClientToScreen(
&
point);
Pwnd
->
ScreenToClient(
&
point);
Pwnd
->
GetClientRect(
&
m_ShowRect);
if
(m_ShowRect.PtInRect(point))
{
HCURSOR hcur
=
AfxGetApp()
->
LoadCursor(IDC_CURSOR_PEN);
SetClassLong(GetSafeHwnd(),GCL_HCURSOR,(LONG)hcur);
if
(BIsLButtonDown)
{
if
(point.x
<
0
) point.x
=
0
;
if
(point.x
>
m_ShowRect.Width()) point.x
=
m_ShowRect.Width();
if
(point.y
<
0
) point.y
=
0
;
if
(point.y
>
m_ShowRect.Height()) point.y
=
m_ShowRect.Height();
if
(m_strokePoint
<=
MAXPOINT)
//
小与100才画出来
{
pDC
->
MoveTo(m_ptOrigin);
pDC
->
LineTo(point);
if
(m_ptOrigin
!=
point)
{
PixelHandXY[m_NumPoints
++
]
=
point.x;
PixelHandXY[m_NumPoints
++
]
=
point.y;
m_ptOrigin
=
point;
m_strokePoint
++
;
}
}
}
}
else
{
SetClassLong(GetSafeHwnd(),GCL_HCURSOR,(LONG)LoadCursor(NULL, IDC_ARROW));
}
ReleaseDC(pDC);
CDialog::OnMouseMove(nFlags, point);
}
void
CHandDrawDialog::OnLButtonUp(UINT nFlags, CPoint point)
{
//
TODO: Add your message handler code here and/or call default
BIsLButtonDown
=
false
;
m_strokePoint
=
0
;
CDialog::OnLButtonUp(nFlags, point);
}
重绘
void
CHandDrawDialog::OnPaint()
{
CPaintDC dc(
this
);
//
device context for painting
//
TODO: Add your message handler code here
CWnd
*
Pwnd
=
GetDlgItem(IDC_STATIC_HAND_SHOW);
CDC
*
pDC
=
Pwnd
->
GetDC();
CRect m_clientRect;
Pwnd
->
GetClientRect(
&
m_clientRect);
pDC
->
Rectangle(
&
m_clientRect);
//
画矩形,使图片框背景为白色。
CPoint m_StartPoint,m_EndPoint;
for
(
int
i
=
0
;i
<
m_NumPoints
-
3
;i
=
i
+
2
)
{
if
(PixelHandXY[i]
!=
LINE_END_CONST_X
&&
PixelHandXY[i
+
3
]
!=
LINE_END_CONST_Y)
{
m_StartPoint.x
=
PixelHandXY[i];
m_StartPoint.y
=
PixelHandXY[i
+
1
];
m_EndPoint.x
=
PixelHandXY[i
+
2
];
m_EndPoint.y
=
PixelHandXY[i
+
3
];
pDC
->
MoveTo(m_StartPoint);
if
(m_EndPoint.x
!=
0
) pDC
->
LineTo(m_EndPoint);
}
}
//
Do not call CDialog::OnPaint() for painting messages
}
打印
void
CHandDrawDialog::OnButtonPrint()
{
//
TODO: Add your control notification handler code here
if
(MessageBox(
"
您要打印当前图像吗?
"
,
"
询问
"
,MB_YESNO
|
MB_ICONQUESTION)
==
IDYES)
{
char
szprinter[
80
];
char
*
szDevice,
*
szDriver,
*
szOutput;
HDC hdcprint;
//
定义一个设备环境句柄
//
定义一个打印作业
static
DOCINFO di
=
{
sizeof
(DOCINFO),
"
printer
"
,NULL}
;
//
得到设备字符串存入数组szprinter中
GetProfileString(
"
windows
"
,
"
device
"
,
"
,,,
"
,szprinter,
80
);
//
将设备字符串分解
if
(NULL
!=
(szDevice
=
strtok(szprinter,
"
,
"
))
&&
NULL
!=
(szDriver
=
strtok(NULL,
"
,
"
))
&&
NULL
!=
(szOutput
=
strtok(NULL,
"
,
"
)))
{
CWaitCursor wc;
//
创建一个打印机设备句柄
if
((hdcprint
=
CreateDC(szDriver,szDevice,szOutput,NULL))
!=
0
)
{
if
(StartDoc(hdcprint,
&
di)
>
0
)
//
开始执行一个打印作业
{
StartPage(hdcprint);
//
打印机走纸,开始打印
SaveDC(hdcprint);
//
保存打印机设备句柄
//
输出一行文字
CString str;
str.Format(
"
班级: %d 姓名: %d 学号: %d
"
,
10
,
20
,
30
);
TextOutA(hdcprint,
150
*
6
,
40
*
6
,str,str.GetLength());
//
输出图像
CPoint m_start,m_end;
for
(
int
k
=
0
;k
<
m_NumPoints
-
3
;k
=
k
+
2
)
{
if
((PixelHandXY[k]
!=
LINE_END_CONST_X)
&&
(PixelHandXY[k
+
3
]
!=
LINE_END_CONST_Y))
//
-1是新笔画开始的标志
{
m_start.x
=
PixelHandXY[k]
*
6
+
150
*
6
;
m_start.y
=
PixelHandXY[k
+
1
]
*
6
+
90
*
6
;
m_end.x
=
PixelHandXY[k
+
2
]
*
6
+
150
*
6
;
m_end.y
=
PixelHandXY[k
+
3
]
*
6
+
90
*
6
;
MoveToEx(hdcprint,m_start.x,m_start.y,NULL);
if
(PixelHandXY[k
+
2
]
!=
0
)
{
LineTo(hdcprint,m_end.x,m_end.y);
//
m_end.x=0是轨迹结束的标志
}
}
}
RestoreDC(hdcprint,
-
1
);
//
恢复打印机设备句柄
EndPage(hdcprint);
//
打印机停纸,停止打印
EndDoc(hdcprint);
//
结束一个打印作业
MessageBox(
"
打印完成!
"
,
"
提示
"
,MB_OK);
}
else
{
MessageBox(
"
打印机没有连接!
"
,
"
提示
"
,MB_OK
|
MB_ICONWARNING);
}
//
用API函数DeleteDC销毁一个打印机设备句柄
DeleteDC(hdcprint);
}
else
{
MessageBox(
"
没有安装打印机!
"
,
"
提示
"
,MB_OK
|
MB_ICONWARNING);
return
;
}
}
}
}
查看全文
相关阅读:
公司的OA系统基础框架系统(光标办公平台)
通用权限控制系统--系统设计
聘.Net软件工程师(昆明)
对AgileFramework的思考
iTextSharp.text.Rectangle 使用方法说明
Castle Aspect# 难倒只支持一个拦截器?
聘云南昆明地区的.Net工程师
招聘云南软件销售人员
给vncviewer 添加调用函数 GIS
分享一个c++ 加密算法 ,在百度贴吧找的,比较好玩 GIS
原文地址:https://www.cnblogs.com/wqj1212/p/1121327.html
最新文章
wpf 4.5和4.5之前版本 binding的一个bug????
去除string的 换行回车符等特殊字符
设计时特性
BuildAction之Content与Resource(转)
wpf 自定义窗体 另一种实现方式
看坛子里面有个朋友 做了个wpf的时钟,开年无事也搞了个,分享一下
视图模型(ViewModel)到底是什么?(转载)
wpf treeview 之 整行选中 效果
PageDataSource+Request.CurrentExecutionFilePath实现便捷分页
Be the best ‘you’ that you can
热门文章
Five lessens live by to follow your dreamsOne
ASP.NET Cache学习心得分享
Win8学习总结之"给定的 System.Uri 无法转换为 Windows.Foundation.Uri"问题
.NET中将数据导出(导入)Excel文件
Thank you
关于猫叫、老鼠逃跑、人被惊醒的程序设计
AJAXControlTooKit实用控件使用详解
WinForm应用程序之注册模块的设计与实现
最近完成的一个可伸缩性的WEB开发框架
Visual WebGui 技术文档中文版下载
Copyright © 2011-2022 走看看