画图程序中,如何实现橡皮筋效果????
在画图程序中,例如要画一个矩形,当鼠标移动时,屏幕显示一个虚线的矩形跟随鼠标移动,当鼠标停止,左键弹起时,虚线消失. 问题点数: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




