Share via


IViewObjectEx (Compact 2013)

3/26/2014

This interface is an extension derived from the IViewObject2 interface to provide support for:

  • Enhanced, flicker-free drawing for non-rectangular objects and transparent objects.
  • Hit testing for non-rectangular objects.
  • Control sizing.

Flicker free drawing

Containers can now choose between a variety of drawing algorithms, depending on their sophistication and the situation.

Flicker is created by redrawing the background before letting an object redraw its foreground as in the back-to-front drawing algorithm known as the Painter's Algorithm. There are essentially two ways to avoid flickering:

  • Draw into an off-screen bitmap and then copy the resulting image to the screen in one chunk. This technique might require significant additional resources to store the off-screen image, depending on the size of the region to drawn, the resolution, and the number of colors.
  • Draw front to back, instead of back to front, excluding each rectangular area from the clipping region as soon as its has been painted.
    One benefit of this technique is that each pixel is painted only once. Speed depends essentially on the performance of the clipping support.

Each technique has advantages and disadvantages, depending on the specific situation. There is no single algorithm that is most efficient in all situations.

Depending on the situation and their sophistication, containers can choose to use one or another, or a combination of both.

The IViewObjectEx interface provides methods to support both techniques or a combination of the two.

Simple containers can implement a simplistic back-to-front painting algorithm directly to the screen. The speed is likely to be high but so will flicker.

If flicker is to be reduced to a minimum, painting to an off-screen device context is the solution of choice.

If memory consumption is a problem, containers can use clipping to reduce the use of off-screen bitmaps.

To draw as flicker-free as possible without using an off-screen bitmap, the container will have to paint in two passes.

The first pass is done front to back. During that pass, each object draws regions of itself that are cheap enough to clip out efficiently and that it can entirely obscure. These regions are known as opaque. After each object is done, the container clips out the regions just painted to ensure that subsequent objects will not modify the bits on the screen.

During the second pass, which occurs back to front, each object draws its remaining parts - irregular, oblique, or text, which are in general difficult to clip out. Such parts are known as transparent. At this point, the container is responsible for clipping out any opaque, already painted regions in front of the object currently drawing.

The less painting during this second pass, the less flicker on the screen.

Clipping during the second pass may be very inefficient because the clipping region needs to be recreated for every object that has something to draw. This might be acceptable if not too many overlapping objects have irregular or transparent parts.

An object can tell its container ahead of time whether it wants to be called during this second pass.

If the container provides an off-screen bitmap to paint into, it can skip the first pass and ask every object to render itself entirely during the second pass.

In certain cases, the container can also decide that flicker is not a problem and use that same technique while painting directly on screen. For example, flicker might be acceptable when painting a form for the first time, but not when repainting.

Note

Although documented here, two pass drawing is not currently used by any containers.

Hit testing for non-rectangular objects

The IViewObjectEx interface supports hit detection for non-rectangular objects. Using the QueryHitPoint and QueryHitRect methods, the object can participate in the hit-test logic with the container.

Control Sizing

The IViewObjectEx interface allows controls to provide sizing hints as the user resizes the control. The control can specify a minimum and maximum size and can specify the nearest good size to a size requested by the user.

When to Implement

Implement this interface on objects that need to support efficient flicker-free drawing, non-rectangular hit testing, or control sizing. This interface is derived from the IViewObject2 interface, which in turn is derived from the IViewObject interface.

All IViewObjectEx methods described in this document that take or return a position assume that the location is expressed in HIMETRIC units relative to the origin of the object.

When to Use

Containers call the methods of this interface to draw objects in an efficient, flicker-free manner, to test whether points or rectangles are within the object, or to resize controls.

Methods

The following table shows the methods for this interface in the order that the compiler calls the methods. Like all COM interfaces, this interface inherits the methods for the IUnknown interface.

IUnknown method

Description

QueryInterface

Returns pointers to supported interfaces.

AddRef

Increments reference count.

Release

Decrements reference count.

Method

Description

Draw

Draws a representation of an object onto the specified device context.

Freeze

Freezes an aspect of the object's presentation so it does not change until the IViewObject::Unfreeze method is called.

GetAdvise

Retrieves the existing advisory connection on the object if there is one and returns the parameters used in the most recent call to the IViewObject::SetAdvise method.

GetColorSet

Returns the logical palette that the object uses for drawing in its IViewObject::Draw method with the corresponding parameters.

SetAdvise

Establishes a connection between the view object and an advise sink so the advise sink can be notified about changes in the object's view.

Unfreeze

Releases a previously frozen drawing.

IViewObject2 method

Description

GetExtent

Returns the size that the specified view object will be drawn on the specified target device.

IViewObjectEx methods

Description

GetNaturalExtent

Provides sizing hints from the container for the object to use as the user resizes it.

GetRect

Returns a rectangle describing a requested drawing aspect.

GetViewStatus

Returns information about the opacity of the object and what drawing aspects are supported.

QueryHitPoint

Indicates whether a point is within a given aspect of an object.

QueryHitRect

Indicates whether any point in a rectangle is within a given drawing aspect of an object.

Remarks

To determine whether the platform supports this interface, see Determining Supported COM APIs.

Requirements

Header

ocidl.h,
ocidl.idl

Library

ole32.lib,
uuid.lib

See Also

Reference

COM Interfaces
IViewObject2::GetExtent