拖动用鼠标拖动图片移动(Drag the picture move with mouse)

鼠标图片  时间:2021-04-19  阅读:()

用鼠标拖动图片移动Drag the picture move with mouseDrag the picture to respond to the 3 mouse message

OnLBut t onD own, OnLBut t onUp, OnMous eMove

When the left button is pressed:

To determine if the image is pressed inside the image, if youcapture the picture

When the left key is released:

Release pictures

Mouse movement: according to the movement of the mouse,real-time redraw pictures

For this purpose, three class variables are set:

CPoint Pt; / / save the starting point

BOOL bcapture; / / image capture

CSize offsetsize; //offset of the mouse and the starting pointof the picture

The first is initialization:

[cpp] view plaincopyprint?

CMovePictureView: : CMovePictureView ()

{

Add construction code here / / TODO:

Bcapture=FALSE;

Pt.x=0;

Pt.y=0;

Offsetsize.cx=0;

Offsetsize.cy=0;

}

Then respond to the OnLButtonDown message

[cpp] view plaincopyprint?

Void CMovePictureView: : OnLButtonDown (UINT nFlags, CPointpoint)

{

CRect selrc (PT, size) ;

CClientDC DC (this) ;

OnPrepareDC (&dc) ;

CRgn rgn;

Rgn.CreateRectRgnIndirect (&selrc) ;

If (rgn.PtInRegion (point))

{

SetCapture () ;

B c ap tur e=T RUE;

CPoint RCPT (PT) ;

Offsetsize=point-rcpt;

SetCursor (LoadCursor (NULL, IDC_CROSS) ) ;

}

CScrollView: : OnLButtonDown (nFlags, point) ;

}

Respond to UP messages

[cpp] view plaincopyprint?

Void CMovePictureView: : OnLButtonUp (UINT nFlags, CPointpoint)

{

ReleaseCapture () ;

Bcapture=FALSE;

CScrollView: : OnLButtonUp (nFlags, point) ;

}

Respond to Move messages

[cpp] view plaincopyprint?

Void CMovePictureView: : OnMouseMove (UINT nFlags, CPointpoint)

{

If (bcapture)

{

CClientDC DC (this) ;

OnPrepareDC (&dc) ;

CRect oldrc (PT, size) ;

InvalidateRect (oldrc, TRUE) ;

Pt=point-offsetsize;

CRect newrc (PT, size) ;

InvalidateRect (newrc, TRUE) ;

}

CScrollView: : OnMouseMove (nFlags, point) ;

}

If you're drawing in the whole view or drawing in the entiredialog box, you can move the picture. But, if you're drawingin the CStatic picture control in the dialog box, there' s aproblem.

The reason is that: the mouse in response to the news, thecoordinates of CPoint points are the coordinates of the clientarea (dialog box because the response is a mouse message dialogbox so the coordinate system is a coordinate system, and thedialog box) our map is a CSTATIC picture control coordinatesystem and two coordinate systems are different, so there wasconfusion, cause we can not achieve the results you want.Solution: when the mouse message is received, screencoordinates are used as intermediate media. Specifically asfollows: first converts the CPoint from the dialog coordinatesystem to the screen coordinate system, and then converts thescreen coordinate system to the control coordinate system

[cpp] view plaincopyprint?

Void CShowImageDlg: : OnLButtonDown (UINT nFlags, CPoint point){

TODO: / / add your message handler code here and / or calldefault

CPoint orgPoint=point;

This->ClientToScreen (&point) ; //dialog box coordinates intoscreen coordinates

M_image.ScreenToClient (&point) ; / / screen coordinates intothe control coordinate system

CRect selRc (m_pt, m_size) ; / / coordinate control

CRgn rgn;

Rgn.CreateRectRgnIndirect (&selRc) ;

If (rgn.PtInRegion (point)) / / in the judgment of thecoordinate control, so you should first convert point tocoordinate control

{

SetCapture () ;

M_bc apt ure=TRUE;

CPoint RCPT (m_pt) ;

M_offsetsize=point-rcpt;

SetCursor (LoadCursor (NULL, IDC_CROSS) ) ;

}

CDialog: : OnLButtonDown (nFlags, orgPoint) ;

}

[cpp] view plaincopyprint?

Void CShowImageDlg: : OnLButtonUp (UINT nFlags, CPoint point){

TODO: / / add your message handler code here and / or calldefault

ReleaseCapture () ;

M_bcapture=FALSE;

CDialog: : OnLButtonUp (nFlags, point) ;

}

[cpp] view plaincopyprint?

Void CShowImageDlg: : OnMouseMove (UINT nFlags, CPoint point){

TODO: / / add your message handler code here and / or calldefault

CPoint orgPoint=point;

This->ClientToScreen (&point) ;

M_image.ScreenToClient (&point) ;

If (m_bcapture)

{

CRect oldRc (m_pt, m_size) ; / / coordinate control

M_image.ClientToScreen (&oldRc) ; / / into screen coordinatesThis->ScreenToClient (&oldRc) ; / / convert dialog boxcoordinates, then call the right InvalidateRect (oldRc, TRUE) ;because this function is invoked in the dialog box, so thedialog box coordinates coordinates

InvalidateRect (oldRc, TRUE) ;

M_pt=point-m_offsetsize;

CRect newRc (m_pt, m_size) ;

M_image.ClientToScreen (&newRc) ; // the same, will coordinatecontrol of newRc into the dialog box coordinates conversion,can call the InvalidateRect function correctly

This->ScreenToCl ient (&newRc) ;

InvalidateRect (newRc, TRUE) ;

}

CDialog: : OnMouseMove (nFlags, orgPoint) ;

}

RackNerd:美国便宜VPS,洛杉矶DC-02/纽约/芝加哥机房,4TB月流量套餐16.55美元/年

racknerd怎么样?racknerd美国便宜vps又开启促销模式了,机房优秀,有洛杉矶DC-02、纽约、芝加哥机房可选,最低配置4TB月流量套餐16.55美元/年,此外商家之前推出的最便宜的9.49美元/年套餐也补货上架,同时RackNerd美国AMD VPS套餐最低才14.18美元/年,是全网最便宜的AMD VPS套餐!RackNerd主要经营美国圣何塞、洛杉矶、达拉斯、芝加哥、亚特兰大、新...

EtherNetservers年付仅10美元,美国洛杉矶VPS/1核512M内存10GB硬盘1Gpbs端口月流量500GB/2个IP

EtherNetservers是一家成立于2013年的英国主机商,提供基于OpenVZ和KVM架构的VPS,数据中心包括美国洛杉矶、新泽西和杰克逊维尔,商家支持使用PayPal、支付宝等付款方式,提供 60 天退款保证,这在IDC行业来说很少见,也可见商家对自家产品很有信心。有需要便宜VPS、多IP VPS的朋友可以关注一下。优惠码SUMMER-VPS-15 (终身 15% 的折扣)SUMMER-...

Atcloud:全场8折优惠,美国/加拿大/英国/法国/德国/新加坡vps,500g大硬盘/2T流量/480G高防vps,$4/月

atcloud怎么样?atcloud刚刚发布了最新的8折优惠码,该商家主要提供常规cloud(VPS)和storage(大硬盘存储)系列VPS,其数据中心分布在美国(俄勒冈、弗吉尼亚)、加拿大、英国、法国、德国、新加坡,所有VPS默认提供480Gbps的超高DDoS防御。Atcloud高防VPS。atcloud.net,2020年成立,主要提供基于KVM虚拟架构的VPS、只能DNS解析、域名、SS...

鼠标图片为你推荐
徐州微信5fugedios11互联网周鸿祎University163大学生就业信息获取与信息分析支持ipadAnthemmy支持ipad城乡居民社会养老保险人脸识别生存认证iphone连不上wifi苹果手机无法连接wifi是什么原因
全球付 表格样式 服务器cpu性能排行 南昌服务器托管 免费全能空间 yundun 台湾google 外贸空间 英雄联盟台服官网 东莞主机托管 789电视剧网 蓝队云 bwg 网络安装 戴尔主机 个人web服务器 **tp服务器是什么 元旦促销方案 网站被挂马检测工具 letitgo冰雪奇缘 更多