The POLYGON sample demonstrates how to implement custom properties, events, and a property page for an ATL control. The POLYCNTR sample is a simple dialog box application that provides a container for the CPolyCtl control.
The CPolyCntrDlg dialog box class has one public variable, m_Polygon, which is a CPolyCtl object.
The CPolyCtl class implements the IPolyCtl interface in addition to the IUnknown and IDispatch interfaces. It supports a dual interface, so you can either access the IPolyCtl methods through IDispatch::Invoke or call them directly by way of the vtable. IPolyCtl exposes two methods, get_Sides and put_Sides. CPolyCtl also has three data members. The m_clrFillColor member is an OLE_COLOR value that contains the color with which to draw the polygon. The m_nSides member contains the number of sides in the current polygon. The m_arrPoint member is an array of 100 POINT structures, that contains the coordinates of all the vertices of the polygon.
The CPolyCtl constructor initializes m_nSides to three, and m_clrFillColor to green. The OnDraw handler draws a black circle on a white background. Then it calculates the coordinates of the vertices of and equilateral polygon with m_nSides sides, and draws the polygon inside the circle, filling it with the color specified by the m_clrFillColor data member. When you tap the screen with the stylus, inside the control, the OnLButtonDown handler captures the coordinates at which the stylus tip touched the touch screen. If the x coordinate is greater than the y coordinate, the control fires the ClickIn event. Otherwise, it fires the ClickOut event. (Windows CE doesn't support the WM_RBUTTONDOWN message, so the OnRButtonDown handler isn't used.)
When the CPolyCntrDlg dialog box receives the ClickIn event, its OnClickInPolyCtl1 event handler uses the CPolyCtl control's dispinterface to invoke the IPolyCtl::get_Sides method, which returns the value of the control's m_nSides data member. OnClickInPolyCtl1 increments this value by one and passes the new value to the IPolyCtl::put_Sides method, again using the dispinterface. IPolyCtl::put_Sides assigns this value to the Polygon control's m_nSides member and calls CComControl::FireViewChange to notify the container that the control should be redrawn. When the CPolyCntrDlg object receives the ClickOut event, it uses the dispinterface in the same way to decrement the value of the control's m_nSides member.
The Polygon control has a property page, CPolyProp, that you can use during the design stage, when embedding this control in a container. The property page contains an edit control labeled Sides. When you enter a number in this edit control and tap the Apply button, the property page invokes IPolyCtl::put_Sides on the Polygon control, passing it the number you entered. IPolyCtl::put_Sides verifies that the number is greater than two and less than 101, and assigns it's value to CPolyCtl::m_nSides. It then fires CComControl::FireViewChange to notify the container that the control should be redrawn.
This sample demonstrates the following keywords:
You can find the POLYGON project files in the Wce\Samples\Atl\POLYGON directory.
You can find the POLYCNTR project files in the Wce\Samples\Atl\POLYCNTR directory.
To build the POLYGON and POLYCNTR samples, follow the procedure described in Building the Sample Applications, selecting one or more of the following project configurations.