Windows Cursors

Started by
5 comments, last by epsilon 23 years, 9 months ago
How would I go about creating a color (Windows GDI) cursor at runtime from a bitmap? The cursor cannot be loaded from a resource file. It must be generated at runtime. I also cannot draw the cursor as part of the scene as the framerate is too low. Thanks in advance!
Advertisement
Here''s my findings on cursors and DirectX:

When using a black and white cursor, (like the standard arrow cursor for example), if you are running fullscreen, the cursor may or may not flicker depending upon the video card. For example, I developed a game and since the cursor looked fine on my computer I assumed it was fine. When a friend tried it out, the cursor flashed badly...

Also, whenever I tried using a colored cursor, it flashed on ANY computer.

Once again, this is only if you''re running fullscreen - maybe also with flipping surfaces.

I can''t say how to do it in C++ - this was a couple years ago when I was using VB and DirectDraw.

Hope this helps somewhat... your only option might be to manually draw the cursor.

Clay
Clay LarabieLead DeveloperTacendia.com
i don''t know whether you can use this or not, but there is a function called
HCURSOR LoadCursorFromFile(LPCTSTR lpFileName);
it loads a cursor from a file, the file must be in .cur or .ani format. go figure...
heres another one, a LOT more complicated:HANDLE LoadImage(

HINSTANCE hinst, // handle of the instance containing the image
LPCTSTR lpszName, // name or identifier of image
UINT uType, // type of image
int cxDesired, // desired width
int cyDesired, // desired height
UINT fuLoad // load flags
);

from what i can tell (i got this from MSDN) you have to pass NULL as your hinstance so it doesn''t try to load it as a resource.
lpszName is the file name to load from.
uType should be IMAGE_CURSOR.
cxDesired and cyDesired are the x and y sizes of the cursor, use SM_CXCURSOR or SM_CYCURSOR for the defaults.
fuLoad (hehe) should be LR_LOADFROMFILE to load from a file.
happy codin, hope i helped.
farmersckn


Sometimes even chickens need to eat... Don't bang your head against a wall just to enjoy the good feeling when you stop.
Yesterday is the past, tomorrow is the future. Today is a gift, that is why we call it the present.
Thanks for the tips guys. For now I guess I''ll write the cursor to disk as a bitmap and then call loadImage on it.

If anyone else knows how to convert a bitmap to a cursor in RAM, that''d be great.
If you have mouse trails on (Control Panel->Mouse) Your mouse may flicker in full screen mode.

--------------------------
Carpe Diem
D.V.Carpe Diem
Thanks for the tip on LoadImage(). Starting from there, I looked around for a while, and finally stumbled upon CopyImage(). It looks like I can use that similarly to LoadImage(), except I can specify to copy a bitmap into a new cursor.
I have recently wroten a test program to show a series of cursors
under DirectDraw in VC++ with DirectX 7.0.
I can''t figure out what the cursor ''flashes'' is in your computer.
In my case, the cursor flash because I forgot to registe the class cursor as NULL. As a result, the cursor return to the system default one when mouse move, even though you have called the SetCursor(). And then, the cursor flashes....
After I registe the class cursor as NULL, this problem is disappear..

That''s my condition....

Hopes that would help you and sorry about my poor English..



Titan

This topic is closed to new replies.

Advertisement