Jump to content

WinCreateCursor: Difference between revisions

From EDM2
Created page with "This function creates or changes a cursor for a specified window. ==Syntax== WinCreateCursor(hwnd, lx, ly, lcx, lcy, ulrgf, prclClip) ==Parameters== ; hwnd (HWND) - input ..."
 
 
(2 intermediate revisions by 2 users not shown)
Line 1: Line 1:
This function creates or changes a cursor for a specified window.  
This function creates or changes a cursor for a specified window.


==Syntax==
==Syntax==
Line 5: Line 5:


==Parameters==
==Parameters==
; hwnd (HWND) - input
;hwnd ([[HWND]]) - input:Handle of window in which cursor is displayed.
:Handle of window in which cursor is displayed.
:This must be the handle of a window for which the application can receive input.
 
;lx ([[LONG]]) - input:x-position of cursor.
:This must be the handle of a window for which the application can receive input.  
;ly (LONG) - input:y-position of cursor.
 
;lcx (LONG) - input:x-size of cursor.
;lx (LONG) - input
:If 0, the system nominal border width (SV_CXBORDER) is used.
:x-position of cursor.  
;lcy (LONG) - input:y-size of cursor.
 
:If 0, the system nominal border height (SV_CYBORDER) is used.
;ly (LONG) - input
;ulrgf ([[ULONG]]) - input:Controls the appearance of the cursor.
:y-position of cursor.  
::CURSOR_SOLID - The cursor is solid.
 
::CURSOR_HALFTONE - The cursor is halftone.
;lcx (LONG) - input
::CURSOR_FRAME - The cursor is a rectangular frame.
:x-size of cursor.
::CURSOR_FLASH - The cursor flashes.
:If 0, the system nominal border width (SV_CXBORDER) is used.  
::CURSOR_SETPOS - Set a new cursor position. lcx and lcy are ignored. Used when a cursor has already been created. In this case, all other appearance flags are ignored.
 
;prclClip (PRECTL) - input:Cursor rectangle.
;lcy (LONG) - input
:y-size of cursor.
:If 0, the system nominal border height (SV_CYBORDER) is used.  
 
;ulrgf (ULONG) - input
:Controls the appearance of the cursor.
:;CURSOR_SOLID
::The cursor is solid. CURSOR_HALFTONE
::The cursor is halftone. CURSOR_FRAME
::The cursor is a rectangular frame. CURSOR_FLASH
::The cursor flashes. CURSOR_SETPOS
::Set a new cursor position. lcx and lcy are ignored. Used when a cursor has already been created. In this case, all other appearance flags are ignored.  
 
;prclClip (PRECTL) - input
:Cursor rectangle.
 
:A rectangle within which the cursor is visible. If the cursor goes outside this rectangle, it is clipped away and is invisible.
:A rectangle within which the cursor is visible. If the cursor goes outside this rectangle, it is clipped away and is invisible.
:The rectangle is specified in window coordinates.
:The rectangle is specified in window coordinates.
:If prclClip is NULL, the drawing of the cursor is clipped to the window rectangle of hwnd.
:If prclClip is NULL, the drawing of the cursor is clipped to the window rectangle of hwnd.
:Note: The cursor is always clipped to the window rectangle, even if part of prclClip is outside it.
:Note: The cursor is always clipped to the window rectangle, even if part of prclClip is outside it.
:The value of each field in this structure must be in the range -32 768 through 32 767. The data type WRECT can also be used, if supported by the language.
:The value of each field in this structure must be in the range -32 768 through 32 767. The data type WRECT can also be used, if supported by the language.


==Returns==
==Returns==
;rc (BOOL) - returns
;rc (BOOL) - returns:Success indicator.
:Success indicator.
::TRUE - Successful completion
:;TRUE
::FALSE - Error occurred.
::Successful completion  
:;FALSE
::Error occurred.


==Errors==
==Errors==
Possible returns from WinGetLastError
Possible returns from WinGetLastError
 
;PMERR_INVALID_HWND (0x1001):An invalid window handle was specified.
;PMERR_INVALID_HWND (0x1001)
;PMERR_INVALID_FLAG (0x1019):An invalid bit was set for a parameter. Use constants defined by PM for options, and do not set any reserved bits.
:An invalid window handle was specified.
;PMERR_INVALID_FLAG (0x1019)
:An invalid bit was set for a parameter. Use constants defined by PM for options, and do not set any reserved bits.


==Remarks==
==Remarks==
Line 69: Line 43:
The cursor width is generally specified as 0 (nominal border width is used). This is preferable to a value of 1, for example, as such a fine width is almost invisible on a high-resolution device.
The cursor width is generally specified as 0 (nominal border width is used). This is preferable to a value of 1, for example, as such a fine width is almost invisible on a high-resolution device.


When ulrgf is set to CURSOR_FLASH, TID_CURSOR timer is created.  
When ulrgf is set to CURSOR_FLASH, TID_CURSOR timer is created.


==Example Code==
==Example Code==
This example creates a cursor of default height and width at (0,200) which will be visible within the entirety of the input window.
This example creates a cursor of default height and width at (0,200) which will be visible within the entirety of the input window.
<pre>
<pre>
#define INCL_WINCURSORS         /* Window Cursor Functions     */
#define INCL_WINCURSORS   /* Window Cursor Functions */
#include <os2.h>
#include <os2.h>


BOOL fSuccess;         /* success indicator                   */
BOOL   fSuccess;     /* success indicator           */
HWND    hwnd;           /* cursor display window               */
HWND    hwnd;         /* cursor display window       */
LONG   lx = 0;         /* cursor x position                   */
LONG   lx = 0;       /* cursor x position           */
LONG   ly = 200;       /* cursor y position                   */
LONG   ly = 200;     /* cursor y position           */
ULONG  ulrgf;         /* cursor appearance                   */
ULONG  ulrgf;         /* cursor appearance           */


fSuccess = WinCreateCursor(hwnd, lx, ly, 0, 0, ulrgf, NULL);
fSuccess = WinCreateCursor(hwnd, lx, ly, 0, 0, ulrgf, NULL);
</pre>
Definition
<pre>
#define INCL_WINCURSORS /* Or use INCL_WIN, INCL_PM, Also in COMMON section */
#include <os2.h>
HWND      hwnd;      /*  Handle of window in which cursor is displayed. */
LONG      lx;        /*  x-position of cursor. */
LONG      ly;        /*  y-position of cursor. */
LONG      lcx;      /*  x-size of cursor. */
LONG      lcy;      /*  y-size of cursor. */
ULONG    ulrgf;    /*  Controls the appearance of the cursor. */
PRECTL    prclClip;  /*  Cursor rectangle. */
BOOL      rc;        /*  Success indicator. */
rc = WinCreateCursor(hwnd, lx, ly, lcx, lcy,
      ulrgf, prclClip);
</pre>
</pre>


==Related Functions==
==Related Functions==
* WinDestroyCursor
* [[WinDestroyCursor]]
* WinQueryCursorInfo
* [[WinQueryCursorInfo]]
* WinShowCursor  
* [[WinShowCursor]]


[[Category:Win]]
[[Category:Win]]

Latest revision as of 18:47, 10 April 2025

This function creates or changes a cursor for a specified window.

Syntax

WinCreateCursor(hwnd, lx, ly, lcx, lcy, ulrgf, prclClip)

Parameters

hwnd (HWND) - input
Handle of window in which cursor is displayed.
This must be the handle of a window for which the application can receive input.
lx (LONG) - input
x-position of cursor.
ly (LONG) - input
y-position of cursor.
lcx (LONG) - input
x-size of cursor.
If 0, the system nominal border width (SV_CXBORDER) is used.
lcy (LONG) - input
y-size of cursor.
If 0, the system nominal border height (SV_CYBORDER) is used.
ulrgf (ULONG) - input
Controls the appearance of the cursor.
CURSOR_SOLID - The cursor is solid.
CURSOR_HALFTONE - The cursor is halftone.
CURSOR_FRAME - The cursor is a rectangular frame.
CURSOR_FLASH - The cursor flashes.
CURSOR_SETPOS - Set a new cursor position. lcx and lcy are ignored. Used when a cursor has already been created. In this case, all other appearance flags are ignored.
prclClip (PRECTL) - input
Cursor rectangle.
A rectangle within which the cursor is visible. If the cursor goes outside this rectangle, it is clipped away and is invisible.
The rectangle is specified in window coordinates.
If prclClip is NULL, the drawing of the cursor is clipped to the window rectangle of hwnd.
Note: The cursor is always clipped to the window rectangle, even if part of prclClip is outside it.
The value of each field in this structure must be in the range -32 768 through 32 767. The data type WRECT can also be used, if supported by the language.

Returns

rc (BOOL) - returns
Success indicator.
TRUE - Successful completion
FALSE - Error occurred.

Errors

Possible returns from WinGetLastError

PMERR_INVALID_HWND (0x1001)
An invalid window handle was specified.
PMERR_INVALID_FLAG (0x1019)
An invalid bit was set for a parameter. Use constants defined by PM for options, and do not set any reserved bits.

Remarks

The cursor is used to indicate the position of text input. It is initially hidden and must be made visible using the WinShowCursor function.

This function destroys any existing cursor, as it is confusing to the user if two cursors are visible at any one time. An application creates and displays a cursor when it has the input focus, or is the active window. Creating a cursor at any other time can stop the cursor from flashing in another window. Similarly, when the application loses the input focus or becomes inactive, it destroys its cursor using the WinDestroyCursor function.

The cursor width is generally specified as 0 (nominal border width is used). This is preferable to a value of 1, for example, as such a fine width is almost invisible on a high-resolution device.

When ulrgf is set to CURSOR_FLASH, TID_CURSOR timer is created.

Example Code

This example creates a cursor of default height and width at (0,200) which will be visible within the entirety of the input window.

#define INCL_WINCURSORS    /* Window Cursor Functions */
#include <os2.h>

BOOL    fSuccess;      /* success indicator           */
HWND    hwnd;          /* cursor display window       */
LONG    lx = 0;        /* cursor x position           */
LONG    ly = 200;      /* cursor y position           */
ULONG   ulrgf;         /* cursor appearance           */

fSuccess = WinCreateCursor(hwnd, lx, ly, 0, 0, ulrgf, NULL);

Related Functions