将鼠标光标隐藏在 Windows 中的特定客户区上 [英] hide mouse cursor over specific client area in windows

查看:49
本文介绍了将鼠标光标隐藏在 Windows 中的特定客户区上的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将 Directx 嵌入到我的应用程序的子窗口中,并希望仅在它位于该客户区上方时隐藏窗口光标.我知道如何在一般情况下隐藏光标,并且确实设法找到了一个临时示例,如果只在光标不在任何客户区域上方时显示它,但这对此没有帮助.如何仅在光标位于特定客户区(/子窗口)上方时隐藏光标?

I have directx embedded into a child window of my application and would like to hide the windows cursor only when it's over that client area. I know how to hide the cursor in general and did manage to find a make-shift example if only showing the cursor while it's not over any client areas, but it wasn't helpful for this. How can I hide the cursor only while it's over a specific client area (/child window)?

这与我得到的一样接近,但光标在 dx 区域上方不可预测地闪烁(随着鼠标移动)

edit: this is as close as I've gotten but the cursor flickers unpredictably (as the mouse moves) while over the dx area

case WM_SETCURSOR:
{
    static bool bCursorVisible = TRUE;

    if( hWnd!=hwD3DArea && !bCursorVisible )
    {
        ShowCursor((bCursorVisible=TRUE));
    }
    else if( hWnd==hwD3DArea && bCursorVisible )
    {
        ShowCursor((bCursorVisible=FALSE));
        return TRUE;
    }
}
break;

啊啊!您必须在此消息中使用 wParam 而不是 hWnd这是工作代码:

edit2: AHAH! you have to use wParam instead of hWnd in this message Here's the working code:

case WM_SETCURSOR:
{
    static bool bCursorVisible = TRUE;

    if( ((HWND)wParam)!=hwD3DArea && !bCursorVisible )
    {
        ShowCursor((bCursorVisible=TRUE));
    }
    else if( ((HWND)wParam)==hwD3DArea && bCursorVisible )
    {
        ShowCursor((bCursorVisible=FALSE));
        return TRUE;
    }
}
break;

推荐答案

修复:

case WM_SETCURSOR:
        {
            static bool bCursorVisible = TRUE;
            if( ((HWND)wParam)!=hwD3DArea && !bCursorVisible )
            {
                ShowCursor((bCursorVisible=TRUE));
            }
            else if( ((HWND)wParam)==hwD3DArea && bCursorVisible )
            {
                ShowCursor((bCursorVisible=FALSE));
                return TRUE;
            }
        }
        break;

我在正确的轨道上,但在我应该使用 wParam(它保存光标所在窗口的真实句柄)时使用了 hWnd

I was on the right track but was using hWnd when I should have been using wParam (which holds the REAL handle of the window the cursor is in)

这篇关于将鼠标光标隐藏在 Windows 中的特定客户区上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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