用鼠标拖动图片移动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) ;
}
简介华圣云 HuaSaint是阿里云国际版一级分销商(诚招募二级代理),专业为全球企业客户与个人开发者提供阿里云国际版开户注册、认证、充值等服务,通过HuaSaint开通阿里云国际版只需要一个邮箱,不需要PayPal信用卡,不需要买海外电话卡,绝对的零门槛,零风险官方网站:www.huasaint.com企业名:huaSaint Tech Limited阿里云国际版都有什么优势?阿里云国际版的产品...
Contabo自4月份在新加坡增设数据中心以后,这才短短的过去不到3个月,现在同时新增了美国纽约和西雅图数据中心。可见Contabo加速了全球布局,目前可选的数据中心包括:德国本土、美国东部(纽约)、美国西部(西雅图)、美国中部(圣路易斯)和亚洲的新加坡数据中心。为了庆祝美国独立日和新增数据中心,自7月4日开始,购买美国地区的VPS、VDS和独立服务器均免设置费。Contabo是德国的老牌服务商,...
蓝竹云怎么样 蓝竹云好不好蓝竹云是新商家这次给我们带来的 挂机宝25元/年 美国西雅图云服务器 下面是套餐和评测,废话不说直接开干~~蓝竹云官网链接点击打开官网江西上饶挂机宝宿主机配置 2*E5 2696V2 384G 8*1500G SAS RAID10阵列支持Windows sever 2008,Windows sever 2012,Centos 7.6,Debian 10.3,Ubuntu1...