- //在Single09View.h里声明变量
- public:
- POINT lastPos;
- POINT m_top;
- / 在Single09View.cpp里加入下面代码
- CSingle09View::CSingle09View()
- {
- // TODO: add construction code here
- m_top.x = 0;
- m_top.y = 0;
- }
- void CSingle09View::OnDraw(CDC* pDC)
- {
- CSingle09Doc* pDoc = GetDocument();
- ASSERT_VALID(pDoc);
- // TODO: add draw code for native data here
- CBitmap bmp;
- bmp.LoadBitmap(IDB_BITMAP1);
- BITMAP bm;
- bmp.GetBitmap(&bm);
- int nWidth=bm.bmWidth,nHeight=bm.bmHeight;
- CDC MemDC;
- MemDC.CreateCompatibleDC(pDC);
- CBitmap* pOldBmp = MemDC.SelectObject(&bmp);
- pDC->BitBlt(m_top.x,m_top.y,nWidth,nHeight,&MemDC,0,0,SRCCOPY);
- MemDC.SelectObject(pOldBmp);
- }
- void CSingle09View::OnLButtonDown(UINT nFlags, CPoint point)
- {
- // TODO: Add your message handler code here and/or call default
- lastPos.x = point.x;
- lastPos.y = point.y;
- CView::OnLButtonDown(nFlags, point);
- }
- void CSingle09View::OnMouseMove(UINT nFlags, CPoint point)
- {
- // TODO: Add your message handler code here and/or call default
- if((nFlags&MK_LBUTTON)!=0)
- {
- m_top.x = m_top.x+point.x-lastPos.x;
- m_top.y = m_top.y+point.y-lastPos.y;
- lastPos.x = point.x;
- lastPos.y = point.y;
- this->Invalidate();
- }
- CView::OnMouseMove(nFlags, point);
- }
vc 在单文档中拖动图片的方法
最新推荐文章于 2020-12-28 01:09:12 发布