如何从程序窗口之外获取鼠标事件 [英] How to get mouse events from outside of program window

查看:369
本文介绍了如何从程序窗口之外获取鼠标事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想拖动这个角色.图片:

I want to drag this character. Image :

所以我使用这种方法来获取鼠标位置:

so i use this method to get mouse position:

WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
    ...
    switch (message){
    case WM_LBUTTONDOWN:
    case WM_MOUSEMOVE:
        GetCursorPos(&mousePosition);
        break;
    }
    ...
}

该程序似乎运行良好,但是如果鼠标不在字符位置,它将不再跟随鼠标光标.

The program seems to be running well, but if the mouse is out of the characters location, it wouldn't follow the mouse cursor anymore.

如何解决此问题?

推荐答案

请参见 SetCapture :

将鼠标捕获设置为属于当前线程的指定窗口. SetCapture 捕获鼠标输入是在鼠标悬停在捕获窗口上方时,还是在鼠标悬停在捕获窗口上方且按钮仍处于按下状态时按下鼠标按钮.一次只能捕获一个窗口.

Sets the mouse capture to the specified window belonging to the current thread. SetCapture captures mouse input either when the mouse is over the capturing window, or when the mouse button was pressed while the mouse was over the capturing window and the button is still down. Only one window at a time can capture the mouse.

SetCapture .. ReleaseCapture使您可以暂时将鼠标事件处理扩展到窗口外部(事件起源于此)的空间.

SetCapture..ReleaseCapture lets you temporarily extend your mouse event handling to space outside the window [where the event originated from].

您有一些示例/演示 查看全文

登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆