WinApi,将光标隐藏在窗口客户区中 [英] WinApi, hide cursor inside window client area

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

问题描述

我想在没有边框和标题栏的窗口客户区中隐藏光标(它是简单的 opengl 应用程序).所以,函数

I want hide cursor inside window client area without borders and title bar (it is simple opengl application). So, function

    ShowCursor(FALSE);

不合适.在对 winapi 进行一些搜索后,我找到了这个解决方案:

is not suitable. After some searching the winapi i find this solution:

    //when create window class for application window
    WNDCLASSEX WndClass;
    //...
    BYTE CursorMaskAND[] = { 0xFF };
    BYTE CursorMaskXOR[] = { 0x00 };
    WndClass.hCursor = CreateCursor(NULL, 0,0,1,1, CursorMaskAND, CursorMaskXOR);

这是解决这个典型任务的好方法吗?什么方法最好?

Is this a good way to solve this typical task? What way is the best?

推荐答案

MSDN 说您可以将 WNDCLASSEX hCursor 字段设置为 NULL,在这种情况下,您必须在窗口过程中显式设置光标(这意味着处理 WM_SETCURSOR 消息).例如:

MSDN says that you can set the WNDCLASSEX hCursor field to NULL, in which case you must explicitly set the cursor in your window procedure (which means handling the WM_SETCURSOR message). For example:

if (Msg == WM_SETCURSOR && LOWORD(lParam) == HTCLIENT)
{
    SetCursor(NULL);

    return TRUE;
}

// Remainder of window procedure code

检查 HTCLIENT 可确保光标仅隐藏在客户区中,并且窗口框架和标题将使用正确的光标.

Checking for HTCLIENT ensures that the cursor is only hidden in the client area, and that the window frame and caption will use the correct cursors.

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

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