Since your application will require several new variables, add the following statements to the beginning of your C-language source file:
char szStr[255]; /* general-purpose string buffer */
HCURSOR hSaveCursor; /* handle of current cursor */
HCURSOR hHourGlass; /* handle of hourglass cursor */
BOOL fTrack = FALSE; /* TRUE if left button clicked */
int OrgX = 0, OrgY = 0; /* original cursor position */
int PrevX = 0, PrevY = 0; /* current cursor position */
int X = 0, Y = 0; /* last cursor position */
RECT Rect; /* selection rectangle */
POINT ptCursor; /* x and y coordinates of cursor */
int repeat = 1; /* repeat count of keystroke */
In this example, the hSaveCursor and hHourGlass variables hold the cursor handles to be used for the lengthy operation. The fTrack variable holds a Boolean flag indicating whether a selection is in progress. The variables OrgX, OrgY, PrevX, and PrevY hold the original and current cursor positions as a selection is being made. OrgX and OrgY, along with the variables X and Y, hold the original and final coordinates of the selection when the selection is complete. The ptCursor structure holds the current position of the cursor in the client area. (This position is updated when the user presses an arrow key.) The Rect structure holds the current dimensions of the client area and is used to ensure that the cursor stays within the client area. The repeat variable holds the current repeat count for each keyboard motion.