Broad Network


Predefined Windows Cursors

Window Classes – Part 4

Volume - Windows User Interface

Forward: In this part of the series, we look at predefined windows cursors.

By: Chrysanthus Date Published: 29 Aug 2012

Introduction

This is part 4 of my series, Window Classes. I assume you have read all the previous tutorials before this one. You should be reading the tutorials in the order given. In this part of the series, we look at predefined windows cursors.

Note: If you cannot see the code or if you think anything is missing (broken link, image absent), just contact me at forchatrans@yahoo.com. That is, contact me for the slightest problem you have about what you are reading.

WNDCLASSEX and the Cursor
The WNDCLASSEX struct is,

typedef struct tagWNDCLASSEX {
  UINT      cbSize;
  UINT      style;
  WNDPROC   lpfnWndProc;
  int       cbClsExtra;
  int       cbWndExtra;
  HINSTANCE hInstance;
  HICON     hIcon;
  HCURSOR   hCursor;
  HBRUSH    hbrBackground;
  LPCTSTR   lpszMenuName;
  LPCTSTR   lpszClassName;
  HICON     hIconSm;
} WNDCLASSEX, *PWNDCLASSEX;

A class is a set of window characteristics. Any window can choose a particular registered class when it is being created. The characteristics are assigned as values to the members of the WNDCLASSEX struct. Our interest in this tutorial is the hCursor member of the struct.

The Cursor
The cursor here means the mouse pointer. The cursor can have different types of shapes. Windows has predefined shapes, which you can use. The identifiers of these predefined cursors (shapes) and their meanings are:

IDC_APPSTARTING: Standard Arrow and Small Hourglass
IDC_ARROW: Standard Arrow
IDC_CROSS: Crosshair
IDC_IBEAM: Text I-Beam
IDC_NO: Slashed Circle
IDC_SIZEDALL:
IDC_SIZENESW: Double-pointed Arrow pointing Northeast and Southwest
IDC_SIZENS: Double-pointed Arrow pointing North and South.
IDC_SIZENWSE: Double-pointed Arrow pointing Northwest and Southeast.
IDC_SIZEWE: Double-pointed arrow pointing west and east.
IDC_UPARROW: Vertical Arrow
IDC_WAIT: Hourglass.

Assigning to hCursor
Programming the User Interface is rather tricky. You do not assign any of the above identifiers to the hCursor member of the WNDCLASSEX struct. What has to be assigned to hCursor is a handle of the cursor and not the identifier of the cursor. And so the User Interface provides a function called the loadCursor function. This function returns a handle to the cursor, if it succeeds in its operation or NULL if it fails.

Assume that you want the Standard Arrow cursor. The identifier is IDC_ARROW. For the hCursor member, you would type:

    wcx.hCursor = LoadCursor(NULL, IDC_ARROW);

Here, wcx is the identifier of your choice for the struct. hCursor is the cursor member in the struct declared already by the User Interface. LoadCursor is the function that returns a handle to the cursor. The first argument in the function is NULL when you want a predefined cursor. The second argument is the identifier of the predefined cursor. This identifier has already been declared by the User Interface, unknown to you.

You can use the example code in one of the tutorials titled, “Your First Window” of the previous series to try some of the above cursors.

Let us end here. We continue in the next part of the series.

Chrys

Related Courses

C++ Course
Relational Database and Sybase
Windows User Interface
Computer Programmer – A Jack of all Trade – Poem

Comments

Become the Writer's Fan
Send the Writer a Message