Visual Component Interfaces

The IVisual interface shown in IVisual interface defines methods for rendering objects to a device context. The OnPrepareDC() method gives visual components an opportunity to set up the device context prior to drawing. OnPrepareDC() is typically used to set mapping modes, window and viewport extents, select pens and brushes, etc. The OnRestoreDC() method returns the device context back to its original state. The Draw() method does the actual rendering of the visual component to the device context.

IVisual interface

class __declspec(uuid("E7707E00-1E4F-4f4e-A525-290CFA9C1EF3"))

IVisual : public IQueryGuid, public IRefCount

{

public:

virtual void Draw(CDC* pDC) = 0;

virtual void OnPrepareDC(CDC* pDC) = 0;

virtual void OnRestoreDC(CDC* pDC) = 0;

};

As mentioned previously, a visual component has two-dimensional bounds. The IBounds2D interface shown in IBounds2D interface provides methods for manipulating the bounds of a visual component.

IBounds2D interface

class __declspec(uuid("A332FE8E-B30D-47ee-AF1B-7E863FDEFFE5"))

IBounds2D : public ISize2D

{

public:

virtual CRect GetBounds() const = 0;

virtual CPoint GetOrigin() const = 0;

virtual CPoint SetOrigin(int x, int y) = 0;

virtual CPoint MoveOrigin(int xOff,int yOff) = 0;

};

The IBounds2D interface is derived from the ISize2D interface shown in ISize2D interface. These two interfaces are distinct because an object might have two-dimensional size, but no origin. The IBounds2D extents the ISize2D interface by adding methods for accessing the origin.

ISize2D interface

class __declspec(uuid("A989AFCB-D665-4faf-93A6-34E378BF75E0")

ISize2D : public IQueryGuid, public IRefCount

{

public:

virtual CSize GetSize() const = 0;

virtual CSize SetSize(int cx, int cy) = 0;

};