Review of rubber bands

Source: Internet
Author: User

Crecttracker (commonly known as the "rubber band" class) can be used to display boundaries. You can also use its eight corners to zoom in and out, or use it as a box.

Http://dev.csdn.net/htmls/7/7001.html

This blog introduces the usage of this class in detail.

 

To use this class, you must first initialize some of its members:

1. crecttracker: m_rect

Specifies the size of the initialized rectangle.

2. crecttracker: m_nstyle

Description of the rectangular Style

The style is as follows:

  • Crecttracker: solidlineSolid line.
  • Crecttracker: dottedlineDotted Line, which cannot be used together with the solid line.
  • Crecttracker: hatchedborderThe border has a strip line.
  • Crecttracker: resizeinsideDraw lines inside the rectangle.
  • Crecttracker: resizeoutsideDraw a line outside the rectangle.
  • Crecttracker: hatchinsideInternal strip line.

It is an object that can be created in the crecttracker process, such as m_trect; then it is set in the initialization function. The size and style of the initial rectangle are shown in the constructor.

M_trect.m_rect.setrect (100,100,200,200); <br/> m_trect.m_nstyle = crecttracker: resizeinside | crecttracker: solidline;

The remaining two message response functions on the operation interface are:

Afx_msg bool onsetcursor (cwnd * pwnd, uint nhittest, uint message); <br/> afx_msg void onlbuttondown (uint nflags, cpoint point );

 

The onsetcursor function is used to change the shape of the cursor in the m_trect area.

Bool crectview: onsetcursor (cwnd * pwnd, uint nhittest, uint message) <br/>{// todo: add your message handler code here and/or call default <br/> crectdoc * pdoc = getdocument (); <br/> If (pwnd = This & pdoc-> m_recttracker.setcursor (this, nhittest) <br/> return true; <br/> return cview :: onsetcursor (pwnd, nhittest, message); <br/>}

 

Onlbuttondown mainly refers to some actions of the rectangle. Some important functions are:

Crecttracker: normalizehit, which is a regular function that draws a dotted box with the mouse.

Crecttracker: hittest. This function returns the result. The cursor is relative to the position of the rectangle.

Return Value

Meaning

-1

Point outside the Quadrilateral

0

Upper left corner

1

Upper right corner

2

Bottom right corner

3

In the lower left corner (0, 1, 2, 3, and 1 circle clockwise)

4

Top

5

Right

6

Bottom

7

Left (or clockwise)

8

Points inside the Quadrilateral, but does not hit the first eight points

Crecttracker: track. This function will change the size of the rectangle from time to time.

Bool track (cwnd * pwnd, // window object containing a rectangle.
Cpoint point, // The mouse coordinate of the current mouse position relative to the customer area.
Bool ballowinvert = false, // if this parameter is true, the rectangle can be reversed along the X axis or Y axis; otherwise, this parameter is false
Cwnd * pwndclipto = NULL // The window to which the painting operation is to be cut. If this parameter is null, pwnd is used as the clipboard rectangle.
);

 

 

Crecttracker: gettruerect

Void gettruerect (lprect lptruerect) const; used to return the current size and position of m_trect for repainting

Void ccorrectiondlg: onlbuttondown (uint nflags, cpoint point) <br/>{< br/> // todo: add your message handler code here and/or call default <br/> CDC * Dc = This-> getdc (); <br/> assert_valid (DC ); <br/> cbrush * pbrush = cbrush: fromhandle (hbrush) getstockobject (null_brush )); <br/> // transparent paint brush <br/> cbrush * opbrush = Dc-> SelectObject (pbrush); <br/> m_trect.m_rect.normalizerect (); <br/> If (m_trect.hittest (point)> = 0) <br/>{< br/> // pdoc-> m_trect.draw (DC ); <br/> m_trect.track (this, point, true); </P> <p> m_trect.gettruerect (& m_rect [m_counter]); <br/> m_trect.gettruerect (& m_rect_show [m_counter]); <br/> DC-> rectangle (& m_rect_show [m_counter]); <br/>}< br/> invalidate (false); <br/>}</P> <p >}< br/> DC-> SelectObject (opbrush ); <br/> cdialog: onlbuttondown (nflags, point); <br/>}

 

The code below is the code written by the above blog cool

Void crectview: onlbuttondown (uint nflags, cpoint point) <br/>{< br/> // todo: add your message handler code here and/or call default <br/> int Nin; // defines the click value of a mouse. <br/> nin = getdocument () -> m_recttracker.hittest (point); // you can check the position. <br/> If (nin <0) // It is not in the quadrilateral area; <br/>{< br/> crecttracker temp; <br/> temp. trackrubberband (this, point, true); <br/> temp. m_rect.normalizerect (); <br/> crecttracker interrect; <br // Create a crecttracker to record the intersection between the mouse and the ellipse. <Br/> If (interrect. m_rect.intersectrect (temp. m_rect, getdocument ()-> m_recttracker.m_rect) <br/> bdraw = true; // if there is an intersection, draw the boundary of the Quadrilateral, this parameter indicates that an elliptic <br/> else bdraw = false; <br/> invalidate (); // causes the ondraw function to occur; <br/>}< br/> else <br/> // In the quadrilateral area: <br/>{< br/> cclientdc (this ); <br/> getdocument ()-> m_recttracker.draw (& DC); <br/> getdocument ()-> m_recttracker.track (this, point, true ); <br/> // track () is the most popular among crecttracker Charming functions. It always changes the caller's m_rect; <br/> bdraw = true; <br/> invalidate (); <br/>}< br/> cview: onlbuttondown (nflags, point); <br/>}

 

 

Crecttracker: trackrubberband

Bool Trackrubberband ( Cwnd * Pwnd, Cpoint Point, Bool Ballowinvert = True );

Compile and run. When you press the mouse and drag it, you will see the effect.
How can we draw a "rubber band" area with the mouse? The member function in the crecttracker class is: trackrubberband (this, point, true). Note the three parameters:
The first parameter is the pointer to the form of the "rubber band", of course, this
The second parameter draws the starting point of the "rubber band.
The third parameter is very interesting. When you use false (the default value is true), your "rubber band" can only be drawn from the top left to the bottom right, and the reverse direction is not allowed. Compile and run the value false.
It is particularly worth noting that the process of trackrubberband ends with the right-click lift, and no cview mousemove occurs. Remember this 1.1 million!

 

Crecttracker: Draw

Void Draw ( CDC * PDC ) Const;This function will actually draw a rectangle box. If this function is called, m_trect will not be exported. If you only need to draw a rectangle to abuse the internal oval, you can use gettruerect to obtain the area and then draw the Oval. m_trect does not need to be drawn.

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.