VC++实现在鼠标在打开的图像上拖动

源代码在线查看: 状态栏,鼠标拖动画边框.txt

软件大小: 2 K
上传用户: sgly2002
关键词: 鼠标 图像
下载地址: 免注册下载 普通下载 VIP

相关代码

				void CMultusefulView::OnLButtonDown(UINT nFlags, CPoint point) 
				{
					// TODO: Add your message handler code here and/or call default
				
					CMultusefulDoc* pDoc = GetDocument();
					ASSERT_VALID(pDoc);
				
					m_draging = 1;
					m_dragcretflag = 1;
					m_firstx = point.x;
					m_firsty = point.y;
				
					pDoc->m_Emlx = point.x;
					pDoc->m_Emly = point.y;
				
				//	AddCross(pDoc->img,pDoc->Row,pDoc->Col,point.x,point.y);
						//在状态条上显示图象大小
					char string[100];
					wsprintf(string,"图像:%d行%d列",pDoc->Row,pDoc->Col);
					CStatusBar* pStatusBar=(CStatusBar*)AfxGetMainWnd()->GetDescendantWindow(AFX_IDW_STATUS_BAR);
					pStatusBar->SetPaneText(pStatusBar->CommandToIndex(ID_INDICATOR_IMAGESIZE),LPCSTR(string));
				
							wsprintf(string,"选定位置:X=%d Y=%d",point.x,point.y);
						pStatusBar=(CStatusBar*)AfxGetMainWnd()->GetDescendantWindow(AFX_IDW_STATUS_BAR);
						pStatusBar->SetPaneText(pStatusBar->CommandToIndex(ID_INDICATOR_POINT),LPCSTR(string));
						//状态条上显示选定得位置坐标
					if(point.x < pDoc->Col && point.y < pDoc->Row)
					{
						m_btnPressed = true ; 
						m_startP = point ; 
						wsprintf(string,"灰度:%d",pDoc->img[point.y*pDoc->Col + point.x]);
						pStatusBar=(CStatusBar*)AfxGetMainWnd()->GetDescendantWindow(AFX_IDW_STATUS_BAR);
						pStatusBar->SetPaneText(pStatusBar->CommandToIndex(ID_INDICATOR_GRAY),LPCSTR(string));
					}	
				//	   Invalidate(TRUE);
				
					CScrollView::OnLButtonDown(nFlags, point);
				
				}
				
				
				void CMultusefulView::OnLButtonUp(UINT nFlags, CPoint point) 
				{
					// TODO: Add your message handler code here and/or call default
					if(m_draging)
					{
						m_draging = 0;
						m_dragcretflag = 1;
						m_lastx = point.x;
						m_lasty = point.y;
						ClipCursor(NULL);
					}
				
					m_endP = point ;
					
					if(m_btnPressed)
						m_btnPressed = false; 
				//    Invalidate();
					CScrollView::OnLButtonUp(nFlags, point);
				}
				
				void CMultusefulView::OnMouseMove(UINT nFlags, CPoint point) 
				{
					// TODO: Add your message handler code here and/or call default
				   CMultusefulDoc *pDoc = GetDocument() ; 
				   ASSERT_VALID(pDoc) ;	
				
				   if(point.x>pDoc->Col || point.y>pDoc->Row)
					   return;				// 至关重要!!!!!!!!!
				
						//在状态条上显示鼠标位置
					m_lastx = point.x;
					m_lasty = point.y;
					char string[100];
					wsprintf(string,"鼠标位置:X=%d Y=%d",point.x,point.y);
					CStatusBar* pStatusBar=(CStatusBar*)AfxGetMainWnd()->GetDescendantWindow(AFX_IDW_STATUS_BAR);
					pStatusBar->SetPaneText(pStatusBar->CommandToIndex(ID_INDICATOR_MOUSE),LPCSTR(string));
				//	if(m_draging==1)
				//		Invalidate();
				
					if(m_btnPressed) 
				{ 
				   CDC *pDC = GetDC() ; 
				   CMultusefulDoc *pDoc = GetDocument() ; 
				  ASSERT_VALID(pDoc) ; 
				  m_endP = point ; 
				  rect.SetRect(m_startP,m_endP) ; 
				   pDoc->m_recTk.DrawTrackerRect(&rect,AfxGetMainWnd(),pDC,AfxGetMainWnd()) ; 
				
					wsprintf(string,"所选区域大小:dx=%d dy=%d",abs(rect.right-rect.left),abs(rect.bottom-rect.top));
					pStatusBar=(CStatusBar*)AfxGetMainWnd()->GetDescendantWindow(AFX_IDW_STATUS_BAR);
					pStatusBar->SetPaneText(pStatusBar->CommandToIndex(ID_INDICATOR_RECT),LPCSTR(string));
				/*  	CPen pen(PS_DASH,1,RGB(255,0,0));
					pDC->SelectObject(&pen);
					pDC->Rectangle(rect);
				*/	
				  ReleaseDC(pDC); 
				
				} 
				
					//	CScrollView::OnMouseMove(nFlags, point);
				}
				
				
				
				
				
				
				
				
				
				
				
				
				
				
				
				
				
				
					int m_dragcretflag;		// 画矩形框的标志位
					int m_lasty;	// 选中框结束点坐标
					int m_lastx;
					int m_firsty;	// 选中框起始点坐标
					int m_firstx;
					int m_draging;	// 判断鼠标是否按下
					bool m_btnPressed; 
					CPoint m_endP; 
					CPoint m_startP; 
					CRect rect ; 
				
				
				
				
				
					m_draging = 0;
					m_dragcretflag = 0;		// 画矩形框的标志位
					m_lasty = 0;	// 选中框结束点坐标
					m_lastx = 0;
					m_firsty = 0;	// 选中框起始点坐标
					m_firstx = 0;
					m_btnPressed = false; 
				
				
				
				
							

相关资源