1
votes

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)?

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;

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;
3

3 Answers

2
votes
case WM_SETCURSOR:
{
    if (LOWORD(lParam) == HTCLIENT)
    {
        SetCursor(NULL);
        return TRUE;
    }

    return DefWindowProc(hWnd, msg, wParam, lParam);
}
1
votes

I think it would be simpler if you just set the cursor for that specific client window to a null cursor.

1
votes

the fix:

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;

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)