67.2.1 Using the Line Functions to Draw Markers

You can use the line functions to draw markers. A marker is a symbol that is centered over a point. Drawing applications use markers to designate starting points, ending points, and control points. Spreadsheet applications use markers to designates points of interest on a chart or graph. The following illustration shows a screen from a drawing application that uses markers to designate the endpoints and control points for a Bezier spline:

Using Markers to Designate Control and Endpoints

The function that draws the markers is very simple, it receives the coordinates of the cursor when the user presses the left-button and then draws two intersecting lines that are 20 pixels in length using the MoveToEx and LineTo functions:

void Marker(LONG x, LONG y, HWND hwnd)

{

HDC hdc;

hdc = GetDC(hwnd);

MoveToEx(hdc, (int)x-10, (int)y, (LPPOINT)NULL);

LineTo(hdc, (int)x+10, (int)y);

MoveToEx(hdc, (int)x, (int)y-10, (LPPOINT)NULL);

LineTo(hdc, (int)x, (int)y+10);

ReleaseDC(hwnd, hdc);

}

When the user presses the mouse, the coordinates of the cursor are stored in the lParam parameter of the WM_LBUTTONDOWN message. The following code demonstrates how an application obtains these coordinates, how it determines that the coordinates lie within its client area, and finally, how these coordinates are passed to the application-defined Marker function to draw the marker:

case WM_LBUTTONDOWN:

if (bCollectPoints && index<32){

/* Create region from client area. */

GetClientRect(hWnd, &rect);

hrgn = CreateRectRgn(rect.left, rect.top,

rect.right, rect.bottom);

ptTmp = MAKEPOINTS((POINTS FAR *)lParam);

ptMouseDown[index].x = (LONG)ptTmp.x;

ptMouseDown[index].y = (LONG)ptTmp.y;

/* Test for hit in client rect. */

if (PtInRegion(hrgn, ptMouseDown[index].x,

ptMouseDown[index].y)){

/* If hit occurs, record the mouse coordinates */

Marker(ptMouseDown[index].x, ptMouseDown[index].y, hWnd);

index++;

}

}

break;