CSDN首页 空间 新闻 论坛 Blog 下载 读书 网摘 搜索 .NET Java 视频 接项目 求职 在线学习 买书 程序员 通知
IBM Rational 系统开发最佳实践工具包 WebSphere MQ 最佳实践 TOP 15
CSDN社区
搜索 收藏 打印 关闭
CSDN社区 >  VC/MFC >  基础类

画图程序中,如何实现橡皮筋效果????

楼主ztl_1208(流星)2006-03-18 09:39:41 在 VC/MFC / 基础类 提问

在画图程序中,例如要画一个矩形,当鼠标移动时,屏幕显示一个虚线的矩形跟随鼠标移动,当鼠标停止,左键弹起时,虚线消失. 问题点数:20、回复次数:11Top

1 楼vcmute(BCare4 H1Rest Good9!)回复于 2006-03-18 10:09:41 得分 0

这个叫TrackerTop

2 楼vcmute(BCare4 H1Rest Good9!)回复于 2006-03-18 10:10:14 得分 5

CRectTracker   Class   Members  
  Data   Members  
   
  m_nHandleSize   Determines   size   of   resize   handles.    
  m_rect   Current   position   (in   pixels)   of   the   rectangle.    
  m_sizeMin   Determines   minimum   rectangle   width   and   height.    
  m_nStyle   Current   style(s)   of   the   tracker.    
   
   
  Construction  
   
  CRectTracker   Constructs   a   CRectTracker   object.    
   
   
  Operations  
   
  Draw   Renders   the   rectangle.    
  GetTrueRect   Returns   width   and   height   of   rectangle,   including   resize   handles.    
  HitTest   Returns   the   current   position   of   the   cursor   related   to   the   CRectTracker   object.    
  NormalizeHit   Normalizes   a   hit-test   code.    
  SetCursor   Sets   the   cursor,   depending   on   its   position   over   the   rectangle.    
  Track   Allows   the   user   to   manipulate   the   rectangle.    
  TrackRubberBand   Allows   the   user   to   “rubber-band”   the   selection.    
   
   
  Overridables  
   
  AdjustRect   Called   when   the   rectangle   is   resized.    
  DrawTrackerRect   Called   when   drawing   the   border   of   a   CRectTracker   object.    
  OnChangedRect   Called   when   the   rectangle   has   been   resized   or   moved.    
  GetHandleMask   Called   to   get   the   mask   of   a   CRectTracker   item’s   resize   handles.    
  Top

3 楼vcmute(BCare4 H1Rest Good9!)回复于 2006-03-18 10:11:03 得分 0

TRACKER:   Illustrates   Various   CRectTracker   Styles   and   Options  
  Click   to   open   or   copy   the   TRACKER   project   files.  
   
  The   TRACKER   sample   is   a   test   application   that   provides   an   exhaustive   illustration   of   CRectTracker   member   functions,   styles,   and   options.   For   a   real-world   example   that   uses   CRectTracker,   see   DRAWCLI,   the   object-oriented   drawing   sample   application.  
   
  TRACKER   initially   displays   a   square   with   four   colored   and   numbered   quadrants.   The   quadrants   are   displayed   to   help   you   see   when   the   square   is   inverted   horizontally   and/or   vertically.   Initially,   the   square   has   no   CRectTracker   adornments.   Try   the   various   toolbar   commands,   or   Edit   menu   commands,   to   turn   on   and   off   CRectTracker   styles,   including   dotted   or   solid   lines;   hatched   border,   inside   or   outside   the   rectangle;   and   resize   handles,   inside   or   outside   the   rectangle.  
   
  Notice   how   the   cursor   changes   shape   over   parts   of   the   rectangle   to   indicate   what   happens   if   you   drag   the   mouse.   Try   moving   and   resizing   the   rectangle.  
  Top

4 楼XXKKFF(齐次边界条件有界弦自由振动方程混合问题的分离变量法-_-!!!)回复于 2006-03-18 10:18:49 得分 10

OnLButtonDown(UINT   nFlags,   CPoint   point)    
  {  
  CClientDC   ClientDC(this);  
  OnPrepareDC(&ClientDC);  
  ClientDC.DPtoLP(&point);  
   
  m_PointOrigin=point;  
  m_PointOld=point;  
  m_Dragging=1;  
   
  CScrollView::OnLButtonDown(nFlags,   point);  
  }  
   
  void   OnLButtonUp(UINT   nFlags,   CPoint   point)    
  {  
  if(m_Dragging){  
  m_Dragging=0;  
  CClientDC   ClientDC(this);  
   
  OnPrepareDC(&ClientDC);  
  ClientDC.DPtoLP(&point);  
   
  ClientDC.SetROP2(R2_NOT);  
  ClientDC.MoveTo(m_PointOrigin);  
  ClientDC.LineTo(m_PointOld);  
  ClientDC.SetROP2(R2_COPYPEN);  
  ClientDC.MoveTo(m_PointOrigin);  
  ClientDC.LineTo(point);  
  }  
  CScrollView::OnLButtonUp(nFlags,   point);  
  }  
   
  void   OnMouseMove(UINT   nFlags,   CPoint   point)    
  {  
  CClientDC   ClientDC(this);//设备描述表  
  OnPrepareDC(&ClientDC);  
  ClientDC.DPtoLP(&point);  
   
  if(m_Dragging){  
  CClientDC   ClientDC(this);//设备描述表  
   
  OnPrepareDC(&ClientDC);  
  ClientDC.DPtoLP(&point);  
   
  ClientDC.SetROP2(R2_NOT);//生成逆转当前屏幕颜色来画线的绘图方式以擦去之前画的线  
  ClientDC.MoveTo(m_PointOrigin);//画线  
  ClientDC.LineTo(m_PointOld);  
  ClientDC.MoveTo(m_PointOrigin);  
  ClientDC.LineTo(point);  
  m_PointOld=point;  
  }  
   
  OnMouseMove(nFlags,   point);  
  }  
   
  这是画线的,画矩形只要Rectangle就行了,稍微改一下Top

5 楼teli_eurydice(哭泣的仙人掌。。。。)回复于 2006-03-18 11:53:23 得分 0

CRectTrackerTop

6 楼ruoruo1982(弱弱)回复于 2006-03-18 13:54:36 得分 2

楼上说的对,  
  用CRectTracker::TrackRubberBand();  
  例子如下:  
  void   CMyView::OnLButtonDown(UINT   nFlags,   CPoint   point)    
  {  
     
              CRectTracker     temp;  
              temp.TrackRubberBand(this,point,TRUE);  
              temp.m_rect.NormalizeRect();  
              CRectTracker   interRect;    
              Invalidate();   //引起OnDraw函数的发生;  
              }Top

7 楼gzlyb(冰风)回复于 2006-03-18 14:36:51 得分 2

在windows程序设计中也有一个用API实现的例子Top

8 楼ydfivy(我就是一送外卖的)回复于 2006-03-18 14:43:27 得分 1

CRectTracker这个就可以了.  
   
  Top

9 楼ruoruo1982(弱弱)回复于 2006-03-18 15:01:56 得分 0

我要得分了~~~~~~~~Top

10 楼ztl_1208(流星)回复于 2006-03-18 18:19:40 得分 0

这个好象只能实现画矩形,那又如何实现画直线呢?Top

11 楼ztl_1208(流星)回复于 2006-03-18 18:20:16 得分 0

椭圆等等Top

相关问题

  • 画图中实现橡皮筋功能,大虾帮忙找找毛病
  • 画图程序出错
  • 本人欲求计算机画图中的橡皮筋技术画线例程,请大家指教并加相关注释,先帖出代码都得分.
  • 我使用CRectTracker来画橡皮筋程序,但是主窗口的lbuttonup并屏蔽了
  • 橡皮筋画线
  • 一个画图程序的问题.......
  • 如何外挂画图程序?
  • 寻画图程序源码,谢谢
  • 谁能给我一个画图程序?
  • 谁教我做画图程序?

关键词

  • 矩形
  • 鼠标
  • crecttracker
  • rectangle
  • 实现
  • position
  • current

得分解答快速导航

  • 帖主:ztl_1208
  • vcmute
  • XXKKFF
  • ruoruo1982
  • gzlyb
  • ydfivy

相关链接

  • Visual C++类图书
  • Visual C++类源码下载

广告也精彩

反馈

请通过下述方式给我们反馈
反馈
提问
网站简介|广告服务|VIP资费标准|银行汇款帐号|网站地图|帮助|联系方式|诚聘英才|English|问题报告
北京创新乐知广告有限公司 版权所有, 京 ICP 证 070598 号
世纪乐知(北京)网络技术有限公司 提供技术支持
Copyright © 2000-2008, CSDN.NET, All Rights Reserved
GongshangLogo