No pit to hide--mouse messages outside the Capture window (hooks or??) )

Source: Internet
Author: User

Do a Send Expression dialog box, similar to QQ, click on the expression button, pop-up expression box, mouse click on the outside of the expression box, the expression box was killed.

This is the window to get the mouse message outside the window.

Google Baidu, a lot of people say that using hooks to get the window outside of the click event, this is too much fuss about it.

Fortunately, a simple function was found:
setcapture (*this);
function function: This function sets mouse capture in the specified window belonging to the current thread. Once the window captures the mouse, all mouse input is directed at the window, regardless of whether the cursor is within the bounds of the window. Only one window can capture the mouse at a time. If the mouse cursor is on a window created by another thread, the system will only point the mouse input to the specified window when the mouse button is pressed.

So when creating a window, using this function allows the window to get a mouse click message outside the window:

int500;int800;SetWindowPos(*thisNULL, x_position_, y_position_, cx, cy, SWP_FRAMECHANGED);SetCapture(*this);

The next task is simply to get the mouse click position, using the GetCursorPos () function:

function function: The function checks the position of the cursor, expressed in screen coordinates.
Function prototype: BOOL GetCursorPos (Lppoint lppoint);
Parameters:
Ippoint:point The structure pointer that receives the screen coordinates of the cursor.

This allows you to make a judgment in the message queue of this window:

POINT click_point;GetCursorPos(&click_point);if500 > click_point.x && click_point.x > x_position_     800 > click_point.y     && click_point.y> y_position_)    {        MessageBox(NULL"表情", L"没有表情"NULL);    }else    {        //delete 该窗口    }

No pit to hide--mouse messages outside the Capture window (hooks or??) )

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.