用鼠标拖动图片移动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) ;
}
GigsGigsCloud是一家成立于2015年老牌国外主机商,提供VPS主机和独立服务器租用,数据中心包括美国洛杉矶、中国香港、新加坡、马来西亚和日本等。商家VPS主机基于KVM架构,绝大部分系列产品中国访问速度不错,比如洛杉矶机房有CN2 GIA、AS9929及高防线路等。目前Los Angeles - SimpleCloud with Premium China DDOS Protectio...
7月4日是美国独立日,大致就是国庆节的意思吧。hostodo今年提前搞了个VPS大促销活动,4款便宜VPS,相当于7折,续费不涨价,本次促销不定时,不知道有多少货,卖完为止。VPS基于KVM虚拟,NVMe阵列,1Gbps带宽,自带一个IPv4+/64 IPv6,solusvm管理,送收费版DirectAdmin授权,VPS在用就有效! 官方网站:https://www.hostodo.com ...
BlueHost 主机商在以前做外贸网站的时候还是经常会用到的,想必那时候有做外贸网站或者是选择海外主机的时候还是较多会用BlueHost主机商的。只不过这些年云服务器流行且性价比较高,于是大家可选择商家变多,但是BlueHost在外贸主机用户群中可选的还是比较多的。这次年中618活动大促来袭,毕竟BLUEHOST商家目前中文公司设立在上海,等后面有机会也过去看看。他们也会根据我们的国内年中促销发...