[SDL] Colored Cursors on MS Windows

Adrian Grigore adrian at lobstersoft.com
Fri Sep 15 09:54:48 PDT 2006


Hi,

I am creating a puzzle game for Windows using SDL. So far everything went very 
smoothly, but now I am stuck while trying to implement a colored mouse cursor. 

I know that SDL officially only supports b/w cursors, but I do not require 
cross-plattform compatibility, nor do I need hardware acceleration. So a 
regular windows cursor will suffice. I would not want to hide the SDL cursor 
and blit the mousecursor myself because that makes the mouse feel quite laggy 
on slow systems. 

So far I tried setting the mouse cursor via the windows API: 
the following:

//load a windows cursor cursor resource
HCURSOR hCursor = (HCURSOR)LoadImage(NULL,CursorPath.c_str
(),IMAGE_CURSOR,0,0,LR_LOADFROMFILE|LR_SHARED);
//set the cursor globally.
::SetCursor(hCursor);	

This works, but only for a brief moment, before SDL seems to notice what has 
been happening and resets the cursor to the previous look. 


I thought it might have to do with the following behaviour described in the 
windows manual:

<SNIP>
If your application must set the cursor while it is in a window, 
make sure the class cursor for the specified window's class is
set to NULL. If the class cursor is not NULL, the system restores
the class cursor each time the mouse is moved.	
</SNIP>

So I tried the following as well:

//Set the main window's caption
SDL_WM_SetCaption("MyGame","");
//get a handle to the main window
HWND MainWindowHandle=FindWindow(NULL,"MyGame");

//set the window's class cursor to NULL, so it does not revert
//to the sdl cursor as soon as the mouse is moving
SetClassLongPtr(MainWindowHandle,GCLP_HCURSOR,NULL);

//load a windows cursor cursor resource
HCURSOR hCursor = (HCURSOR)LoadImage(NULL,CursorPath.c_str
(),IMAGE_CURSOR,0,0,LR_LOADFROMFILE|LR_SHARED);
//set the cursor globally.
::SetCursor(hCursor);	
	
Unfortunately this did not seem to have any different effect either. 

Is there any kind of hack (again: I really don't care about cross-plattform 
compatibility at the moment) that would allow me to set a colored windows 
cursor? I had a look at the SDL sources, but could not figure out how to do it.

Thanks,

Adrian Grigore







More information about the SDL mailing list