Jump to content

PMGuide - Cursors: Difference between revisions

From EDM2
Created page with "{{IBM-Reprint}} {{PMGuide}} A cursor is a rectangle that can be shown at any location in a window, indicating where the user's next interaction with items on the screen will ..."
 
Ak120 (talk | contribs)
mNo edit summary
 
Line 2: Line 2:
{{PMGuide}}
{{PMGuide}}


A cursor is a rectangle that can be shown at any location in a window, indicating where the user's next interaction with items on the screen will happen. This chapter describes how to create and use cursors in your PM applications.  
A cursor is a rectangle that can be shown at any location in a window, indicating where the user's next interaction with items on the screen will happen. This chapter describes how to create and use cursors in your PM applications.
 
==About Cursors==
==About Cursors==
Only one cursor appears on the screen at a time-either marking the text-insertion point (a text cursor) or indicating which items the user can interact with from the keyboard (a selection cursor). For example, when an entry field has the keyboard focus, it displays a blinking vertical bar to show the text-insertion point; however, when a button has the keyboard focus, the cursor appears as a halftone rectangle the size of the button. The operating system draws and blinks the cursor, freeing the application from handling these details. Notice that the cursor has no direct relationship with the mouse pointer.  
Only one cursor appears on the screen at a time-either marking the text-insertion point (a text cursor) or indicating which items the user can interact with from the keyboard (a selection cursor). For example, when an entry field has the keyboard focus, it displays a blinking vertical bar to show the text-insertion point; however, when a button has the keyboard focus, the cursor appears as a halftone rectangle the size of the button. The operating system draws and blinks the cursor, freeing the application from handling these details. Notice that the cursor has no direct relationship with the mouse pointer.
 
===Cursor Creation and Destruction===
===Cursor Creation and Destruction===
The system can use only one cursor at a time, so windows must create and destroy cursors as each windows gains and loses the keyboard focus. If an application attempts to use more than one cursor at a time, the results can be unpredictable and might affect other applications.
The system can use only one cursor at a time, so windows must create and destroy cursors as each windows gains and loses the keyboard focus. If an application attempts to use more than one cursor at a time, the results can be unpredictable and might affect other applications.


An application creates a cursor by calling WinCreateCursor. Generally, this is done when a window gains the keyboard focus. The application specifies the window in which to display the cursor, whether it be the desktop window, an application window, or a control window. An application destroys a cursor by calling WinDestroyCursor- when the specified window loses the keyboard focus, for example.
An application creates a cursor by calling WinCreateCursor. Generally, this is done when a window gains the keyboard focus. The application specifies the window in which to display the cursor, whether it be the desktop window, an application window, or a control window. An application destroys a cursor by calling WinDestroyCursor- when the specified window loses the keyboard focus, for example.
====Position and Size====
====Position and Size====
An application can set the position (in window coordinates) of an existing cursor by calling WinCreateCursor, specifying the CURSOR_SETPOS flag. The cursor width is usually 0 (nominal border width is used) for text-insertion cursors. This is preferable to a value of 1, since such a fine width is almost invisible on a high-resolution monitor. The cursor width also can be related to the window size-for example, when a button control uses a dotted-line cursor around the button text to indicate focus. To change the cursor size, the application must destroy the current cursor and create a new one of the desired size.  
An application can set the position (in window coordinates) of an existing cursor by calling WinCreateCursor, specifying the CURSOR_SETPOS flag. The cursor width is usually 0 (nominal border width is used) for text-insertion cursors. This is preferable to a value of 1, since such a fine width is almost invisible on a high-resolution monitor. The cursor width also can be related to the window size-for example, when a button control uses a dotted-line cursor around the button text to indicate focus. To change the cursor size, the application must destroy the current cursor and create a new one of the desired size.
 
====Other Cursor Characteristics ====
====Other Cursor Characteristics ====
An application uses the WinCreateCursor function to specify information about the cursor rectangle and the clipping rectangle. WinCreateCursor specifies whether the cursor rectangle should be filled, framed, blinking, or halftone. In addition, the function specifies the clipping rectangle, in window coordinates, that controls the cursor clipping region. Probably the most efficient strategy is for the application to specify NULL, which causes the rectangle to clip the cursor to the window rectangle.  
An application uses the WinCreateCursor function to specify information about the cursor rectangle and the clipping rectangle. WinCreateCursor specifies whether the cursor rectangle should be filled, framed, blinking, or halftone. In addition, the function specifies the clipping rectangle, in window coordinates, that controls the cursor clipping region. Probably the most efficient strategy is for the application to specify NULL, which causes the rectangle to clip the cursor to the window rectangle.
 
===Cursor Visibility ===
===Cursor Visibility ===
An application can use the WinShowCursor function to show or hide a cursor. The operating system maintains a show level for the cursor: when the cursor is visible, the its show level is zero; each time the cursor is hidden, its show level is incremented; each time the cursor is shown, its show level is decremented. The show:hide relationship is 1:1, so the show level cannot drop below zero. When first creating a cursor, an application should show the cursor because the application creates the cursor with a show level of 1.
An application can use the WinShowCursor function to show or hide a cursor. The operating system maintains a show level for the cursor: when the cursor is visible, the its show level is zero; each time the cursor is hidden, its show level is incremented; each time the cursor is shown, its show level is decremented. The show:hide relationship is 1:1, so the show level cannot drop below zero. When first creating a cursor, an application should show the cursor because the application creates the cursor with a show level of 1.


The operating system automatically hides the cursor when the application calls WinBeginPaint; it shows the cursor when the application calls WinEndPaint. Therefore, there is no conflict with the cursor during WM_PAINT processing.  
The operating system automatically hides the cursor when the application calls WinBeginPaint; it shows the cursor when the application calls WinEndPaint. Therefore, there is no conflict with the cursor during WM_PAINT processing.
 
==Using Cursors==
==Using Cursors==
This section explains how to perform the following tasks:
This section explains how to perform the following tasks:
*Create and destroy a cursor
*Create and destroy a cursor
*Respond to a WM_SETFOCUS message
*Respond to a WM_SETFOCUS message
===Creating and Destroying a Cursor ===
===Creating and Destroying a Cursor ===
The following code fragment shows how an application should respond to a WM_SETFOCUS message when using a cursor in a particular window:
The following code fragment shows how an application should respond to a WM_SETFOCUS message when using a cursor in a particular window:

Latest revision as of 01:31, 24 May 2024

Reprint Courtesy of International Business Machines Corporation, © International Business Machines Corporation

Presentation Manager Programming Guide and Reference
  1. How to Use this Book
  2. Device Functions
  3. Direct Manipulation Functions
  4. Dynamic Data Formatting Functions
  5. Hooks and Procedures
  6. Profile Functions
  7. Spooler Functions
  8. Window Functions
  9. Message Processing
  10. Data Types
  11. Errors
  12. Atom Tables
  13. Button Controls
  14. Clipboards
  15. Combination Box
  16. Container Controls
  17. Control Windows
  18. Cursors
  19. Dialog Windows
  20. Direct Manipulation
  21. Drawing in Windows
  22. Dynamic Data Exchange
  23. Entry-Field Controls
  24. File Dialog Controls
  25. Font Dialog Controls
  26. Frame Windows
  27. Hooks
  28. Initialization Files
  29. Keyboard Accelerators
  30. List-Box Controls
  31. Menus
  32. Messages and Message Queues
  33. Multiple-Line Entry Field Controls
  34. Mouse and Keyboard Input
  35. Mouse Pointers and Icons
  36. Notebook Controls
  37. Painting and Drawing
  38. Presentation Parameters
  39. Resource Files
  40. Scroll-Bar Controls
  41. Slider Controls
  42. Spin Button Controls
  43. Static Controls
  44. Title-Bar Controls
  45. Value Set Controls
  46. Windows
  47. Window Classes
  48. Window Procedures
  49. Window Timers
  50. Appendices
  51. Notices
  52. Glossary

A cursor is a rectangle that can be shown at any location in a window, indicating where the user's next interaction with items on the screen will happen. This chapter describes how to create and use cursors in your PM applications.

About Cursors

Only one cursor appears on the screen at a time-either marking the text-insertion point (a text cursor) or indicating which items the user can interact with from the keyboard (a selection cursor). For example, when an entry field has the keyboard focus, it displays a blinking vertical bar to show the text-insertion point; however, when a button has the keyboard focus, the cursor appears as a halftone rectangle the size of the button. The operating system draws and blinks the cursor, freeing the application from handling these details. Notice that the cursor has no direct relationship with the mouse pointer.

Cursor Creation and Destruction

The system can use only one cursor at a time, so windows must create and destroy cursors as each windows gains and loses the keyboard focus. If an application attempts to use more than one cursor at a time, the results can be unpredictable and might affect other applications.

An application creates a cursor by calling WinCreateCursor. Generally, this is done when a window gains the keyboard focus. The application specifies the window in which to display the cursor, whether it be the desktop window, an application window, or a control window. An application destroys a cursor by calling WinDestroyCursor- when the specified window loses the keyboard focus, for example.

Position and Size

An application can set the position (in window coordinates) of an existing cursor by calling WinCreateCursor, specifying the CURSOR_SETPOS flag. The cursor width is usually 0 (nominal border width is used) for text-insertion cursors. This is preferable to a value of 1, since such a fine width is almost invisible on a high-resolution monitor. The cursor width also can be related to the window size-for example, when a button control uses a dotted-line cursor around the button text to indicate focus. To change the cursor size, the application must destroy the current cursor and create a new one of the desired size.

Other Cursor Characteristics

An application uses the WinCreateCursor function to specify information about the cursor rectangle and the clipping rectangle. WinCreateCursor specifies whether the cursor rectangle should be filled, framed, blinking, or halftone. In addition, the function specifies the clipping rectangle, in window coordinates, that controls the cursor clipping region. Probably the most efficient strategy is for the application to specify NULL, which causes the rectangle to clip the cursor to the window rectangle.

Cursor Visibility

An application can use the WinShowCursor function to show or hide a cursor. The operating system maintains a show level for the cursor: when the cursor is visible, the its show level is zero; each time the cursor is hidden, its show level is incremented; each time the cursor is shown, its show level is decremented. The show:hide relationship is 1:1, so the show level cannot drop below zero. When first creating a cursor, an application should show the cursor because the application creates the cursor with a show level of 1.

The operating system automatically hides the cursor when the application calls WinBeginPaint; it shows the cursor when the application calls WinEndPaint. Therefore, there is no conflict with the cursor during WM_PAINT processing.

Using Cursors

This section explains how to perform the following tasks:

  • Create and destroy a cursor
  • Respond to a WM_SETFOCUS message

Creating and Destroying a Cursor

The following code fragment shows how an application should respond to a WM_SETFOCUS message when using a cursor in a particular window:

    LONG   curXPos,curYPos,curWidth,curHeight;

    case WM_SETFOCUS:
        if (SHORT1FROMMP(mp2)) {

            /* Gain the focus. */
            WinCreateCursor(hwnd, curXPos, curYPos, curWidth, curHeight,
                CURSOR_SOLID | CURSOR_FLASH, (PRECTL) NULL);
            WinShowCursor(hwnd, TRUE);
        }
        else {

            /* Lose the focus. */
            WinDestroyCursor(hwnd);
        }

        return 0;