Changing cursor during runtime

Hello,
I would like to change the mouse cursor whenever the user starts the program
I have tried this and it worked except I can only restore the original once from control panel after the program ends.

1
2
3
const char * s = "C:\\Users\\user\\Desktop\\PT_Project\\cur1.ani";
	HCURSOR Cursor = LoadCursorFromFile(s);
	SetSystemCursor(Cursor,32512);


and It's my first time programming with Windows library.. so I would be grateful if anyone offers me a good starting spot to learn more about it.
Thanks :D
Last edited on
closed account (E0p9LyTq)
You don't want to use SetSystemCursor() to change cursors for your program, you want to use SetCursor().

Setting the Cursor Image (Windows) - msdn.microsoft.com
https://msdn.microsoft.com/en-us/library/windows/desktop/gg153552(v=vs.85).aspx

Being this is your first time programming for Windows you might want to look at this:

Learn to Program for Windows in C++ - msdn.microsoft.com
https://msdn.microsoft.com/en-us/library/windows/desktop/ff381399(v=vs.85).aspx

Windows programming is a LOT to learn. :)
I still tried to handle WM_SETCURSOR, but I don't know how to exactly how to do so. should there be an Exception handling procedure here? I have just learned that at my programming course and I am not sure if I can implement something this complicated sadly, is there any other way ?

1
2
3
4
5
6
7
8
   case WM_SETCURSOR:
        if (LOWORD(lParam) == HTCLIENT)
        {
            SetCursor(hCursor);
            return TRUE;
        }
        break;

and this should be the catch right?

and I think I will just go over the basics with windows programming, I don't think getting into it that much would be helpful to me in the long run.
anyways thanks :D
closed account (E0p9LyTq)
ahmedkhalifa wrote:
I would like to change the mouse cursor whenever the user starts the program

You can set your app's cursor in WinMain() using the WNDCLASS/WNDCLASSEX structure you supply to RegisterClass()/RegisterClassEx().

Now if all that sounds like a lot of gobbley-gook nonsense:

Win32 API Tutorial
http://www.winprog.org/tutorial/

You really need to read what WM_SETCURSOR represents, it isn't what you think it means.
https://msdn.microsoft.com/en-us/library/windows/desktop/ms648382(v=vs.85).aspx
Last edited on
Ohh wow, this is really complicated. So I think I understand what WNDCLASS is, its the default class by the windows that contains all the info about the window, as far as I am concerned, the cursor is the only thing that matters to me, but the question is how to set the cursor? And I don't know what WMCURSOR is really, like is this a defintion? If so how come it takes parameters as mentionned on microsoft page? The whole thing is just way too complicated for me to understand. Thanks for your time tho
closed account (E0p9LyTq)
The Windows API is complicated because the Windows operating system does all the work.

You, as a programmer, tell Windows what you want done and let the OS handle all the work. Windows tells your program what happens with messages, and you then handle whatever messages are important to your program.

As I said earlier learning Windows programming is a LOT to learn, and is not easy to grasp.

FYI, that Win32 API tutorial I linked above is but a VERY small part of what can be done in a Windows application. To make it even more complicated there are add-on libraries for the Common Controls and DirectX.
The whole thing is just way too complicated for me to understand.

GUI programming in C++ is not easy. Why don't you have a look at C# or Java.
GUI programming in C++ is not easy. Why don't you have a look at C# or Java.
The project that I am worked on at school is using the C++ language. P.S: I am not required to do anything at all with the windows library, I just thought that would be a plus, and hopefully I will try learning a new language this summer.
closed account (E0p9LyTq)
Learning the Windows API is learning another language, MS took C and heaped a lot of stuff onto it.
By another language, I mean stuff like java or even stuff like mySQL or C# . Alot have told me that C++ is not as useful as those mentioned above. and my major doesn't really require deep knowledge of languages. P.S: would using a custom library help? or would it be bad practice because of the lack of understand I have when it comes to windows programming?
MS took C and heaped a lot of stuff onto it

@FurryGuy,
what do you mean?

@OP,
all custom libraries have a rather steep learning curve. What do you actually want to do ?
@Thomas1965 not really, given my current experience with c++. -I did try the SFML library but I would have to start from scratch because of the GUI given to me doesn't really handle SFML-
I think I won't be capable of handling windows.h functions so I'd rather stick to what's asked to do. Thanks however
Windows programs will always reload the cursor in the window registered class (WNDCLASSEX wincl ) to stop this set wincl.hCursor = NULL;
and then set your cursor when your program starts

alternatively you could set your desired cursor with
case WM_SETCURSOR:
SetCursor(LoadCursor(NULL,IDC_CROSS));
break;

in the windowprocedure.
Topic archived. No new replies allowed.