I am developing a C++ MFC application using Visual Studio 2008. I have a button in my UI and when the user clicks the button I want to change the mouse pointer to a panning hand. How can I do this?
Asked
Active
Viewed 1,901 times
1
-
refer http://stackoverflow.com/questions/6743644/how-to-change-the-mouse-cursor-into-a-custom-one-when-working-with-windows-forms – vishal Oct 12 '15 at 05:49
2 Answers
2
Use SetCursor()
. When button is clicked, set bool m_bHand
to true.
And in OnMouseMove()...
if (m_bHand == true)
{
SetCursor(::LoadCursor(NULL, IDC_HAND));
}
else
{
SetCursor(::LoadCursor(NULL, IDC_ARROW));
}
The 2nd parameter of LoadCursor can be your own ico resource ID.
Hope this helps. :-)

SevenWow
- 305
- 3
- 14
-2
Finally I have found an answer. Double click on the button and I have copy the following code lines as the button function. Here IDC_CURSOR1 is the ID of the cursor which I have imported to my MFC Project. I have found cursors which are in C:\Windows\Cursors.
SetClassLong(m_hWnd,
GCL_HCURSOR,
(LONG)LoadCursor(AfxGetInstanceHandle(),
MAKEINTRESOURCE(IDC_CURSOR1)));

KMA
- 211
- 3
- 17
-
This is a global solution (well, not really a solution) to a local problem. You want to change the cursor shape of a particular window class instance. Changing the window class (and thereby all window instances of that class) is going way too far. Call [SetCursor](https://msdn.microsoft.com/en-us/library/windows/desktop/ms648393.aspx) in the [WM_SETCURSOR](https://msdn.microsoft.com/en-us/library/windows/desktop/ms648382.aspx) handler. – IInspectable Oct 12 '15 at 18:18