Determine the actual user zone issues in the window

Source: Internet
Author: User

1. The two coordinate attributes of rect are different from those of indexes.

A window with a width of 400 and a length of 300 at in the upper left corner. Its rect is {400,300, 399,299} Instead }, because the width from 0 to 399 on the X axis is 399 instead of 400.

Why does this problem occur, because when you send any rect structure to most DirectDraw functions, it generally contains the upper left corner, but not the lower right corner. This is an independent problem, but it is easy to create conceptual confusion when used in the same scenario.

 

2. Adjust the window to the correct user area

If the user area you want is 400*300, but the 400,300 window created using createmediawex contains not only the user area, but also the title bar, menu, border, and so on, therefore, you need to adjust the size of the window after creating the window to make the user area as expected.

The following code assumes that you want the upper-left corner of the window to be at 0, 0. If the upper-left corner remains the same, adjust the window size to screen_width * screen_height.

Rect window_rect = {0, screen_width, screen_height}; <br/> adjustwindowrectex (& window_rect, <br/> getwindowstyle (main_window_handle), <br/> getmenu (main_window_handle )! = NULL, <br/> getjavaswexstyle (main_window_handle); <br/> border =-window_rect.left; <br/> Title =-window_rect.top; </P> <p> movewindow (main_window_handle, 0, window_rect.right-window_rect.left, <br/> window_rect.bottom-window_rect.top, false );

 

3. When the window is moved by the user, the correct user area can still be located.

On the top, we calculated the left and right sides of the window (Here we only consider the simplest case to illustrate, when the window has more controls, we should modify the algorithm as appropriate ).

Border =-window_rect.left;
Title =-window_rect.top;

With this data, you can still locate the user area after moving the window. The following code locates user_rect and executes BLT on the main surface:

Rect window_rect; <br/> getwindowrect (main_window_handle, & window_rect); </P> <p> rect dest_rect; <br/> dest_rect.left = window_rect.left + border; <br/> dest_rect.top = window_rect.top + title; <br/> dest_rect.right = window_rect.right-border; <br/> dest_rect.bottom = window_rect.bottom-border; </P> <p> If (failed (lpddsprimary-> BLT (& dest_rect, lpddsbackground, null, ddblt_wait, null) <br/> return 0;

 

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.