Http://topic.csdn.net/u/20080625/13/cf92a220-d2a9-4f05-ae53-7acce4dd84dc.html
O (success _ success) O... Thank you.
At first, I did what you said. If I didn't succeed, you said, "These two sentences are superfluous .." Let me remove all your rect statements.
Okay, let's close the post. Thank you, but I have to clarify the problem solution first:
Step 1: add the Class header file
Crecttracker m_tracker;
Crect m_recttrack; // at that time, only the mxm324 renxiong said that the two sentences can be avoided. The key is "rect is a member variable" ==!
Step 2: Initialize In the constructor
Ctrackerview: ctrackerview ()
{
M_recttracker.setrect (100,100,200,200); // initialization size
M_tracker.m_nstyle = crecttracker: solidline inclucrecttracker: resizeinside; // you can specify a border style.
}
Step 3: draw it in the ondraw Function
Void ctrackerview: ondraw (CDC * PDC)
{
Ctrackerdoc * pdoc = getdocument ();
Assert_valid (pdoc );
If (! Pdoc)
Return;
Cbrush brush (RGB (192,192,192 ));
PDC-> SelectObject (& brush );
/////////// Mxm324 the following two sentences can be commented out, but I found that,
/// // The second sentence is required. Otherwise, the rectangle cannot be drawn.
PDC-> rectangle (m_recttracker );
M_tracker.m_rect = m_recttracker;
PDC-> lptodp (& m_tracker.m_rect );
M_tracker.draw (PDC );
}
Step 4: Change the onlbuttondown Function
Void ctrackerview: onlbuttondown (uint nflags, cpoint point)
{
Cclientdc DC (this );
M_tracker.track (this, point );
M_recttracker = m_tracker.m_rect;
Onpreparedc (& DC );
DC. dptolp (& m_recttracker );
This-> invalidate (true );
Cscrollview: onlbuttondown (nflags, point );
}
Step 5: Set the cursor
Bool ctrackerview: onsetcursor (cwnd * pwnd, uint nhittest, uint message)
{
If (pwnd = This & m_tracker.setcursor (this, nhittest) // Changes the cursor when the cursor enters the box range.
Return true;
Return cscrollview: onsetcursor (pwnd, nhittest, message );
}