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
;
}
}
}
}
查看全文
相关阅读:
TimeSpan的操作
List<T>的排序和筛选
编程中的一些概念
SVN返回版本
语音播报
优化编译器的局限性
Inline Functions 与它的形式参数和局部变量
函数的效能 & 指向 Member Functions 的指针与其效能
虚拟继承下 Virtual Function 的语意
多重继承下 Virtual Function 的语意
原文地址:https://www.cnblogs.com/wqj1212/p/1121327.html
最新文章
tableview head
苹果打包,每隔两年就会出现这个问题
Android中的GridView
Android中layoutParams
android中tabhost异常
PATB1033 旧键盘打字 (20 分)
日常笔记4关于cin、cin.get()、cin.getline()、getline()使用区别
日常笔记3关于bool类型数组初始化的问题
B1020 月饼(25分)
19.10.25
热门文章
19.10.26
19.10.23
19.10.19
19.10.18
19.10.16
ASP.NET MVC 实现二级域名
VS-Visual Studio-IIS Express 支持局域网访问
自动更新
WPF后台更改样式
SQL 函数 TIMESTAMPDIFF
Copyright © 2011-2022 走看看