
SetCursor
The SetCursor function establishes the cursor shape.
SetCursor函数用于设置光标形状.
HCURSOR SetCursor(
HCURSOR hCursor // handle to cursor光标句柄
);
Parameters
参数
- hCursor
- Handle to the cursor. The cursor must have been created by the CreateCursor or loaded by the LoadCursor or LoadImage function. If this parameter is NULL, the cursor is removed from the screen.
- 光标句柄.这个光标(句柄指向的)必须是由CreateCursor建立或者用LoadCursor或LoadImage函数读取的.
- 如果这个参数为NULL,光标将从屏幕去除.
Windows 95: The width and height of the cursor must be the values returned by the GetSystemMetrics function for SM_CXCURSOR and SM_CYCURSOR. In addition, the cursor bit depth must match the bit depth of the display or the cursor must be monochrome.
Win95:光标的宽度和高度必须符合函数GetSystemMetrics使用SM_CXCURSOR和SM_CYCURSOR执行后的返回值.另外,光标的位深必须符合(当前)显示色深或为单色光标.
- 光标句柄.这个光标(句柄指向的)必须是由CreateCursor建立或者用LoadCursor或LoadImage函数读取的.
Return Values
返回值
The return value is the handle to the previous cursor, if there was one.
如果(函数执行前)有光标,那么返回前一光标的句柄.
If there was no previous cursor, the return value is NULL.
如果没有前一光标,则返回NULL.
Remarks
注:
The cursor is set only if the new cursor is different from the previous cursor; otherwise, the function returns immediately.
仅当新的光标与前一光标不同时新的光标才被设定,否则,函数立即返回.
The cursor is a shared resource. A window should set the cursor shape only when the cursor is in its client area or when the window is capturing mouse input. In systems without a mouse, the window should restore the previous cursor before the cursor leaves the client area or before it relinquishes control to another window.
光标是一种共享资源.只有当光标位于窗口客户区内或窗口捕捉到鼠标输入(或称捕捉到光标)时,窗口才可以设置光标形状.在没有鼠标的系统中,窗口应该在光标离开(此窗口的)客户区之前或在它将控制权让与另一个窗口前,恢复前一光标
If your application must set the cursor while it is in a window, make sure the class cursor for the specified window's class is set to NULL. If the class cursor is not NULL, the system restores the class cursor each time the mouse is moved.
如果应用程序必须在窗口中设置光标,必须确保指定窗口类的类光标被设为NULL,如果类光标不是NULL,则每次移动鼠标时,系统都要恢复类光标。(而且你要设置的光标最好是自己添加的资源)
The cursor is not shown on the screen if the internal cursor display count is less than zero. This occurs if the application uses the ShowCursor function to hide the cursor more times than to show the cursor.
如果内部的光标显不计数值小于零,则光标不在屏幕上显示。当一个应用程序使用ShowCursor函数隐藏光标的次数多于显示光标的次数时,则会发生这种情况。
Windows CE: Use the cursor component when targeting a platform that does not support mouse cursors. The only cursor this component supports is the wait cursor. Use the following code to set the wait cursor:
当一个目标平台不支持鼠标光标时,使用cursor光标组件,该光标组件仅支持等待光标,设置等待光标,使用如下的代码:
SetCursor(LoadCursor(NULL, IDC_WAIT));
Use the mcursor component when targeting a platform that does support mouse cursors. This component does not support color cursors.
当一个目标平台不支持鼠标光标时,使用mcursor光标组件。该组件不支持彩色光标。
QuickInfo
快速信息
Windows NT: Requires version 3.1 or later.需要3.1以上版本
Windows: Requires Windows 95 or later.Win95以上
Windows CE: Requires version 1.0 or later.1.0以上版本
Header: Declared in winuser.h.在winuser.h中声明
Import Library: Use user32.lib.使用user32.lib库
See Also
Cursors Overview, Cursor Functions, CreateCursor, GetCursor, GetSystemMetrics, LoadCursor, LoadImage, SetCursorPos, ShowCursor

