Help Center

GdipGetStringFormatFlagsfunction

Gets the string format flags for a **StringFormat** object.

Graphicsfunctiondocumented

Syntax

FUNCTION GdipGetStringFormatFlags (BYVAL format AS CONST GpStringFormat PTR, BYVAL flags AS INT_ PTR) AS GpStatus

Parameters

NameDescription
format[in] Pointer to the StringFormat object.
flags[out] Pointer to a variable that receives a value that indicates which string format flags are set for this StringFormat object. This value can be any combination (the result of a bitwise OR applied to two or more elements) of elements of the StringFormatFlags enumeration.

Description

Gets the string format flags for a StringFormat object.

Example

' ======================================================================================== ' The following example creates a StringFormat object, sets the string's format flags, and ' then gets the 32-bit value that contains the format flags and stores it in a variable. ' The code then creates another StringFormat object and uses the stored format flags value ' to set the format flags of the second StringFormat object. Next, the code uses the second ' StringFormat object to draw a formatted string. The code also draws the string's layout ' rectangle. ' ======================================================================================== SUB Example_GetStringFormatFlags (BYVAL hdc AS HDC)

DIM hStatus AS LONG

' // Create a graphics object from the device context DIM graphics AS GpGraphics PTR hStatus = GdipCreateFromHDC(hdc, @graphics)

' // Get the DPI scaling ratios DIM dpiX AS SINGLE hStatus = GdipGetDpiX(graphics, @dpiX) DIM rxRatio AS SINGLE = dpiX / 96 DIM dpiY AS SINGLE hStatus = GdipGetDpiY(graphics, @dpiY) Dim ryRatio AS SINGLE = dpiY / 96 ' // Set the scale transform hStatus = GdipScaleWorldTransform(graphics, rxRatio, ryRatio, MatrixOrderPrepend)

' // Create the font DIM fontFamily AS GpFontFamily PTR hStatus = GdipCreateFontFamilyFromName("Times New Roman", NULL, @fontFamily) DIm font AS GpFont PTR IF hStatus = StatusOk THEN

hStatus = GdipCreateFont(fontFamily, AfxGdipPointsToPixels(18, TRUE), FontStyleRegular, UnitPixel, @font)
  GdipDeleteFontFamily(fontFamily)

END IF

' // Create a StringFormat object, and set its format flags. DIM format AS GpStringFormat PTR hStatus = GdipCreateStringFormat(0, LANG_NEUTRAL, @format) hStatus = GdipSetStringFormatFlags(format, StringFormatFlagsDirectionVertical OR StringFormatFlagsNoFitBlackBox)

' // Get the format flags from the StringFormat object. DIM flags AS LONG hStatus = GdipGetStringFormatFlags(format, @flags)

' // Create a second StringFormat object with the same flags. DIM format2 AS GpStringFormat PTR hStatus = GdipCreateStringFormat(0, LANG_NEUTRAL, @format2) hStatus = GdipSetStringFormatFlags(format2, flags)

' // Create a solid brush DIM solidBrush AS GpSolidFill PTR hStatus = GdipCreateSolidFill(ARGB_RED, @solidBrush)

' // Draw the string using the second StringFormat object DIM wszText AS WSTRING * 64 = "This text is vertical because of a format flag." DIM rcf AS GpRectF = (30, 30, 150, 200) hStatus = GdipDrawString(graphics, wszText, LEN(wszText), font, @rcf, format2, solidBrush)

' // Draw the rectangle that encloses the text DIM pen AS GpPen PTR hStatus = GdipCreatePen1(ARGB_RED, 1, UnitPixel, @pen) hStatus = GdipScalePenTransform(pen, rxRatio, ryRatio, MatrixOrderPrepend) hStatus = GdipDrawRectangle(graphics, pen, rcf.x, rcf.y, rcf.width, rcf.height)

' // Cleanup IF font THEN GdipDeleteFont(font) IF solidBrush THEN GdipDeleteBrush(solidBrush) IF pen THEN GdipDeletePen(pen) IF format2 THEN GdipDeleteStringFormat(format2) IF format THEN GdipDeleteStringFormat(format) IF graphics THEN GdipDeleteGraphics(graphics)

END SUB ' ========================================================================================

Reference

  • Defined in AfxNova/AfxGdiPlus.bi:2399
  • Documented in Graphics/GdiPlus Flat Api/GdiPlusStringFormat.md
  • Topic: GdiPlusStringFormat