Game Development Community

System cursors always trying to change back to Default Arrow

by Tim Scheiman · in Torque Game Builder · 05/02/2010 (12:03 pm) · 2 replies

Hey all,

I've got windows system cursors finally up and running, but I'm running into some weirdness.

The engine is CONSTANTLY trying to set the cursor back to the default Arrow. It's especially bad when moving the mouse around, but it happens even when just sitting there.

CursorManager::refreshCursor() successfully keeps changing it back to what it is supposed to be, but the end result is some pretty nasty flickering-in-and-out of the default arrow.

I've examined every called to "SetCursor()" in the source code, stepping through... and it isn't any of them. (i.e. the source is at no point ASKING the game to switch back to the default arrow)

Anyone have any insights as to why this might be happening?

(btw this is 1.7.4, running in Vista)

-Tim

#1
04/26/2012 (6:06 pm)
This thread is a bit old, but I just ran up against the same problem and after a bit of digging, I have found a fix.

In winWindow.cc there is the InitWindowClass() function for creating the main window class for your application:

static void InitWindowClass()
{
   WNDCLASS wc;
   dMemset(&wc, 0, sizeof(wc));

   wc.style         = CS_OWNDC;
   wc.lpfnWndProc   = WindowProc;
   wc.cbClsExtra    = 0;
   wc.cbWndExtra    = 0;
   wc.hInstance     = winState.appInstance;
   wc.hIcon         = LoadIcon(winState.appInstance, MAKEINTRESOURCE(IDI_ICON1));
   wc.hCursor       = LoadCursor (NULL,IDC_ARROW);
   wc.hbrBackground = (HBRUSH) GetStockObject(BLACK_BRUSH);
   wc.lpszMenuName  = 0;
   wc.lpszClassName = windowClassName;
   RegisterClass( &wc );

   // Curtain window class:
   wc.lpfnWndProc   = DefWindowProc;
   wc.hCursor       = NULL;
   wc.hbrBackground = (HBRUSH) GetStockObject(GRAY_BRUSH);
   wc.lpszClassName = dT("Curtain");
   RegisterClass( &wc );
}

The line you want to change is:
wc.hCursor       = LoadCursor (NULL,IDC_ARROW);
Simply change this to:
wc.hCursor       = NULL;

The reason why this causes the problem is that Windows itself will set the cursor to whatever is contained in wc.hCursor when it gets mouse move messages.
#2
04/28/2012 (3:06 pm)
I don't remember how I ended up resolving this one... but thanks for posting a fix to the forums for all!

Anyone using Windows system cursors will end up seeing this issue, so it's nice to have the fix here.