Mouse Pointer

Started by
5 comments, last by Jamazon 22 years, 3 months ago
Hi I''m making a simple game with Open Gl And Windows. My game needs to be able to change the mouse pointer depending on where abouts it is but I cant find out how to do it. Please Help...: Heres what i''ve got: //boring code above/.. GetCursorPos(&mpos); if (mpos.y < 5) //if mouse at top screen I want to change to arrow upwards (data/icons/test.cur) { Y -= 0.25f; //move screen UP //here change mouse cursor to data/cursors/up_arrow.ico - or bmp. //I think i have to do this?? wc.hCursor = LoadCursor (NULL, ???); } I dont want to use one of the already defined cursors, one from a file. How do i chnage it to the file one?? Please help !! Thanks -------
-------
Advertisement
Look in MSDN under SetCursor or LoadCursor. I think those functions should do it. SetCursor will change the cursor without having to recreate a window.
the previous guy was right, but there''s a way to get much nicer cursors.
1.hide the standard cursor (call ShowCursor(false); or so, don''t remember now)
2.while drawing your frame at the end draw a bitmap of cursor at cursor''s position. use a simple textured quad for it and turn off zbuffer check so your cursor always gets written, just like you would be writing a 2d bitmap for your GUI. Now instead windows cursor you have got a texture image representing your cursor. It can include such effects like alpha-blending etc. Pretty cool, eh?

With best regards,
Mirek Czerwiñski
http://kris.top.pl/~kherin/
With best regards, Mirek Czerwiñski
One thing you might want to do is to define a few integral constants to represent the cursors you''ll display. Then, make some function for switching the cursor that switches only if the requested cursor isn''t already being displayed; otherwise, you might get annoying flickering. Here''s a little snippet to demonstrate:

  enum cursor {arrow, hand, hourglass};void UseCursor(cursor new_cursor){    static int last_cursor = -1;    if(last_cursor == new_cursor)        return;    switch(new_cursor)    {        case arrow:            SetCursor(LoadCursor(...        break;                case ...        break;    }    last_cursor = new_cursor;}  
Hi again

Thanks for your help but it still wont work. The loadcurser funtion and SetCurser doesnt want to load my own curser (from a different file) (LoadCurser(NULL, "tst.cur")) but works when using one like IDC_ARROW - LoadCurser(NULL, IDC_ARROW) which is already defined. Is it possible to define your cursers like above? How? Also, how would u turn off z buffering to draw the bmp curser.

Thanks

-------
-------
Jamazon when you load from resources you must use ''MAKEINTRESOURCE'', try this:
LoadCursor (NULL, MAKEINTRESOURCE(IDC_ARROW))

From the MSDN:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/cursors_2sab.asp

And to disable z-buffer
glDisable(GL_DEPTH_TEST)

To enable it, us glEnable with GL_DEPTH_TEST

Hope this helps


_____________________
Yoshy - From The Bobs
_____________________
If I''m observing correctly, you''re trying to load a cursor from an external file, right? If so, you have to use LoadCursorFromFile or LoadImage.

This topic is closed to new replies.

Advertisement