Wm_nchittest (process scaling of borderless Windows)

Source: Internet
Author: User

Msdn explains it as follows:

The wm_nchittest message is sent to a window when the cursor moves, or when a mouse button is
Pressed or released. If the mouse is not captured, the message is sent to the window beneath the cursor. Otherwise, the message is sent to the window that has captured the mouse.

This message is sent when you move the mouse or press the mouse key.

What does Windows use this message? "Hittest" indicates "hit test". The wm_nchittest message is used to obtain the current hit position of the mouse.

The message response function of wm_nchittest determines which part of the window the mouse hits based on the current coordinate of the mouse. the return value of the message response function indicates the part. For example, it may return htcaption, or htclient. (There are many return values. Please refer to msdn ).

For ease of understanding, let me first describe the response process for pressing the mouse key in Windows:

1. Determine the window to which the mouse key is clicked. Windows uses a table to record the regional coordinates of each window on the current screen. When the mouse driver notifies windows that the mouse key is pressed, Windows determines which window it is clicked Based on the mouse coordinates.

2. Determine which part of the window is clicked by the mouse key. Windows sends the wm_nchittest message to the mouse key clicking window to ask which part of the window is clicked by the mouse key. (Windows will be notified of the return value of the message response function of wm_nchittest ). Generally, wm_nchittest messages are processed by the system, and users generally do not take the initiative to process them (that is, the wm_nchittest message response function usually uses the Windows Default processing function ).

3. Send the corresponding message to the window based on the mouse key clicked part. For example, if the return value of the message response function of wm_nchittest is htclient, indicating that the user clicks the client area, Windows will send the wm_lbuttondown message to the window; if the return value of the message response function of wm_nchittest is not htclient (probably htcaption, htclose, htmaxbutton, etc.), that is, if you click the non-customer area with the mouse, Windows will send the wm_nclbuttondown message to the window.

The following describes how to use wm_nchittest to scale a borderless window:
Response Message. The message response function is as follows:

Lresult onnchittest (uint/* umsg */, wparam/* wparam */, lparam, bool & bhandled)
{
// This prevents you from zooming the window when maximizing the size (you need to do so without the ws_thickframe style)
If (: iszoomed (m_hwnd ))
{
Return true;
}

Point mousepos;
Mousepos. x = get_x_lparam (lparam );
Mousepos. Y = get_y_lparam (lparam );
: Screentoclient (m_hwnd, & mousepos );

Rect RC;
Int retn = true;
: Getclientrect (m_hwnd, & rc );
Int iwidth = RC. Right-RC. Left;
Int iheight = RC. Bottom-RC. Top;
If (ptinrect (crect (5, 0, iwidth-100, 5), mousepos ))
Retn = httop;
Else if (ptinrect (crect (0, 5, 5, iHeight-5), mousepos ))
Retn = htleft;
Else if (ptinrect (crect (iwidth-5, 25, iwidth, iheight-5), mousepos ))
Retn = htright;
Else if (ptinrect (crect (5, iheight-5, iwidth-5, iheight), mousepos ))
Retn = htbottom;
Else if (ptinrect (crect (0, 0, 5, 5), mousepos ))
Retn = httopleft;
Else if (ptinrect (crect (0, iheight-5, 5, iheight), mousepos ))
Retn = htbottomleft;
Else if (ptinrect (crect (iwidth-5, iheight-5, iwidth, iheight), mousepos ))
Retn = htbottomright;
Return retn;
}

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.