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

}

RAKsmart(年79元),云服务器年付套餐汇总 - 香港 美国 日本云服务器

RAKsmart 商家从原本只有专注于独立服务器后看到产品线比较单薄,后来陆续有增加站群服务器、高防服务器、VPS主机,以及现在也有在新增云服务器、裸机云服务器等等。机房也有增加到拥有洛杉矶、圣何塞、日本、韩国、中国香港等多个机房。在年前也有介绍到RAKsmart商家有提供年付129元的云服务器套餐,年后我们看到居然再次刷新年付云服务器低价格。我们看到云服务器低至年79元,如果有需要便宜云服务器的...

LayerStack$10.04/月(可选中国香港、日本、新加坡和洛杉矶)高性能AMD EPYC (霄龙)云服务器,

LayerStack(成立于2017年),当前正在9折促销旗下的云服务器,LayerStack的云服务器采用第 3 代 AMD EPYC™ (霄龙) 处理器,DDR4内存和企业级 PCIe Gen 4 NVMe SSD。数据中心可选中国香港、日本、新加坡和洛杉矶!其中中国香港、日本和新加坡分为国际线路和CN2线路,如果选择CN2线路,价格每月要+3.2美元,付款支持paypal,支付宝,信用卡等!...

wordpress高级跨屏企业主题 wordpress绿色企业自适应主题

wordpress高级跨屏企业主题,通用响应式跨平台站点开发,自适应PC端+各移动端屏幕设备,高级可视化自定义设置模块+高效的企业站搜索优化。wordpress绿色企业自适应主题采用标准的HTML5+CSS3语言开发,兼容当下的各种主流浏览器: IE 6+(以及类似360、遨游等基于IE内核的)、Firefox、Google Chrome、Safari、Opera等;同时支持移动终端的常用浏览器应...

鼠标图片为你推荐
圆周刊社区责任编辑:深圳做网站-确认收货手太快网店发来空箱子functionscss由陈可辛率领的《武侠》大军OPENCORE苹果引导配置说明第四版-基于photoshop技术ps几大关键技术?ipad如何上网苹果ipad无线上网卡怎么设置?win10关闭445端口如何进入注册表修改关闭445端口tcpip上的netbiostcp 协议里的 netbios . 在哪,找不到csshackcss中 *bottom是什么意思?
ix主机 l5520 名片模板psd lamp配置 韩国网名大全 北京双线机房 如何用qq邮箱发邮件 吉林铁通 免费个人网页 卡巴斯基试用版下载 香港ip 美国主机 什么是dns 发证机构 带宽测速 美国西雅图独立 iptables cc攻击 ddos攻击教程 dmz主机 更多