How to make CRectTracker's m_rect beyond a certain range, such as screen or the scope of a document

Source: Internet
Author: User

Recently in the attempt to make a tool like QQ, one of the functions is to make a selection box, the natural use of CRectTracker

But one of the key things is that when you drag a crecttracker, you can't let CRectTracker "move out" the screen, or there's a black block.

What to do? Searched, and did not find any useful information (may be my search skills too low)

Go to MSDN and look at CRectTracker's documentation, and think of the one method that should be override.

Later pondering a bit, fix, directly override Crecttracker::onchangedrect can, code directly paste below:

CVSCRectTracker.h

1 #pragmaOnce2 3#include <afxext.h>4 5 //Canvas CRectTracker6 classCvscrecttracker:7      PublicCRectTracker8 {9  Public:Ten Cvscrecttracker (Lpcrect lpsrcrect, UINT nstyle); One     /****************************************************** A In order to restrict the tracker ' s rectangle within - The range of the screen . -  the Override This method when the rectangle ' s - device coordinates is beyond the range of - the device (the screen), refuse to make the change. -     ******************************************************/ +     Virtual voidOnchangedrect (Constcrect&rectold); -};

CVSCRectTracker.cpp

1#include"CVSCRectTracker.h"2 3 Cvscrecttracker::cvscrecttracker (Lpcrect lpsrcrect, UINT nstyle): CRectTracker (Lpsrcrect, NStyle)4 {5 }6 7 voidCvscrecttracker::onchangedrect (Constcrect&rectold)8 {9     //Get screen metricsTen LONG Cxscreen (:: GetSystemMetrics (Sm_cxscreen)), Cyscreen (:: GetSystemMetrics (Sm_cyscreen)); One     //If coordinates is out of the screens, reset the rectangle to their last position A     if(M_rect.left <=0|| M_rect.right >=Cxscreen) -M_rect.left = m_rectlast.left, M_rect.right =M_rectlast.right; -     if(M_rect.top <=0|| M_rect.bottom >=Cyscreen) theM_rect.top = m_rectlast.top, M_rect.bottom =M_rectlast.bottom; - Crecttracker::onchangedrect (m_rect); -}

Canvas.cpp

New Cvscrecttracker (&rect, Crecttracker::resizeoutside | CRectTracker::d ottedline);

And how you can use it.

How to make CRectTracker's m_rect beyond a certain range, such as screen or the scope of a document

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.