Share via


IViewObject::Draw (Compact 2013)

3/26/2014

This method draws a representation of an object onto the specified device context.

Syntax

HRESULT Draw( 
  DWORD dwAspect, 
  LONG lindex, 
  void* pvAspect, 
  DVTARGETDEVICE* ptd, 
  HDC hicTargetDev, 
  HDC hdcDraw, 
  const LPRECTL lprcBounds, 
  const LPRECTL lprcWBounds, 
  BOOL (*) (DWORD) pfnContinue, 
  DWORD dwContinue
);

Parameters

  • dwAspect
    [in] Specifies the aspect to be drawn, that is, how the object is to be represented. Representations include content, an icon, a thumbnail, or a printed document.

    Valid values are taken from the enumeration DVASPECT.

    Windowless objects allow only DVASPECT_CONTENT, DVASPECT_OPAQUE, and DVASPECT_TRANSPARENT.

  • lindex
    [in] Portion of the object that is of interest for the draw operation.

    Its interpretation varies depending on the value in the dwAspect parameter. For more information, see the DVASPECT enumeration.

  • pvAspect
    [in] Pointer to additional information in a DVASPECTINFO structure that enables drawing optimizations depending on the aspect specified.

    Newer objects and containers that support optimized drawing interfaces support this parameter.

    Older objects and containers that do not support optimized drawing interfaces always specify NULL for this parameter.

  • ptd
    [in] Pointer to the DVTARGETDEVICE structure that describes the device that the object is to be rendered for.

    If NULL, the view should be rendered for the default target device (typically the display).

    A value other than NULL is interpreted in conjunction with hicTargetDev and hdcDraw. For example, if hdcDraw specifies a printer as the device context, the ptd parameter points to a structure describing that printer device.

    The data might actually be printed if hicTargetDev is a valid value or it might be displayed in print preview mode if hicTargetDev is NULL.

  • hicTargetDev
    [in] Information context for the device indicated by the ptd parameter from which the object can extract device metrics and test the device's capabilities.

    If ptd is NULL, the object should ignore the value in the hicTargetDev parameter.

  • hdcDraw
    [in] Device context on which to draw.

    For a windowless object, do the following:

    • The hdcDraw parameter should be in MM_TEXT mapping mode with its logical coordinates matching the client coordinates of the containing window.
    • The device context should be in the same state as the one normally passed by a WM_PAINT message.
  • lprcBounds
    [in] Long pointer to a RECTL structure that specifies the rectangle on hdcDraw and in which the object should be drawn.

    This parameter controls the positioning and stretching of the object.

    This parameter should be NULL to draw a windowless in-place active object. In every other situation, NULL is not a legal value and should result in an E_INVALIDARG error code.

    If the container passes a non-NULL value to a windowless object, the object should render the requested aspect into the specified device context and rectangle.

    A container can request this from a windowless object to render a second, nonactive view of the object or to print the object.

  • lprcWBounds
    [in] If hdcDraw is a metafile device context, this parameter is a long pointer to a RECTL structure specifying the bounding rectangle in the underlying metafile. The rectangle structure contains the window extent and window origin.

    These values are useful for drawing metafiles.

    The rectangle indicated by lprcBounds is nested inside this lprcWBounds rectangle; they are in the same coordinate space.

    If hdcDraw is not a metafile device context; lprcWBounds will be NULL.

  • pfnContinue
    [in] Pointer to a callback function that the view object should call periodically during a lengthy drawing operation to determine whether the operation should continue or be canceled.

    This function returns TRUE to continue drawing.

    It returns FALSE to stop the drawing in which case Draw returns DRAW_E_ABORT.

  • dwContinue
    [in] Specifies a value to pass as a parameter to the function pointed to by the pfnContinue parameter.

    Typically, dwContinue is a pointer to an application-defined structure needed inside the callback function.

Return Value

This method supports the standard return values E_INVALIDARG and E_OUTOFMEMORY, as well as the values described in the following table.

Value

Description

S_OK

The object was drawn successfully.

OLE_E_BLANK

No data to draw from.

DRAW_E_ABORT

Draw operation aborted.

VIEW_E_DRAW

Error in drawing.

DV_E_LINDEX

Invalid value for lindex; currently only -1 is supported.

DV_E_DVASPECT

Invalid value for dwAspect.

OLE_E_INVALIDRECT

Invalid rectangle.

Remarks

A container application issues a call to Draw to create a representation of a contained object. This method draws the specified piece (lindex) of the specified view (dwAspect and pvAspect) on the specified device context (hdcDraw).

Formatting, fonts, and other rendering decisions are made on the basis of the device specified by the ptd parameter.

There is a relationship between the dwDrawAspect value and the lprcbounds value. The lprcbounds value specifies the rectangle on hdcDraw into which the drawing is to be mapped.

For DVASPECT_THUMBNAIL, DVASPECT_ICON, and DVASPECT_SMALLICON, the object draws whatever it wants to draw, and it maps it into the space given in the best way.

Some objects might scale to fit while some might scale to fit but preserve the aspect ratio. In addition, some might scale so the drawing appears at full width, but the bottom is cropped.

The container can use IOleObject::SetExtent to suggest a size, but it has no control over the rendering size. In the case of DVASPECT_CONTENT, the Draw implementation should either use the extents given by SetExtent or use the bounding rectangle given in the lprcBounds parameter.

To maintain compatibility with older objects and containers that do not support drawing optimizations, all objects, rectangular or not, are required to maintain an origin and a rectangular extent.

This allows the container to still consider all its embedded objects as rectangles and to pass them appropriate rendering rectangles in Draw.

An object's extent depends on the drawing aspect. For nonrectangular objects, the extent should be the size of a rectangle covering the entire aspect.

By convention, the origin of an object is the top left corner of the rectangle of the DVASPECT_CONTENT aspect.

In other words, the origin always coincides with the top left corner of the rectangle maintained by the object's site, even for a nonrectangular object.

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

Note to Callers

The value of hicTargetDevice is typically an information context for the device. However, it can be a full device context.

Note to Implementers

If you are writing an object handler (such as the default handler) that implements Draw by playing a metafile, you must treat SetPaletteEntries metafile records in a special way because of the Windows behavior.

The Windows function PlayMetaFile sets these palette entries to the foreground. You must override this default by setting them to the background palette. Use EnumMetaFile to do this. Enhanced metafiles are always recorded with the background palette so there is no need to do it manually.

Requirements

Header

Oleidl.h,
oleidl.idl

Library

oleaut32.lib,
uuid.lib

See Also

Tasks

Determine Supported COM APIs

Reference

IViewObject
DVASPECT
DVASPECTINFO
DVTARGETDEVICE
IOleObject::SetExtent

Other Resources

SetPaletteEntries
RECTL