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

}

[6.18]DogYun:充100送10元,态云7折,经典云8折,独立服务器月省100元,幸运大转盘最高5折

DogYun是一家2019年成立的国人主机商,提供VPS和独立服务器租用等,数据中心包括中国香港、美国洛杉矶、日本、韩国、德国、荷兰等,其中VPS包括常规VPS(经典云)和按小时计费VPS(动态云),使用自行开发的面板和管理系统,支持自定义配置,动态云各个硬件独立按小时计费,带宽按照用户使用量计费(不使用不计费)或者购买流量包,线路也可以自行切换。目前商家发布了6.18促销方案,新购动态云7折,经...

创梦网络-四川大带宽、镇江电信服务器云服务器低至56元

达州创梦网络怎么样,达州创梦网络公司位于四川省达州市,属于四川本地企业,资质齐全,IDC/ISP均有,从创梦网络这边租的服务器均可以备案,属于一手资源,高防机柜、大带宽、高防IP业务,一手整C IP段,四川电信,一手四川托管服务商,成都优化线路,机柜租用、服务器云服务器租用,适合建站做游戏,不须要在套CDN,全国访问快,直连省骨干,大网封UDP,无视UDP攻击,机房集群高达1.2TB,单机可提供1...

IMIDC(rainbow cloud):香港/台湾/日本/莫斯科独立服务器特价,闪购大促销,最低30usd/月起

imidc怎么样?imidc彩虹网路,rainbow cloud知名服务器提供商。自营多地区数据中心,是 Apnic RIPE Afrinic Arin 认证服务商。拥有丰富的网路资源。 在2021年 6.18 开启了输血大促销,促销区域包括 香港 台湾 日本 莫斯科 等地促销机型为 E3係,参与促销地区有 香港 日本 台湾 莫斯科 等地, 限量50台,售罄为止,先到先得。所有服务器配置 CPU ...

鼠标图片为你推荐
如何设置浏览器允许弹出窗口支付apple图书馆学、情报学期刊投稿指南win7telnet怎样在win7下打开telnet 命令canvas2动漫cv井口裕香,都有哪些作品?google中国地图怎样用GOOLE搜中国地图用卫星看的那一种(可以看到城市和房子的)重庆电信宽带管家如何才能以正确的流程在重庆电信安装上宽带win7关闭135端口win7系统怎么关闭135端口?网上很多方法都不好用!csshack关于CSS hack的写法ipad无法加入网络我的IPAD无法加入网络
深圳虚拟主机 免费顶级域名 新加坡服务器 免费个人博客 debian7 最好看的qq空间 免费ftp站点 三拼域名 怎么测试下载速度 admit的用法 asp免费空间申请 闪讯官网 国外的代理服务器 湖南idc 双线空间 阵亡将士纪念日 privatetracker SmartAXMT800 脚本大全 免费获得q币 更多