| < Free Open Study > |
|
CComControlBase is one of the base classes to CComControl<>, the other being CWindowImpl<>, which we examined in the previous chapter. CComControlBase provides quite a bit of functionality to an ActiveX control, and can be broken down into the following categories:
CComControlBase maintains all the pointers necessary to communicate with the container. Typically you can leave well enough alone; however, each member is reachable from your derived class, and is listed in online help.
CComControlBase defines all of the stock property data members for use by CStockPropImpl<>.
CComControlBase defines a number of methods to grab "ambient properties" from your container.
CComControlBase intercepts the client's request to render the control, normalizes the device context, fills the _ATL_DRAWINFO structure, and calls OnDraw().
CComControlBase defines the SetDirty() and GetDirty() methods to flag a property that should be saved (or determine if it needs to be saved).
Let's begin with the SetDirty() method. When you change the value of a custom property, you need to somehow inform the control that the new value should be saved when a container is asking to do so. CComControlBase defines a BOOL data member (m_bRequires- Save) to hold the current "dirty value." The way to tell your container a property is now different (and should be saved) is to call SetDirty() within the implementation of each and every [propput] method. GetDirty() returns the state of the dirty flag. The implementation of each method is trivial:
// Mark the control "dirty" so the container will save it void SetDirty(BOOL bDirty) { m_bRequiresSave = bDirty; } // Obtain the dirty state for the control BOOL GetDirty() { return m_bRequiresSave ? TRUE : FALSE; }
Here is how the ShapeType property could make use of this new functionality:
// This iteration of ShapeType now sets the dirty flag to tell the container // it should be saved. STDMETHODIMP CShapesControl::put_ShapeType(CURRENTSHAPE newVal) { // Is this change OK with the container? if(FAILED(FireOnRequestEdit(1))) // [id(1)] = ShapeType return S_FALSE; // Check bounds. if(newVal >= shapeCIRCLE && newVal <= shapeRECTANGLE) m_shapeType = newVal; // Set dirty flag. SetDirty(TRUE); // Redraw the view (i.e., call OnDraw()) FireViewChange(); // Tell container we have changed the value. FireOnChanged(1); // [id(1)] = ShapeType return S_OK; }
| < Free Open Study > |
|