Window movement, changing the size of the message

Source: Internet
Author: User

window movement, changing the size of the messagethe four messages that will be mentioned are: Wm_move, wm_size, Wm_activate, WM_PAINT.

The first two are very simple. The Wm_move message is sent when the window is moved by the user, and the coordinates of the new location of the window are stored in lparam. (Messages are further described in lparam and wparam, which are parameters of the message control function) lparam The lower-end word stores the coordinates x in the upper-left corner of the client area of the window, storing the coordinate y in the high-end word.
When the size of the window is changed, the wm_size message is sent. Similar to the WM_MOVE message, LPARAM's low-end word stores the width of the customer area, high-end word storage height. Unlike Wm_move, the wparam parameter also controls some important things. It can be any of the following values:

   Size_maxhide: The other windows are maximized.

※size_maximized: This window has been maximized.

※size_maxshow: The other windows have been restored.

※size_minimized: This window has been minimized.

※size_restored: The window has been changed in size, but neither maximized nor minimized.

When you write a window instance, you can keep the current position and size of the window in several global variables. Assuming that we name these global variables xpos,ypos,xsize and ysize, it is best to control the two messages wm_size and Wm_move:

if (msg = = wm_size)
{
Xsize = LOWORD (lparam);
Ysize = HiWord (lparam);
}
if (msg = = Wm_move)
{
XPos = LOWORD (lparam);
YPos = HiWord (lparam);
}

The wm_activate message tells you that a new window is activated. This is useful because if you have a priority application, you will not be able to handle all the logic in the program. Sometimes, such as writing a full-screen DirectX program, ignoring the wm_activate message will cause your program to have a fatal error, possibly it does something you do not want it to do. In any case, it is a good idea to wait for wm_activate messages to take action.

The wm_activate message is emitted when the window is activated and deactivated, and we can detect whether the wparam is activated or canceled by detecting the low-end word. This will have three possible values:

※wa_clickactive: The window is activated by the mouse.

※wa_active: Window is activated by something else. (keyboard, function call, etc.)

※wa_inactive: The window is deactivated.

In order to handle this message, I keep another global variable bfocus, and when the Wm_activate message is received, its value will change. Examples are as follows:

if (msg = = wm_activate)
{
if (LoWord (wparam) = = wa_inactive)
Focus = FALSE;
Else
Focus = TRUE;
Tell Windows we handled it
return (0);
}


There are two associated messages wm_killfocus and Wm_setfocus, when the window receives the input focus, the Windows message Wm_setfocus is sent to it, and the Wm_killfocus message is sent when the focus is lost. Applications can intercept these messages to learn about any changes in the input focus. What is the input focus? The Application (window) that has the input focus is the window that is activated. You think the activated window is just the input focus. Because there may be no window with input focus, I recommend that you keep track of your window state with wm_activate messages. (Some Hu tu?) It doesn't matter, you just remember to do it with wm_activate) down the line.

Related Article

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.