Client window coordinates

Source: Internet
Author: User

GetClientRect (HWND, rect*)---Get the client area size of the window, Left,top always 0,bottom is the client area height, right is the customer area width

GetWindowRect (HWND, rect*)---Coordinates of the window relative to the upper-left corner of the screen (0,0), that is, the upper-left corner of the window (left,top) and the lower-right corner (Right,bottom)

ScreenToClient (HWND, point*)---coordinates a screen coordinate to the upper- left corner of the client area of the window. Suppose client area screen coordinates (110,120, 400,400)
If P (100,100), then P (-10, -20) after conversion
If P (150,150), then P (40, 30) after conversion

ClientToScreen (HWND, point*)---Convert a coordinate that is relative to the upper -left corner of the window client area (always assumed) to screen coordinates. Suppose client area screen coordinates (110,120, 400,400)
If P (5, 5), then P (115,125) after conversion
If P (10,-20), then P (120,100) after conversion;

Windows does not provide a function to directly convert client area RECT coordinates/screen rect coordinates, but the CWindow class in MFC provides ClientToScreen (rect*) and screentoclient (rect*) functions.                                                
For example, when using ClientToScreen (Rect *PRC), the incoming RECT coordinates are assumed to be relative to the upper-left corner of the client area, assuming the client area screen coordinates ( 110,120 , 400,400)
If RC (2,2,4,4), the converted RC (112,122,114,124)
RC ( -5,-5,0,0), after the converted RC (105,115,110,120)
if RC (0,0,290,280), the converted RC (1 10,120,400,400)  >--->------->-------> This example is commonly used to obtain the coordinates of the client area relative to the screen origin:

RECT rcclient; GetClientRect (///0 0 width / /// client area upper left and bottom right screen coordinates /  * very common, But don't be mistaken that ClientToScreen's role is limited to this *  /

Similarly, when screentoclient (rect *PRC) is used, the incoming RECT coordinates are assumed to be screen coordinates, assuming the client area screen coordinates (110,120, 400,400)
If RC (150,150,160,160), the converted RC (40,30,50,40)
If RC (100,100,120,120), the converted RC ( -10,-20,10,0)
If RC (110,120,400,400), the converted RC (0,0,290,280)

Offsetrect (rect*, int dx, int dy)---Move the rectangle from the senses: The DX is positive, the right shift is negative, then the left shift, the DY is positive, the move down, is negative, moves up. If RC (100,100,150,150)
Dx=0,dy=1, the converted RC (100,101,150,151)
DX=-50,DY=-10, the converted RC (50,90,100,140)
Use 1: Turn the window relative to screen coordinates to the upper-left corner of the relative window (that is, 0 0 width high)

RECT Rc;::getwindowrect (hwnd,  &RC);:: Offsetrect (&RC,-rc.left,-rc.top); / * Of course You can also rc.right-= rc.left;rc.bottom-= Rc.top;rc.left = Rc.top = 0; */

Use 2: Calculates the coordinates of the client area relative to the upper-left corner of the window

// MFC under RECT RC, rcclient; GetWindowRect (&RC); // screen coordinates of the window GetClientRect (&rcclient); ClientToScreen (&rcclient); // screen coordinates of the client area :: Offsetrect (&rcclient,-rc.left,-rc.top); // the coordinates of the client area relative to the upper-left corner of the window

 

Client window coordinates

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.