5

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.

During initialization of game:

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;

When setting Cursor type

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

}
General Grievance
  • 4,555
  • 31
  • 31
  • 45
Ryan Madsen
  • 51
  • 2
  • 4
  • Perhaps [this question](http://stackoverflow.com/questions/19257237/reset-cursor-in-wm-setcursor-handler-properly) is helpful. – AlwaysLearningNewStuff Mar 08 '14 at 15:53
  • Windows automatically generates the WM_SETCURSOR message when you move the mouse. After all, the mouse is located somewhere else so the cursor may have to be updated. So if you "change the cursor" then you probably want to send WM_SETCURSOR yourself instead of waiting for Windows to do it for you. – Hans Passant Mar 08 '14 at 16:35

3 Answers3

3

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

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

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

01dschool
  • 31
  • 2
0

I think that you need to aquire the mouse with WM_SETCURSOR at the start of the program and then it will have the mouse.

RAWMOUSE gives you logical coordinates for the mouse based on the mouse's native resolution.

That is, you see the actual movement of the mouse.

Windows will use the mouse speed and acceleration (ballistics) settings to update the cursor position. Because of course the two are not linked - the apparent movement of the mouse must be interpreted to generate a cursor movement else how can more than one mouse be supported?

If you wish to control a pointer, as far as I can tell there is no reason to duplicate the Windows mouse ballistics calculations. Just let windows do it. Therefore for controlling the pointer, you should just use WM_MOUSEMOVE. That is, unless you wish to disable the mouse acceleration settings in your application.

However, if you want to control the player's POV (point of view), or use the mouse to control an in-game object such as a spaceship flight yoke, then the RAWMOUSE data gives you the best possible access to the movement of the mouse, and you can implement your own algorithm to convert that into flight yoke/POV movement.

Josh
  • 188
  • 1
  • 12
0

I have faced the similar problem in my application. I didn’t find the exact reason still now but there is an easy by-pass solution for this problem. Use SetCursorPos function, which will call cursor move function automatically. So get the current cursor possion and set it again after returning from SetCursor function. Here bellow the sample code:

POINT p;
if (::GetCursorPos(&p))
{
    SetCursorPos(p.x,p.y);
}
yeasir007
  • 2,110
  • 2
  • 28
  • 43