2,782 questions
For those that are interested in changing the cursor only when the mouse is hovering (i.e., not moving) over a button -
Subclass procedure to use with SetWindowSubclass function -
LRESULT ButtonProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam, UINT_PTR uiSubclass, DWORD_PTR dwRefdata)
{
static BOOL bTracking = FALSE;
static HCURSOR handCursor = LoadCursor(NULL, IDC_HAND);
switch (msg)
{
case WM_MOUSEMOVE:
{
if (!bTracking)
{
TRACKMOUSEEVENT tme{ sizeof tme };
tme.dwFlags = TME_HOVER | TME_LEAVE;
tme.dwHoverTime = HOVER_DEFAULT;
tme.hwndTrack = hwnd;
if (TrackMouseEvent(&tme))
bTracking = TRUE;
}
}
break;
case WM_MOUSEHOVER:
{
SetCursor(handCursor);
bTracking = FALSE;
return 0;
}
break;
case WM_MOUSELEAVE:
{
bTracking = FALSE;
return 0;
}
break;
case WM_NCDESTROY:
{
RemoveWindowSubclass(hwnd, ButtonProc, uiSubclass);
}
break;
}
return DefSubclassProc(hwnd, msg, wParam, lParam);;
}