1. Base concept and principle on how to use CRectTracker:
Allows an item to be displayed, moved, and resized in different fashions.
--Form MSDN
Example to use this (when you drag the mouse, the RectTracker comes):
1) QQ Snap Desktop picture;
2) Windows explorer;
....
2. Important member funtions of CRectTracker:
SetRect // set the rect of rect tracker
Track // change the position of rect tracker
SetCursor // Change the cursor
HitTest
Draw // draw the rect tracker
Refer MSDN for the Detail.
3. Take an example to show how to use the CRectTracker.
Implement goal show as the follow picture:
Environment VS 2008 Windows XP EN
1) start a MFC dialog based project named tracker
2) Add three member:
CRectTracker m_tracker; // CRectTracker object
CPoint m_start; // the the mouse down, record the start point here
BOOL m_bDraw; // whether draw
3) Add a WM_LBUTTONDOWN handle function(OnLButtonDown)
void
CtrackerDlg::OnLButtonDown(UINT nFlags, CPoint point)
...
{

int nHitTest;
nHitTest = m_tracker.HitTest(point);
if ( nHitTest < 0 ) // if the mouse down point is outside of the rect tracker
...{
m_start = point; // Record the start drawing point
m_bDraw = TRUE; // set m_bDraw (in handle funtion WM_MOUSEMOVE will test this to decide whether to draw)
}
本文介绍了MFC库中CRectTracker类的使用,它用于显示、移动和以不同方式调整矩形大小。通过举例说明如何在鼠标拖动时创建类似QQ截图桌面快照和Windows资源管理器的效果。详细介绍了CRectTracker的重要成员函数,如设置矩形、跟踪位置、更改光标、检测点击和绘制。并提供了在VS2008环境下创建MFC对话框项目并使用CRectTracker的步骤。
最低0.47元/天 解锁文章
2927

被折叠的 条评论
为什么被折叠?



