ITextServices::TxGetNaturalSize method (textserv.h)

Allows a control to be resized so it fits its content appropriately.

Syntax

HRESULT TxGetNaturalSize(
            DWORD          dwAspect,
            HDC            hdcDraw,
            HDC            hicTargetDev,
            DVTARGETDEVICE *ptd,
            DWORD          dwMode,
            const SIZEL    *psizelExtent,
  [in, out] LONG           *pwidth,
  [in, out] LONG           *pheight
);

Parameters

dwAspect

Type: DWORD

The aspect for the drawing. It can be any of the values from the DVASPECT enumeration.

hdcDraw

Type: HDC

The device context into which drawing occurs.

hicTargetDev

Type: HDC

The device context for which text should be formatted (that is, for WYSIWYG).

ptd

Type: DVTARGETDEVICE*

More information on the target device.

dwMode

Type: DWORD

The type of fitting requested. It can be one of the following.

Value Meaning
TXTNS_EMU
Use English Metric Units (EMUs) instead of pixels as the measuring units for this method's parameters.
TXTNS_FITTOCONTENT
Resize the control to fit the entire text by formatting the text to the width that is passed in. The text services object returns the height of the entire text and the width of the widest line.

For example, this should be done when the user double-clicks one of the control's handles.

TXTNS_FITTOCONTENT2
Resize the control so that it fits indented content.
TXTNS_FITTOCONTENT3
Resize the control so that it fits indented content and trailing whitespace.
TXTNS_FITTOCONTENTWSP
Resize the control so that it fits unindented content and trailing whitespace.
TXTNS_INCLUDELASTLINE
For a plain-text control, include the height of the final carriage return when calculating the size.
TXTNS_ROUNDTOLINE
Resize the control to show an integral number of lines (no line is clipped). Format enough text to fill the width and height that is passed in, and then return a height that is rounded to the nearest line boundary.
Note  The passed and returned width and height correspond to the view rectangle. The host should adjust back to the client rectangle as needed. Because these values represent the extent of the text object, they are input and output in HIMETRIC coordinates (each HIMETRIC unit is .01 millimeter), and measuring does not include any zoom factor. For a discussion of the zoom factor, see TxGetExtent.
 

psizelExtent

Type: const SIZEL*

Not supported.

[in, out] pwidth

Type: LONG*

The width for the fitting defined by dwMode.

[in, out] pheight

Type: LONG*

The height for the fitting defined by dwMode.

Return value

Type: HRESULT

If the method succeeds, the return value is S_OK.

If text services could not activate the object, the return value is one of the following HRESULT codes. For more information on COM error codes, see Error Handling in COM.

Return code Description
E_FAIL
Unable to determine correct size.
E_INVALIDARG
One or more arguments are not valid.
E_OUTOFMEMORY
Insufficient memory.

Remarks

The first four parameters are similar to equivalent parameters in ITextServices::TxDraw and give the same information. In the case where the lines must be recalculated, it should use these values the same ways as in ITextServices::TxDraw.

The pwidth and pheight parameters are in/out parameters. The host passes in the tentative width and height of the natural extent of the text object. The text services object compares these values against its current cached state, and if different, recalculate lines. Then, it computes and returns the natural size, as specified by dwMode.

Requirements

Requirement Value
Minimum supported client Windows Vista [desktop apps only]
Minimum supported server Windows Server 2003 [desktop apps only]
Target Platform Windows
Header textserv.h
DLL Msftedit.dll

See also

Conceptual

DVTARGETDEVICE

ITextServices

Other Resources

Reference

TxDraw

TxGetExtent

Windowless Rich Edit Controls