3 out of 7 rated this helpful - Rate this topic

WM_SETCURSOR message

Applies to: desktop apps only

Sent to a window if the mouse causes the cursor to move within a window and mouse input is not captured.

#define WM_SETCURSOR                    0x0020

Parameters

wParam

A handle to the window that contains the cursor.

lParam

The low-order word of lParam specifies the hit-test code.

The high-order word of lParam specifies the identifier of the mouse message.

Return value

If an application processes this message, it should return TRUE to halt further processing or FALSE to continue.

Remarks

The high-order word of lParam is zero when the window enters menu mode.

The DefWindowProc function passes the WM_SETCURSOR message to a parent window before processing. If the parent window returns TRUE, further processing is halted. Passing the message to a window's parent window gives the parent window control over the cursor's setting in a child window. The DefWindowProc function also uses this message to set the cursor to an arrow if it is not in the client area, or to the registered class cursor if it is in the client area. If the low-order word of the lParam parameter is HTERROR and the high-order word of lParam specifies that one of the mouse buttons is pressed, DefWindowProc calls the MessageBeep function.

Requirements

Minimum supported client

Windows 2000 Professional

Minimum supported server

Windows 2000 Server

Header

Winuser.h (include Windows.h)

See also

Reference
DefWindowProc
HIWORD
LOWORD
Conceptual
Cursors

 

 

Send comments about this topic to Microsoft

Build date: 2/3/2012

Did you find this helpful?
(1500 characters remaining)
Community Content Add
Annotations FAQ
WM_SETCURSOR in dialog procedures for child controls
Since I barely ever program GUI in C++ I completely forgot about SetWindowLongPtr() and DWLP_MSGRESULT. This page says you need to return TRUE if you set the cursor for children of the dialog form, but since you also return TRUE to signal that you handled the message, and that happens to be the same value that you return to signal the cursor has been set, I was misled into thinking that the return value was the only thing needed. It is not. You must set the message result using SetWindowLongPtr() and DWLP_MSGRESULT: SetWindowLongPtr(hDlg, DWLP_MSGRESULT, TRUE); return TRUE; That is what is needed in dialog procedures in order to set the cursor for the children controls.
Check LOWORD(lParam)
In most cases you should only set the cursor if LOWORD(lParam) is HTCLIENT, meaning the client area of the window. For the nonclient area, let Windows set the cursor.
What is missing?
i've added in message map ON_WM_SETCURSOR() and a function bool OnSetCursor(CWnd*, UINT, UINT) and i'm becoming following error: $0$0 $0 $0error C2440: 'static_cast' : cannot convert from 'bool (__thiscall CMFCMouseDlg::* )(CWnd *,UINT,UINT)' to 'BOOL (__thiscall CWnd::* )(CWnd *,UINT,UINT)'$0 $0 $0$0 $0 $0at the line where ON_WM_SETCURSOR() is in message map.$0 $0What i should do to make it work? I suppose that is easy but I'm a beginer with MFC.$0 $0Regards,$0 $0Mr M.$0
Value
WM_SETCURSOR = &H20