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.
HRESULT TxGetNaturalSize2( DWORD dwAspect, HDC hdcDraw, HDC hicTargetDev, DVTARGETDEVICE *ptd, DWORD dwMode, const SIZEL *psizelExtent, LONG *pwidth, LONG *pheight, LONG *pascent );
The aspect for the drawing. It can be any of the values from the DVASPECT enumeration.
The device context into which drawing occurs.
The device context for which text should be formatted (that is, for WYSIWYG).
More information on the target device.
The type of fitting requested. It can be one of the following.
||Use English Metric Units (EMUs) instead of pixels as the measuring units (both ways) for this method's parameters.|
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.
||Resize the control so that it fits indented content.|
||Resize the control so that it fits indented content and trailing white space.|
||Resize the control so that it fits unindented content and trailing white space.|
||For a plain-text control, include the height of the final carriage return when calculating the size.|
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.
Type: const SIZEL*
Sizes of extents (in HIMETRIC units) to use for zooming.
The width for the fitting defined by dwMode.
The height for the fitting defined by dwMode.
For single-line controls, receives the ascent (units above the baseline) of characters in the top line of text.
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.
||Unable to determine correct size.|
||One or more arguments are not valid.|
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.
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)))
|Minimum supported client||Windows 8 [desktop apps only]|
|Minimum supported server||Windows Server 2012 [desktop apps only]|