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

}

酷番云78元台湾精品CN2 2核 1G 60G SSD硬盘

酷番云怎么样?酷番云就不讲太多了,介绍过很多次,老牌商家完事,最近有不少小伙伴,一直问我台湾VPS,比较难找好的商家,台湾VPS本来就比较少,也介绍了不少商家,线路都不是很好,有些需求支持Windows是比较少的,这里我们就给大家测评下 酷番云的台湾VPS,支持多个版本Linux和Windows操作系统,提供了CN2线路,并且还是原生IP,更惊喜的是提供的是无限流量。有需求的可以试试。可以看到回程...

bluehost32元/月,2核2G/20GB空间,独立ip,新一代VPS美国云主机!

bluehost怎么样?bluehost推出新一代VPS美国云主机!前几天,BlueHost也推出了对应的周年庆活动,全场海外虚拟主机月付2.95美元起,年付送免费的域名和SSL证书,通过活动进入BlueHost中文官网,购买虚拟主机、云虚拟主机和独立服务器参与限时促销。今天,云服务器网(yuntue.com)小编给大家介绍的是新一代VPS美国云主机,美国SSD云主机,2核2G/20GB空间,独立...

企鹅小屋:垃圾服务商有跑路风险,站长注意转移备份数据!

企鹅小屋:垃圾服务商有跑路风险!企鹅不允许你二次工单的,二次提交工单直接关服务器,再严重就封号,意思是你提交工单要小心,别因为提交工单被干了账号!前段时间,就有站长说企鹅小屋要跑路了,站长不太相信,本站平台已经为企鹅小屋推荐了几千元的业绩,CPS返利达182.67CNY。然后,站长通过企鹅小屋后台申请提现,提现申请至今已经有20几天,企鹅小屋也没有转账。然后,搞笑的一幕出现了:平台账号登录不上提示...

鼠标图片为你推荐
formgraph模块ios8支持ipad支持ipad支持ipadVTLHioscolumnios5Applicationsios5勒索病毒win7补丁win7有针对勒索病毒的补丁吗ipadwifiIpad怎么用移动无线上网
美国免费虚拟主机 ipage 轻博客 60g硬盘 光棍节日志 鲜果阅读 gspeed php空间推荐 老左来了 idc是什么 安徽双线服务器 双12 游戏服务器出租 服务器论坛 cdn网站加速 重庆服务器 卡巴斯基试用版下载 阿里云邮箱个人版 美国asp空间 web服务器 更多