MoveWindow () SetWindowPos () differs from the contact _c language

Source: Internet
Author: User

Knock code, suddenly found that there is a background picture can not be displayed, baffled, and finally found that MoveWindow () SetWindowPos () The two functions of improper use of the resulting.

Here the two functions of the past and present life to analyze.

First look at the MoveWindow () function, used to change the position and size of the window, for the top-level window, according to the screen alignment and the upper left corner, for the child window, then align to the upper left corner of the parent window.

BOOL MoveWindow (HWND hwnd,int x, int y, int nwidth, int nheight,bool brepaint = TRUE);

The first represents a window handle;

The parameter x,y represents the starting point of the upper-left corner of the window;

The parameter nwidth,nheight indicates the height and width of the window;

The last brepaint indicates whether to redraw immediately. When True, the system immediately sends the WM_PAINT to the window program (the UpdateWindow () function is invoked), and false does not occur with any type of redraw operation.

MoveWindow will send wm_windowposchanging,wm_windowposchanged,wm_move,wm_size and wm_nccalcsize messages to the window.

Next look at SetWindowPos (), this function is also used to implement the window movement operation, but more functions.

BOOL SetWindowPos (HWND hwnd,const cwnd* pwndinsertafter, int x, int y,int cx, int cy, UINT nflags);

The first argument is the window handle;

The second parameter is the z Order of the window, when there are more than one window, the sequence shown in this window, top or bottom, optional parameters are hwnd_bottom,hwnd_notopmost,hwnd_top,hwnd_topmost.

Hwnd_bottom: Place the window at the bottom of the z-order. If the parameter HWND identifies a top-level window, the window loses its top-level position and is positioned at the bottom of the other window.
Hwnd_notopmost: Place the window above all non-top-level windows (that is, after all the top-level windows). If the window is already a non top-level window, the flag does not work.
Hwnd_top: Place the window at the top of the z-order.
Hwnd_topmost: Place the window above all non-top-level windows. The window remains at the top level even if the window is not activated.

The next four parameters are the position and size of the window.

The last parameter nflags is the window display way of the flag, this parameter many, can combine use, detailed as follows:

Swp_asncwindowpos: If the calling process does not own a window, the system sends a demand to the thread that owns the window. This prevents the calling thread from deadlock when other threads handle the requirement.
Swp_defererase: Prevents wm_syncpaint messages from being generated.
Swp_drawframe: Draw a border around the window (defined in the window class description).
Swp_framechanged: Sends a WM_NCCALCSIZE message to the window, even if the window size does not change. If this flag is not specified, the wm_nccalcsize is sent only if the window size is changed.
Swp_hidewindow, hiding windows.
Swp_noactivate: Does not activate the window. If no flag is set, the window is activated and is set to the top of the other top-level window or non-top-level group (set according to the parameter hwndlnsertafter).
Swp_nocopybits: Clears all content from the client area. If this flag is not set, the active content of the client area is saved and copied back to the client area after the window size is updated and relocated.
Swp_nomove: Maintain the current position (ignoring the x and Y parameters).
Swp_noownerzorder: Does not change the position of the owner window in the z-order.
Swp_noredraw: does not redraw the changed content. If this flag is set, no repaint action occurs. Applies to client and non-customer areas, including title bars and scrollbars, and to any part of the parent window that is exposed by window back movement. If this flag is set, the application must explicitly invalidate the window and draw any part of the window and the part that the parent window needs to repaint.
Swp_noreposition the same as the Swp_noownerzorder sign.
Swp_nosendchanging: Prevents Windows from receiving wm_windowposchanging messages.
Swp_nosize: Maintain the current size (ignoring the CX and CY parameters).
Swp_nozorder: Maintains the current z-order (ignoring the hwndlnsertafter parameter).
Swp_showwindow: Displays the window.

  Precautions:

With SetWindowPos () if the swp_showwindows or Swp_hidewindow is set, the window will not be moved and resized, and I am using it to set the Swp_showwindow so that the background cannot be redrawn.

  Comparison between the two:

Both can move and change the window size.

MoveWindow () features a single, can only move and change the window size, and SetWindowPos () can set more parameters to achieve ZOrder and display mode flag.

MoveWindow () Send messages such as Wm_windowposchanging,wm_windowposchanged,wm_move,wm_size and wm_nccalcsize to Windows, SetWindowPos () send only WM _windowposchanged Message to window. So it's good to use MoveWindow () if you need to send more messages.

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.