I load the cursor with loadCursorFromFile() , get a variable of type hCursor . How to set the received cursor for the window of my application? Ideally, it is necessary to replace several standard cursors and then be able to switch them using standard identifiers: regular, hourglass, etc.

    1 answer 1

    First, the function is called LoadCursorFromFile and not loadCursorFromFile . This is significant because the names of WinAPI functions are case-sensitive.

    Secondly, this function returns a result of type HCURSOR , not hCursor . For the same reason.

    Although all this is true for WinAPI itself. Your language (which you did not specify) may use its wrappers with other names.

    Thirdly, the cursor setting function is called SetCursor (unexpectedly :).

    • I used SetCursor , but the cursor did not change, then I realized that (as written by your link) the cursor is reset to standard with each mouse movement. Is it possible to avoid having to set the cursor in a mouse move event (each time it is moved, pressed, etc.)? - nup
    • @nup, not exactly. The cursor is reset at the event of the mouse only if the cursor in the class of the corresponding window is set. And it is reset not to the standard, but to the class one. Everything is logical, what are you waiting for? And to avoid this is simple - do not set the class cursor. Why ask him if you want to constantly replace him? - freim
    • Is there a possibility through winApi to reset this class cursor? Apparently, it is defined by the constructor (Delphi language). - nup
    • @nup, see the SetClassLongPtr function, an argument to GCLP_HCURSOR . Another option (which, in theory, you need to do anyway) is to set a handler for WM_MOUSEMOVE and set the cursor there. - freim