WinApi,将光标隐藏在窗口客户区中

编程入门 行业动态 更新时间:2024-10-26 18:18:06
本文介绍了WinApi,将光标隐藏在窗口客户区中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时送ChatGPT账号..

我想在没有边框和标题栏的窗口客户区中隐藏光标(它是简单的 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屋!

更多推荐

[db:关键词]

本文发布于:2023-04-26 00:38:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1126813.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:光标   区中   窗口   客户   WinApi

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!