Objective Views : Chapter 10 Symbols : Creating Symbols on the Fly
Creating Symbols on the Fly
Symbols can also be created programmatically. Remember, a symbol is a component that has the capability of linking to another symbol and of bearing a label. Each component can also act as a composite, which means it can consist of other components. Usually, a symbol is a collection of primitive components.
You can create a new symbol by adding subcomponents to it. You can collect subcomponents into a set and then pass it to the Create() method, as in Example 12.
Example 12 – Adding a collection of subcomponents to a symbol
CODSymbolComponent* pNewSymbol = new CODSymbolComponent();
pNewSymbol->Create(&setComponents);
Or, you can add the subcomponents one by one using the AppendChild() or InsertChild() methods, as in Example 13.
Example 13 – Adding subcomponents individually to a symbol
CODImageComponent* pImageComp = new CODImageComponent();
pImageComp->Create(IDR_IMAGE1, pDC);
 
CODSymbolComponent* pNewSymbol = new CODSymbolComponent();
pNewSymbol->AppenChild(pImageComp)
Remember that each composite component has its own coordinate system. If you added a rectangle with corners at (0,0) and (10,10), it would appear at the top left corner of the symbol whenever the symbol is displayed on the screen.