SKETCH/SKETCNTR

The SKETCH sample demonstrates how to capture mouse/stylus messages and use them to draw on the screen. The SKETCNTR sample is a simple dialog box application that provides a container for the CSketcCtl control.

The CSKETCNTRDlg dialog box class has one public variable, m_Sketch, which is a CSketcCtl object. The dialog box also has an "Erase" button.

The CSketcCtl class implements the ISketcCtl interface in addition to the IUnknown and IDispatch interfaces. It supports a dual interface, so you can either access the ISketcCtl methods through IDispatch::Invoke or call them directly by way of the vtable. ISketcCtl exposes three methods, get_PenWidth, put_PenWidth, and Erase. The CSketcCtl class has seven data members. The left, right, top, and bottom data members contain the x an y coordinates of the lop left and bottom right corners, respectively, of the rectangle occupied by the control. These members are used for drawing and erasing the control. The bLBDown member indicates whether the stylus tip is touching the touch screen (which is equivalent to the left button being pressed on a mouse). The m_PenWidth member specifies the current width in pixels of the pen. The line member is an array of two POINT structures. The POINT at line[0] represents the coordinates for the beginning of a line, and the POINT at line[1] represents the coordinates for the end of the line.

When you touch the dialog box with the stylus, in the area occupied by the Sketch control, it sends the Sketch Control a WM_LBUTTONDOWN message. The CSketcCtl::OnLButtonDown handler sets bLBDown to TRUE, and assigns the coordinates of the stylus tip to the POINT at line[0]. When you move the stylus on the touch screen, it sends a WM_MOUSEMOVE message. The CSketcCtl::OnMouseMove handler sets the value at line[1] to the current coordinates of the stylus tip, draws a line from the point represented by line[0] to the point represented by line[1], then replaces the value at line[0] with the current value at line[1]. When you lift the stylus from the screen, it sends a WM_LBUTTONUP message. The CSketcCtl::OnLButtonUp handler sets bLBDown to FALSE. When you tap the "Erase" button on the CSKETCNTRDlg dialog box, it calls the Sketch control's ISketcCtl::Erase method, which erases the contents of the control.

The dialog box doesn't provide a way to access the ISketcCtl::get_PenWidth and ISketcCtl::put_PenWidth methods, but you could easily add features to take advantage of this functionality. These methods simply set and retrieve the value of the CSketcCtl::m_PenWidth member, which is used to set the pen width in the OnMouseMove handler.

This sample demonstrates the following keywords:

GetDC

Polyline

Rectangle

ReleaseDC

SelectObject

You can find the SKETCH project files in the Wce\Samples\Atl\SKETCH directory.

You can find the SKETCNTR project files in the Wce\Samples\Atl\SKETCNTR directory.

To build the SKETCH and SKETCNTR samples, follow the procedure described in Building the Sample Applications, selecting one or more of the following project configurations.