用鼠标拖动图片移动Drag the picture move with mouseDrag 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) ;
}
onevps最新消息,为了更好服务中国区用户:1、网站支付方式新增了支付宝,即将增加微信;原信用卡、PayPal方式不变;(2)可以切换简体中文版网站,在网站顶部右上角找到那个米字旗,下拉可以换中国简体版本。VPS可选机房有:中国(香港)、新加坡、日本(东京)、美国(纽约、洛杉矶)、英国(伦敦)、荷兰(阿姆斯特丹)、瑞士(苏黎世)、德国(法兰克福)、澳大利亚(悉尼)。不管你的客户在亚太区域、美洲区...
imidc怎么样?imidc彩虹数据或彩虹网络现在促销旗下日本多IP站群独立服务器,原价159美元的机器现在只需要88美元,而且给13个独立IPv4,30Mbps直连带宽,不限制月流量!IMIDC又名为彩虹数据,rainbow cloud,香港本土运营商,全线产品都是商家自营的,自有IP网络资源等,提供的产品包括VPS主机、独立服务器、站群独立服务器等,数据中心区域包括香港、日本、台湾、美国和南非...
Central美国独立日活动正在进行中,旗下美国达拉斯机房VPS 65折优惠,季付赠送双倍内存(需要发工单),Central租用的Hivelocity的机房,只支持信用卡和加密货币付款,不支持paypal,需要美国独服的可以谨慎入手试试。Central怎么样?Central便宜服务器,Central自称成立于2019年,主营美国达拉斯机房Linux vps、Windows vps、专用服务器和托管...