Exploration of the dialog box-based MFC Application getwindowrect () and getclientrect ()

Source: Internet
Author: User

Introduction: This is a dialog box-based MFC application.ProgramThe getwindowrect (), getclientrect () Details page describes PHP, related knowledge, skills, experience, and some PHP source code.

Class = 'pingjiaf' frameborder = '0' src = 'HTTP: // biancheng.dnbc?info/pingjia.php? Id = 338283 'rolling = 'no'>

Create a dialog box-based MFC Application and place a static text control m_plot on the dialog box.

Use m_rectoldwindow variable to save the dialog box rect, and use m_rectoldplotwindow to save the static text control rect

Add the following test in oninitdialog ()Code

 
Getwindowrect (& m_rectoldwindow );
Screentoclient (& m_rectoldwindow );
Getclientrect (& m_rectoldwindow );
Clienttoscreen (& m_rectoldwindow );

M_plot.getclientrect (& m_rectoldplotwindow );
Clienttoscreen (& m_rectoldplotwindow );
M_plot.getwindowrect (& m_rectoldplotwindow );
Screentoclient (& m_rectoldplotwindow );

View variable values during debugging

First getwindowrect (& m_rectoldwindow );

+ & M_rectoldwindow0x002cfcd4 {Top = 0 Bottom = 388 left = 0 right = 576} crect *

Screentoclient (& m_rectoldwindow );

+ & M_rectoldwindow0x002cfcd4 {Top =-30 Bottom = 358 left =-8 Right = 568} crect *

Third sentence getclientrect (& m_rectoldwindow );

+ & M_rectoldwindow0x002cfcd4 {Top = 0 Bottom = 350 left = 0 right = 560} crect *

Fourth sentence clienttoscreen (& m_rectoldwindow );

+ & M_rectoldwindow0x002cfcd4 {Top = 30 Bottom = 380 left = 8 Right = 568} crect *

Fifth sentence m_plot.getclientrect (& m_rectoldplotwindow );

+ & M_rectoldplotwindow0x002cfcc4 {Top = 0 Bottom = 255 left = 0 right = 532} crect *

Sentence 6: clienttoscreen (& m_rectoldplotwindow );

+ & M_rectoldplotwindow0x002cfcc4 {Top = 30 Bottom = 285 left = 8 Right = 540} crect *

Sentence 7: m_plot.getwindowrect (& m_rectoldplotwindow );

+ & M_rectoldplotwindow0x0023f7dc {Top = 42 Bottom = 301 left = 20 right = 556} crect *

Sentence 8: screentoclient (& m_rectoldplotwindow );

+ & M_rectoldplotwindow0x0023f7dc {Top = 12 Bottom = 271 left = 12 Right = 548} crect *

I used to check information online, and it was a mess. Many of them answered questions if they didn't test them ~

Practice is the only criterion for testing truth ~ En ~

Brief Analysis:

Originally, what I thought the first getwindowrect clause should be the rect of the dialog box window relative to the screen coordinate. The result can be seen from the following values.

Neither of these four functions involves the conversion of window coordinates and screen coordinates.

Getwindowrect obtains the rect of the customer and non-customer areas in the dialog box. The non-customer area is the green and border section in the title section of XP, And the translucent section under win7.

The coordinate origin is in the upper left corner of the window.

Why does screentoclient obtain a negative value? Because the client is the customer zone, the coordinate origin is in the upper left corner of the customer zone, and the upper left corner of the window is more left than the upper left corner of the customer zone, so a negative number is displayed.

Getclientrect: Get the rect of the window customer area. The coordinate origin is in the upper left corner of the customer area, and the data of the first and third rows is subtracted, 388-350 = 30 + 8; 576-560 = 2*8;

The coordinate origin of clienttoscreen is changed to the upper left corner of the entire window, which is translated () from the customer's origin. The coordinate conversion is completed by everyone in high school.

M_plot.getclientrect uses the upper-left corner of the static control as the origin to obtain the rect of the static control. Right indicates the width, and bottom indicates the height.

I am wondering about clienttoscreen. Does it belong to Microsoft?AlgorithmIs it a translation )? The upper left corner of my control is not in the upper left corner of the customer area.

M_plot.getwindowrect uses the upper-left corner of the window as the origin to obtain the rect of the control.

Screentoclient uses the upper-left corner of the customer zone as the origin point to obtain the rect of the control. The upper-left corner of the control is shifted to the upper-left corner of the customer zone (12, 12 ).

Not over yet ::

Override control onpaint

Add

 
Getwindowrect (& rect );
Screentoclient (& rect );
Getclientrect (& rect );
Clienttoscreen (& rect );

Getwindowrect (& rect );

+ & Rect0x0029f348 {Top = 233 Bottom = 492 left = 372 right = 908} crect *

Screentoclient (& rect );

+ & Rect0x0029f348 {Top =-2 Bottom = 257 left =-2 right = 534} crect *

Getclientrect (& rect );

+ & Rect0x0029f348 {Top = 0 Bottom = 255 left = 0 right = 532} crect *

Clienttoscreen (& rect );

+ & Rect0x0029f348 {Top = 235 Bottom = 490 left = 374 right = 906} crect *

Something amazing happened!

I still remember the previous sentence. None of the four functions involved the conversion of window coordinates and screen coordinates.

Practice overturned my theory

Why? Why? Why?

In the dialog box, call getwindowrec, m_plot.getwindowrect

Why is the difference between calling getwindowrec in controls so great?

Getwindowrec in the control takes the upper left corner of the screen as the origin! Who can tell me why?

Screentoclient (& rect); more outrageous ~! -2 is the translation relative to the coordinate origin?

The third clause getclientrect (& rect); finally, it is normal, it is the expected result, get the rect with the control's upper left corner as the origin

In the fourth sentence, clienttoscreen (& rect) is rewritten to calculate the rect at the origin point in the upper left corner of the screen. But why is the difference between the two pixels obtained in the first sentence? And the two pixels are exactly

2 pixels come out of the second sentence!

Ask for resolution by passing...

Love J2EE follow Java Michael Jackson video station JSON online tools

http://biancheng.dnbcw.info/php/338283.html pageno: 9

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.