拖动用鼠标拖动图片移动(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) ;

}

wordpress外贸企业主题 wordpress高级全行业大气外贸主题

wordpress高级全行业大气外贸主题,wordpress通用全行业高级外贸企业在线询单自适应主题建站程序,完善的外贸企业建站功能模块 + 高效通用的后台自定义设置,更实用的移动设备特色功能模块 + 更适于欧美国外用户操作体验 大气简洁的网站风格设计 + 高效优化的网站程序结构,更利于Goolge等SEO搜索优化和站点收录排名。点击进入:wordpress高级全行业大气外贸主题主题价格:¥398...

搬瓦工:香港PCCW机房即将关闭;可免费升级至香港CN2 GIA;2核2G/1Gbps大带宽高端线路,89美元/年

搬瓦工怎么样?这几天收到搬瓦工发来的邮件,告知香港pccw机房(HKHK_1)即将关闭,这也不算是什么出乎意料的事情,反而他不关闭我倒觉得奇怪。因为目前搬瓦工香港cn2 GIA 机房和香港pccw机房价格、配置都一样,可以互相迁移,但是不管是速度还是延迟还是丢包率,搬瓦工香港PCCW机房都比不上香港cn2 gia 机房,所以不知道香港 PCCW 机房存在还有什么意义?关闭也是理所当然的事情。点击进...

统计一下racknerd正在卖的超便宜VPS,值得推荐的便宜美国VPS

racknerd从成立到现在发展是相当迅速,用最低的价格霸占了大部分低端便宜vps市场,虽然VPS价格便宜,但是VPS的质量和服务一点儿都不拉跨,服务器稳定、性能给力,尤其是售后方面时间短技术解决能力强,估计这也是racknerd这个品牌能如此成功的原因吧! 官方网站:https://www.racknerd.com 多种加密数字货币、信用卡、PayPal、支付宝、银联、webmoney,可...

鼠标图片为你推荐
支持ipad支持ipadeacceleratoreaccelerator.shm_size设置多少合适呢?photoshop技术ps几大关键技术?photoshop技术photoshop技术对哪些工作有用?ipad如何上网ipad怎么设置网络?ipadwifiIpad怎么用移动无线上网win7如何关闭445端口如何彻底永久取消win7粘滞键功能routeaddroute add 添加路由的命令,内网和外网如何同时上ios10.0.3苹果10.03系统怎么样
域名代理 国外免费域名网站 什么是域名解析 香港vps99idc 樊云 http500内部服务器错误 搜狗抢票助手 河南移动网 河南移动m值兑换 t云 网购分享 phpinfo windowssever2008 alexa世界排名 优惠服务器 nic 网络安装 回程 次时代主机 正在登陆游戏服务器 更多