在鼠标移动/单击之前,SetCursor不起作用(Win32 Api) [英] SetCursor doesn't work until mouse moves/clicks (Win32 Api)

查看:74
本文介绍了在鼠标移动/单击之前,SetCursor不起作用(Win32 Api)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在处理WM_SETCURSOR Windows消息时,我将SetCursor称为特定光标.如果将光标设置为其他值,它将一直等待,直到通过移动或单击以实际设置鼠标来输入鼠标为止.

While processing the WM_SETCURSOR windows message I call SetCursor to a certain cursor. If I set the cursor to something different then what it is, it waits until the mouse gets input via moving or clicking to actually set it.

有没有一种方法可以解决这个问题,从而使光标在输入之前不会在视觉上看起来不对?

Is there a way to counter this so the cursor doesn't visually look wrong until the cursor takes input?

case WM_SETCURSOR:
    {
        SetCursor( game->GetCursor() ); // Returns m_curCurrent
        return true;
    }
    break;

我还想在更改光标类型时对其进行设置.

I also Set the cursor type when I want it to change.

游戏初始化期间:

m_curDefault        = LoadCursor( m_hInstance, MAKEINTRESOURCE( IDC_DEFAULT_CURSOR ));
m_curAttack         = LoadCursor( m_hInstance, MAKEINTRESOURCE( IDC_ATTACK_CURSOR ));
m_curMove           = LoadCursor( m_hInstance, MAKEINTRESOURCE( IDC_MOVE_CURSOR ));
m_curCurrent        = m_curDefault;

设置光标类型时

void Game::SetCursorType( CursorTypes curType )
{
switch ( curType )
{
case CGame::DefaultCursor:
    m_curCurrent = m_curDefault;
    break;
case CGame::AttackCursor:
    m_curCurrent = m_curAttack;
    break;
case CGame::MoveCursor:
    m_curCurrent = m_curMove;
    break;
default:
    break;
}

}

推荐答案

也许为时已晚,但是无论如何,这对我有所帮助.

Maybe it is too late, but anyway here is what helped me.

当我更改了用于选择正确的光标图像的所有条件时,我发送了以下内容:PostMessage(HWND_Object,WM_SETCURSOR,0,0);

When I changed all conditions that are used for selecting proper cursor image I sent following: PostMessage(HWND_Object, WM_SETCURSOR, 0, 0);

显然,在移动鼠标之前未调用WM_SETCURSOR,但是发送此消息有助于我解决此问题.

Obviously WM_SETCURSOR was not called before mouse is moved, but sending this message helped me to solve this issue.

这篇关于在鼠标移动/单击之前,SetCursor不起作用(Win32 Api)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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