This function uses GDI+ to draw text on the designated object.

[C++Builder]     BOOL IKDrawString(LPVOID DeviceValue, LPRECT PrintRect, short BrushType, short Style, HANDLE imgHandle, short TextRenderingHint, int FormatFlags, PTR_IKPRINT_TEXTINFO TextInfo, LPCSTR Text, BYTE DeviceMode);
[Delphi]         function IKDrawString(DeviceValue: THandle; var PrintRect: TRect; BrushType, Style: Smallint; imgHandle: THandle; TextRenderingHint: Smallint; FormatFlags: Integer; var TextInfo: IKPRINT_TEXTINFO; Text: PChar; DeviceMode: Byte): LongBool;

Parameters

Name Explanation
DeviceValue The device context or the raster image data (i.e. Hdc or ImageHandle) depending on the DeviceMode parameter
PrintRect The structure that sets the start position of the text or the area within which the text is drawn.
BrushType Sets the brush type (0: Solid, 1: Hatch, 2: Texture, 4: Gradiation)
Style Sets the style for each brush (Disabled when BrushType is 0)
imgHandle The memory handle of the raster image used with the Texture Brush (BrushType=4)
TextRenderingHint Refers to the text rendering mode (Default is 0)
FormatFlags Format information for the text string (Default is 0)
TextInfo The structure that sets the drawing information
Text The text to be drawn (the terminus is NULL)
DeviceMode The designated object where the text is drawn (0: Screen, 1: Printer, 2: Image data)

Return Value

Returns True (nonzero) if successful. Returns False (0) if unsuccessful.

Explanation

The IKDrawString function uses GDI+ to draw text on the designated object. If the right and bottom members of PrintRect parameter are set to 0 then the text will be drawn with a start position determined by the left and top members of PrintRect parameter. If the right and bottom members of PrintRect parameter are set to values other than 0, then the text will be drawn within a rectangle defined by the left, top, right, and bottom members of PrintRect parameter. Any text that cannot fit within this rectangle will be cut.

Supported designated objects are the screen, printer, or image data)

To draw text using the IKDrawString function, please set the following members of TextInfo parameter: TextColor1, Alpha1, TextColor2, Alpha2, FontName, FontSize, CharAngle, HCentering, VCentering, HotkeyPrefix.

When the HotkeyPrefix member is set to values other than 1, prefixed string functionality cannot be used.

The TextColor1 and Alpha1 members of TextInfo parameter relate to the following: Solid Brush: brush color; Hatch Brush: line color; Gradiation Brush: start color for lined gradiation. The TextColor2 and Alpha2 members relate to the following: Hatch Brush: background color between the hatch lines; Gradiation Brush: end color for lined gradiation.

If using the gradiation brush (BrushType=4), please set the left, top, right,and bottom members of PrintRect.

To execute this function, it is first necessary to execute the IKPrintGdipStart function.

If the DeviceMode parameter is 0 or 2 (the designated object is the screen or the image data) then the left, top, right, bottom members of PrintRect are in pixel units.

If the DeviceMode parameter is 1 (the designated object is the printer) then the left, top, right, bottom members of PrintRect parameter are in 0.1mm units.

The style settings for each brush

For the Hatch Brush

Value Explanation
0 A pattern of horizontal lines
1 A pattern of vertical lines
2 A pattern of diagonal lines from top left to bottom right
3 A pattern of diagonal lines from top right to bottom left
4 A pattern of horizontal and vertical lines that cross
5 A pattern of crisscross diagonal lines. Antialias has been applied to the lines
6 Specifies a 5-percent hatch. The ratio of foreground color to background color is 5:100
7 Specifies a 10-percent hatch. The ratio of foreground color to background color is 10:100
8 Specifies a 20-percent hatch. The ratio of foreground color to background color is 20:100
9 Specifies a 25-percent hatch. The ratio of foreground color to background color is 25:100
10 Specifies a 30-percent hatch. The ratio of foreground color to background color is 30:100
11 Specifies a 40-percent hatch. The ratio of foreground color to background color is 40:100
12 Specifies a 50-percent hatch. The ratio of foreground color to background color is 50:100
13 Specifies a 60-percent hatch. The ratio of foreground color to background color is 60:100
14 Specifies a 70-percent hatch. The ratio of foreground color to background color is 70:100
15 Specifies a 75-percent hatch. The ratio of foreground color to background color is 75:100
16 Specifies a 80-percent hatch. The ratio of foreground color to background color is 80:100
17 Specifies a 90-percent hatch. The ratio of foreground color to background color is 90:100
18 Specifies diagonal lines that slant to the right from top points to bottom points, are spaced 50 percent closer together than 2. Antialias is not applied
19 Specifies diagonal lines that slant to the left from top points to bottom points, are spaced 50 percent closer together than 3. Antialias is not applied
20 Specifies diagonal lines that slant to the right from top points to bottom points, are spaced 50 percent closer together than 2 and are twice its width. Antialias is not applied
21 Specifies diagonal lines that slant to the left from top points to bottom points, are spaced 50 percent closer together than 3 and are twice its width. Antialias is not applied
22 Specifies diagonal lines that slant to the right from top points to bottom points, are spaced the same as 2 and are three times its width. Antialias is not applied
23 Specifies diagonal lines that slant to the left from top points to bottom points, are spaced the same as 3 and are three times its width. Antialias is not applied
24 Specifies vertical lines that are spaced 50 percent closer together than 1
25 Specifies horizontal lines that are spaced 50 percent closer together than 0
26 Specifies vertical lines that are spaced 75 percent closer together than 1 (or 25 percent closer than 24)
27 Specifies horizontal lines that are spaced 75 percent closer together than 0 (or 25 percent closer than 25)
28 Specifies vertical lines that are spaced 50 percent closer together than 1 and twice as wide
29 Specifies horizontal lines that are spaced 50 percent closer together than 0 and twice as wide
30 Specifies dashed diagonal lines that slant to the right from top points to bottom points
31 Specifies dashed diagonal lines that slant to the left from top points to bottom points
32 Specifies dashed horizontal lines
33 Specifies dashed vertical lines
34 Specifies a hatch that has the appearance of confetti
35 Specifies a hatch that has the appearance of confetti, and is composed of larger pieces than 34
36 Specifies horizontal lines that are composed of zigzags
37 Specifies horizontal lines that are composed of tildes
38 Specifies a hatch that has the appearance of layered bricks that slant to the left from top points to bottom points
39 Specifies a hatch that has the appearance of horizontally layered bricks
40 Specifies a hatch that has the appearance of a woven material
41 Specifies a hatch that has the appearance of a plaid material
42 Specifies a hatch that has the appearance of divots
43 Specifies horizontal and vertical lines, each of which is composed of dots, that cross
44 Specifies forward diagonal and backward diagonal lines, each of which is composed of dots, that cross
45 Specifies a hatch that has the appearance of diagonally layered shingles that slant to the right from top points to bottom points.
46 Specifies a hatch that has the appearance of a trellis
47 Specifies a hatch that has the appearance of spheres laid adjacent to one another
48 Specifies a pattern of horizontal and vertical lines that cross and have a width 50 percent closer together than 4
49 Specifies a hatch that has the appearance of a checkerboard
50 Specifies a hatch that has the appearance of a checkerboard with squares that are twice the size of 49
51 Specifies a pattern of crisscross diagonal lines. Antialias is not applied
52 Specifies a hatch that has the appearance of a checkerboard placed diagonally

For the Texture Brush

Value Explanation
0 Tiles the gradient or texture
1 Reverses the texture or gradient horizontally and then tiles the texture or gradient.
2 Reverses the texture or gradient vertically and then tiles the texture or gradient.
3 Reverses the texture or gradient horizontally and vertically and then tiles the texture or gradient.
4 Clamps the texture or gradient to the object boundary

For the Gradiation Brush

Value Explanation
0 Specifies gradiation from left to right
1 Specifies gradiation from top to bottom
2 Specifies gradiation from top left to bottom right
3 Specifies gradiation from top right to bottom left

For Text Rendering

Value Explanation
0 Each character is drawn using its glyph bitmap, with the system default rendering hint. The text will be drawn using whatever font-smoothing settings the user has selected for the system.
1 Each character is drawn using its glyph bitmap. Hinting is used to improve character appearance on stems and curvature.
2 Each character is drawn using its glyph bitmap. Hinting is not used. 
3 Each character is drawn using its antialiased glyph bitmap with hinting. Much better quality due to antialiasing, but at a higher performance cost.
4 Each character is drawn using its antialiased glyph bitmap without hinting. Better quality due to antialiasing. Stem width differences may be noticeable because hinting is turned off.
5 Each character is drawn using its glyph ClearType bitmap with hinting. The highest quality setting. Used to take advantage of ClearType font features.

String format info

Value Explanation
0x00000001 Text is displayed from right to left
0x00000002 Text is vertically aligned.
0x00000004 Parts of characters are allowed to overhang the string's layout rectangle. By default, characters are repositioned to avoid any overhang.
0x00000020 Control characters such as the left-to-right mark are shown in the output with a representative glyph.
0x00000400 Fallback to alternate fonts for characters not supported in the requested font is disabled. Any missing characters are displayed with the fonts missing glyph, usually an open square.
0x00000800 Includes the trailing space at the end of each line. Set this flag to include that space in measurement.
0x00001000 Text wrapping between lines when formatting within a rectangle is disabled. This flag is implied when a point is passed instead of a rectangle, or when the specified rectangle has a zero line length.
0x00002000 Only entire lines are laid out in the formatting rectangle. By default layout continues until the end of the text, or until no more lines are visible as a result of clipping, whichever comes first. Note that the default settings allow the last line to be partially obscured by a formatting rectangle that is not a whole multiple of the line height. To ensure that only whole lines are seen, specify this value and be careful to provide a formatting rectangle at least as tall as the height of one line.
0x00004000 Overhanging parts of glyphs, and unwrapped text reaching outside the formatting rectangle are allowed to show. By default all text and glyph parts reaching outside the formatting rectangle are clipped.

The values of the DrawString function in Delphi should start with $ instead of 0x as written above.

Sample code:

In C++Builder

    IKPRINT_TEXTINFO TextInfo;
    float Str_Width, Str_Height;
    int charactersFitted, linesFilled;
    RECT PrintRect;
    ULONG_PTR token;//DWORD token;

    token = IKPrintGdipStart();
    if (token == 0) return;

    memset(&TextInfo, 0, sizeof(IKPRINT_TEXTINFO));
    TextInfo.FontSize = 20;
    lstrcpy(TextInfo.FontName, "MS Gothic");
    TextInfo.HotkeyPrefix = 0;
    IKMeasureString(hDC, 0, 0, &Str_Width, &Str_Height, &charactersFitted, &linesFilled, 0, &TextInfo, "Text", 0);

    PrintRect.left = 10;
    PrintRect.top = 10;
    PrintRect.right = PrintRect.left + (long)Str_Width - 1;
    PrintRect.bottom = PrintRect.top + (long)Str_Height - 1;
    TextInfo.CharAngle = 0;
    TextInfo.TextColor1 = RGB(255, 0, 0);
    TextInfo.Alpha1 = 255;
    TextInfo.TextColor2 = RGB(255, 255, 255);
    TextInfo.Alpha2 = 255;
    //using the Gradiation Brush
    IKDrawString(hDC, &PrintRect, 4, 0, 0, 0, 0, &TextInfo, "Text", 0);
    IKPrintGdipEnd(token)

In Delphi

    TextInfo: IKPRINT_TEXTINFO;
    Str_Width, Str_Height: Single;
    CharactersFitted, linesFilled: Integer;
    PrintRect: TRect;
    token: DWORD;

    token := IKPrintGdipStart();
    if token = 0 then Exit;

    FillChar(TextInfo, SizeOf(TextInfo), 0);
    TextInfo.FontSize := 20;
    StrPCopy(TextInfo.FontName, 'MS Gothic');
    TextInfo.HotkeyPrefix := 0;
    IKMeasureString(DC, 0, 0, Str_Width, Str_Height, charactersFitted, linesFilled, 0, TextInfo, 'Text', 0);

    PrintRect.Left := 10;
    PrintRect.Top := 10;
    PrintRect.Right := PrintRect.Left + Trunc(Str_Width) - 1;
    PrintRect.Bottom := PrintRect.Top + Trunc(Str_Height) - 1;
    TextInfo.CharAngle := 0;
    TextInfo.TextColor1 := clRed;
    TextInfo.Alpha1 := 255;
    TextInfo.TextColor2 := clWhite;
    TextInfo.Alpha2 := 255;
    //using the Gradiation Brush
    IKDrawString(DC, PrintRect, 4, 0, 0, 0, 0, TextInfo, 'Text', 0);
    IKPrintGdipEnd(token)

 

The ImageKit10 VCL is a product created by Newtone Corporation