Archived

This topic is now archived and is closed to further replies.

Hedos

Changing the cursor

Recommended Posts

Hedos    674
Hi, is there a built-in function to change the cursor appearence with Direct X 8.1 ? Or I will have to Hide the cursor and render a bitmap at the cursor location ?? (Also, I have a second question. Do you know a good website with tutorials on using animated pictures in Direct3D ? Thanks ------------------------- Account: Hedos - Level 1 Programmer

Share this post


Link to post
Share on other sites
szevvy    122
Depends. If you can see your cursor now, then you''d just change the cursor the way you''d normally do it - I use BCB so I''d do it differently. If you can''t see your cursor (i.e. yo''re page flipping) then you''ll have to render a bitmap.

Share this post


Link to post
Share on other sites
Hedos    674
I can see the normal cursor.

quote:

then you'd just change the cursor the way you'd normally do it - I use BCB so I'd do it differently



Hum, but I don't know how to change the cursor, I never did it

And what is BCB ?

-------------------------
Account: Hedos - Level 1 Programmer

[edited by - Hedos on April 28, 2003 11:32:41 PM]

Share this post


Link to post
Share on other sites
brain21    128
He can probably see it, or he wouldn''t be asking.

There is a Win32 API function you can use. try:
SetCursor() ....Look it up in the Win32 help files. Yes you can use it in DirectX.

Share this post


Link to post
Share on other sites
Corry    122
First off are you using DirectDraw or Direct3D. If it is Direct3D here is a solution for you....I don''t know if there is something similar in DirectDraw....SInce you asked about animated pictures in D3D I am assuming you are using Direct3D
In direct3d there is a function HRESULT IDirect3DDevice8/9::SetCursorProperties(UINT XHotSpot, UINT YHotSpot, IDirect3DSurface9 *pCursorBitmap);
where XHotspot is the x coordinate offset from the upper left corner of the bitmap of the point that "clicking" will happen (It will render the surface offset from that point) YHotspot is the same but the Y Coordinate. pCursorBitmap is a surface created in DX8 as CreateImageSurface or DX9 as CreateOffscreenPlainSurface it should be D3DFORMAT_A8R8G8B8, generally speaking it should be 32x32 in size, but on most video cards it will scale it. Just remember you need to call SetCapture(YourProgramsHWND); Now, all the sample code I could find said to handle the WM_SETCURSOR message with something like this
case WM_SETCURSOR:
SetCursor(NULL)
g_lpD3DD->ShowCursor(TRUE);
break;
and somewhere in your initialization you have the call to SetCursorProperties()
However, I found that in my code this did NOT work. Instead, my WM_SETCURSOR handler is a call to SetCapture just to assure I am not going to be getting 1000''s of those messages. Then in my initialization I have the call to SetCursorProperties, followed by a call to the ShowCursor(TRUE) on my Direct3D Device. I then have a call to SetCursorPosition in my ReadMouse function, as well as another call to SetCursorProperties, which seemed to be necessary in DX9, but I havent tried removing it in DX8 yet. I found that any call to the windows API ShowCursor(FALSE) also seemed to translate to the D3D Cursor, as well as the API call to SetCursor(NULL) In most tutorials I found mention calls to both of these functions. You can feel free to try them, but I have had no luck getting it to work. Feel free to IM me if you have any questions on this as I spent all last weekend tracking down these problems and getting the cursor to work. I never suspected the tutorials to be wrong, so I never suspected those lines...

As for animated pictures, are you asking about reading animated formats (avi''s, gif89a?) or are you talking about the famed animated textures?

Share this post


Link to post
Share on other sites
PugPenguin    122
yes I agree I think the simplest way is to use the resource editor in Visual C++ (or whatever you're using) to draw a cursor you want to see, then load it into resource handler and call:

HCURSOR SetCursor(
HCURSOR hCursor // handle to cursor
);

with the handler as the parameter.

EDIT:
This posting seems to have overlapped with Corry's posting. For your info.

[edited by - PugPenguin on April 29, 2003 1:14:06 AM]

Share this post


Link to post
Share on other sites
PugPenguin    122
I don''t know whats ''simplest'' given a particular circumstance. Last time I did anything remotely close, I just went for ANI format rather than CUR and load it with LoadCursorFromFile().

But I think it really depends on what you are dealing with. A little tedious, but my favourate approach is simply to write my own routine. First hide default cursor so you don''t see mouse cursor. Aquire the (x,y) position of cursor (it''s invisible but it exists) and simply render your own graphics at that location.

I''m not an expert in this so I don''t know whats ''easiest'' as such, but I really think it depends on what your approach is and how much control you want.

Share this post


Link to post
Share on other sites