ITextServices2::TxGetNaturalSize2 method

Resizes a control so it fits its content appropriately. This method is similar to TxGetNaturalSize, but also retrieves the ascent of the top line of text.

Syntax


virtual HRESULT TxGetNaturalSize2(
  DWORD dwAspect,
  HDC hdcDraw,
  HDC hicTargetDev,
  DVTARGETDEVICE *ptd,
  DWORD dwMode,
  const SIZEL *psizelExtent,
  LONG *pwidth,
  LONG *pheight,
  LONG *pascent
) = 0;

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.

ValueMeaning
TXTNS_EMU

Use English Metric Units (EMUs) instead of pixels as the measuring units (both ways) 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 white space.

TXTNS_FITTOCONTENTWSP

Resize the control so that it fits unindented content and trailing white space.

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 0.01 millimeter), and measuring does not include any zoom factor. For a discussion of the zoom factor, see TxGetExtent.

 

psizelExtent

Type: const SIZEL*

Sizes of extents (in HIMETRIC units) to use for zooming.

pwidth

Type: LONG*

The width for the fitting defined by dwMode.

pheight

Type: LONG*

The height for the fitting defined by dwMode.

pascent

Type: LONG*

For single-line controls, receives the ascent (units above the baseline) of characters in the top line of text.

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 codeDescription
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, TxGetNaturalSize2 uses these values in 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, recalculates lines. Then, it computes and returns the natural size, as specified by dwMode.

Examples

The following example shows how to initialize the psizelExtent parameter for to a zoom factor of 1:1. The ellipses indicate code that you need to provide.



LONG dxpi = GetDeviceCaps(hdc, LOGPIXELSX);
LONG dypi = GetDeviceCaps(hdc, LOGPIXELSY);
LONG dyAscent = 0;
LONG dx = ... ;  // Text image width, in pixels 
LONG dy = ... ;  // Text image height, in pixels 
SIZEL sizel;     // dx and dy, in HIMETRIC

ITextServices2 *pserv = ... ; // Interface for single-line control

sizel.cx = MulDiv(dx, HIMETRIC_PER_INCH, dxpi); 
sizel.cy = MulDiv(dy, HIMETRIC_PER_INCH, dypi);

pserv->TxGetNaturalSize2(DVASPECT_DOCPRINT, hdc, hdcNil, pNil,
    TXTNS_FITTOCONTENT, &sizel, &dx, &dy, &dyAscent))) 


Requirements

Minimum supported client

Windows 8 [desktop apps only]

Minimum supported server

Windows Server 2012 [desktop apps only]

Header

Textserv.h

DLL

Msftedit.dll

See also

ITextServices2

 

 

Community Additions

ADD
Show:
© 2014 Microsoft