Click here to Skip to main content
15,889,867 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi .. any help how to set my custom cursor over the entire project ?
I have lots of static controls buttons and widows... and i just want to use overall the same cursor I load for the entire SDI.
here is where I load my cursor:

C++
int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrevInst, LPSTR args, int nCmdShow)
{
    InitCommonControls();

    WNDCLASSW wc = {0};

    wc.hbrBackground    = (HBRUSH)(COLOR_WINDOW);
    wc.hCursor          = (HCURSOR)LoadImage(GetModuleHandle(NULL),
                          MAKEINTRESOURCE(IDC_CURSOR), IMAGE_CURSOR, 16, 16, 0);
..
...
....
}


and the cursor load from the resources and all fine.
The point is that if I pass over a control or just over the frame, the cursor changes to the default windows cursor it is set from the system.

What I have tried:

I know there is a WM_SETCURSOR.. but how do I handle this ..?
Posted
Updated 17-Jun-20 2:40am
v2

 
Share this answer
 
Well I did change something and in some how it works, but not 100%

I delete the line in the WNDCLASSW
C++
wc.hCursor = (HCURSOR)LoadImage(GetModuleHandle(NULL),
             MAKEINTRESOURCE(IDC_CURSOR), IMAGE_CURSOR, 16, 16, 0);


And I declare in the global
HCURSOR redarrow = (HCURSOR)LoadImage(GetModuleHandle(NULL),
MAKEINTRESOURCE(IDC_CURSOR), IMAGE_CURSOR, 16, 16, 0);

C++
case WM_SETCURSOR:
            {
                    SetCursor(redarrow);
                return 1;
            }
            return DefWindowProcW(hWnd, msg, wp, lp);


It's working, but I have like few other windows that popup like about or help window where the cursor changes to default window cursor the one from the system.
 
Share this answer
 
Comments
Richard MacCutchan 17-Jun-20 8:58am    
Cursors belong to Windows, so each Window will display the cursor that is defined for its class. If you want a single cursor for all Windows than you will need to subclass any that you have not created for yourself.
M@gelearn 17-Jun-20 9:09am    
Thanks Richard.. I paste the WM_SETCURSOR to the other windows, that I have in the project, and now it works perfectly..

Still one case I don't know how to change the cursor..
I have the About window and the OK button that is deffined in the .rc file like this:
DEFPUSHBUTTON "&Ok", IDOK, 174, 66, 50, 14
I had to remove this button, cause when I pass over the cursor changes to default arrow of the system. And I have no idea how to change the cursor when it pass over the IDOK
case WM_COMMAND:
switch(wp)
{
case IDOK:
EndDialog(hWnd, IDOK);
break;
}
break;
Richard MacCutchan 17-Jun-20 9:15am    
The About Window is a Dialog so it will use the default cursor for a Dialog and its buttons.
M@gelearn 17-Jun-20 9:18am    
Well like I said .. I just removed the IDOK from the Dialog so the user can only use X to close it, and that works fine with the custom cursor.
Hey thanks again for help... cheers!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900