Text Methods

The following methods are used to display text dynamically in a window area and to modify the state of a device context. See GetWindowDC, GetDC, and GetButtonDC for information on how to retrieve a device context.

Write

>>-aDialogControl~Write(--xPos--,--yPos--,--text---------------->

>--+--------------------------------------+--------------------->
   |    +-"SYSTEM"-+                      |
   +-,--+----------+--+-----------------+-+
        +-fontName-+  |    +-10-------+ |
                      +-,--+----------+-+
                           +-fontSize-+

>--+--------------------------------------------------------------------------+--)-><
   +-+----------------------------------------------------------------------+-+
     +-+------------------------------------------------------------------+-+
       |       +-----------------+                                        |
       |       V +-OPAQUE------+ |                                        |
       +-,--"----+-THIN--------+-+--"--+--------------------------------+-+
                 +-EXTRALIGHT--+       +-,--+---------+--+------------+-+
                 +-LIGHT-------+            +-fgColor-+  +-,--bkColor-+
                 +-MEDIUM------+
                 +-SEMIBOLD----+
                 +-EXTRABOLD---+
                 +-BOLD--------+
                 +-HEAVY-------+
                 +-UNDERLINE---+
                 +-ITALIC------+
                 +-STRIKEOUT---+
                 +-TRANSPARENT-+
                 +-CLIENT------+


The Write method writes the specified text to the device context associated with the dialog or dialog control in the given font, style, and color at the given position.

Arguments:

The arguments are:

xPos, yPos

The starting position of the text, in pixels.

text

The string that you want to write to the dialog or dialog control.

fontName

The name of a font. If omitted, the SYSTEM font is used.

fontSize

The size of the font. If omitted, the standard size (10) is used.

fontStyle

One or more of the keywords listed in the syntax diagram, separated by blanks:

TRANSPARENT

This style writes the text without clearing the background.

OPAQUE

This style, which is the default, clears the background with the given background color, or with white if the background color is omitted, before writing the text.

CLIENT

The device context of the client area of the dialog or dialog control is used instead of the device context of the entire dialog or dialog control.

fgcolor

The color index of the text color.

bkColor

The color index of the background color. The background color is not used in transparent mode.

Example:

The following example writes the string "Hello world!" to the dialog using a blue 24pt Arial font in bold and transparent, italic style:

MyDialog~Write(5, 5, "Hello world!", "Arial", 24, ,
"BOLD ITALIC TRANSPARENT CLIENT", 4)

WriteDirect

>>-aDialogControl~WriteDirect(--dc--,--xPos--,--yPos--,--text--)-><


The WriteDirect method enables you to write text to a device context at a given position.

Arguments:

The arguments are:

dc

A device context.

xPos, yPos

The position where the text is placed, in pixels.

text

The string you want to write to the dialog or dialog control.

TransparentText

>>-aDialogControl~TransparentText(--dc--)---------------------->>


The TransparentText method enables you to write text to a device context using WriteDirect in transparent mode, that is, without a white background behind the text. Restore the default mode using OpaqueText.

Arguments:

The only argument is:

dc

A device context.

OpaqueText

>>-aDialogControl~OpaqueText(--dc--)---------------------------><


The OpaqueText method restores the default text mode, that is, with a white background behind the text, which overlays whatever is at that position in the dialog or dialog control. Use this method after transparent mode was set using TransparentText.

Arguments:

The only argument is:

dc

A device context.

WriteToWindow

>>-aDialogControl~WriteToWindow(--hwnd--,--xPos--,--yPos--,--text-->

>--+--------------------------------------+--------------------->
   |    +-"SYSTEM"-+                      |
   +-,--+----------+--+-----------------+-+
        +-fontName-+  |    +-10-------+ |
                      +-,--+----------+-+
                           +-fontSize-+

>--+--------------------------------------------------------------------------+--)-><
   +-+----------------------------------------------------------------------+-+
     +-+------------------------------------------------------------------+-+
       |       +-----------------+                                        |
       |       V +-OPAQUE------+ |                                        |
       +-,--"----+-THIN--------+-+--"--+--------------------------------+-+
                 +-EXTRALIGHT--+       +-,--+---------+--+------------+-+
                 +-LIGHT-------+            +-fgColor-+  +-,--bkColor-+
                 +-MEDIUM------+
                 +-SEMIBOLD----+
                 +-EXTRABOLD---+
                 +-BOLD--------+
                 +-HEAVY-------+
                 +-UNDERLINE---+
                 +-ITALIC------+
                 +-STRIKEOUT---+
                 +-TRANSPARENT-+
                 +-CLIENT------+


The WriteToWindow method enables you to write text to a dialog or dialog control in the given font and size to the given position.

Arguments:

The arguments are:

hwnd

The handle of the dialog or dialog control. See Get for how to get a valid handle.

xPos, yPos

The starting position of the text, in pixels.

text

The string you want to write to the dialog or dialog control.

fontName

The name of a font. If omitted, the SYSTEM font is used.

fontSize

The size of the font. If omitted, the standard size (10) is used.

fontStyle

One or more of the keywords listed in the syntax diagram, separated by blanks:

TRANSPARENT

This style writes the text without clearing the background.

OPAQUE

This style, which is the default, clears the background with the given background color, or with white if the background color is omitted, before writing the text.

CLIENT

The device context of the dialog's client area is used instead of the device context of the entire dialog.

Example:

This example writes the string "Hello world!" to the dialog window using a 24pt Arial font in bold and italic style:

hwnd=MyDialog~Get
MyDialog~WriteToWindow(hwnd, 23, 15, "Hello world!", ,
                       "Arial", 24, "BOLD ITALIC")

WriteToButton

>>-aDialogControl~WriteToButton(--id--,--xPos--,--yPos--,--text-->

>--+--------------------------------------+--------------------->
   |    +-"SYSTEM"-+                      |
   +-,--+----------+--+-----------------+-+
        +-fontName-+  |    +-10-------+ |
                      +-,--+----------+-+
                           +-fontSize-+

>--+--------------------------------------------------------------------------+--)-><
   +-+----------------------------------------------------------------------+-+
     +-+------------------------------------------------------------------+-+
       |       +-----------------+                                        |
       |       V +-OPAQUE------+ |                                        |
       +-,--"----+-THIN--------+-+--"--+--------------------------------+-+
                 +-EXTRALIGHT--+       +-,--+---------+--+------------+-+
                 +-LIGHT-------+            +-fgColor-+  +-,--bkColor-+
                 +-MEDIUM------+
                 +-SEMIBOLD----+
                 +-EXTRABOLD---+
                 +-BOLD--------+
                 +-HEAVY-------+
                 +-UNDERLINE---+
                 +-ITALIC------+
                 +-STRIKEOUT---+
                 +-TRANSPARENT-+
                 +-CLIENT------+


The WriteToButton method enables you to write text to a button in the given font and size to the given position.

Arguments:

The arguments are:

id

The ID of a button.

See WriteToWindow for a description of the other arguments.

GetTextSize

>>-aDialogControl~GetTextSize(--text--+------------------------------------->
                                      +--,--fontname--+--------------------->
                                                      +--,--fontsize--+----->

>--------------------+--)--------------------------------------------------><
>-----------------+--+
>--+-----------+--+
   +--,--hwnd--+


The GetTextSize method returns the width and height that the specified text requires in the font and size given.

Arguments:

The arguments are:

text

The text for which the dimensions are to be returned.

fontname

The name of the font used in the device context (DC).

fontsize

The size of the font used in the device context (DC).

hwnd

The handle to the dialog or dialog control that is the owner of the device context (DC).

Return value:

The width and height of the text, in dialog units, separated by a blank.

Example:

The following example stores the space required by the specified text in the device context of MyButton, in cx and cy:

parse value MyButton~GetTextSize("This is the output!") with cx cy

SetFont

<>>-aDialogControl~SetFont(--fontHandle--+---------+--)---------><
                                         +-,redraw-+


The SetFont method assigns another font to the text in a dialog or dialog control.

Arguments:

The arguments are:

fontHandle

The handle to the font that is to be used by the dialog or dialog item. Use CreateFont to get this handle.

redraw

If you specify 1, the dialog or dialog item is redrawn.

Example:

The following example creates the font Arial with a pitch size of 14 and assigns it to the tree view control FILES, which is forced to be redrawn.

hfnt = Mydialog~CreateFont("Arial", 14)
MyDialog~GetTreeControl("FILES")~SetFont(hfnt, 1)

CreateFont

<                              +-"SYSTEM"-+     +-10-------+
>>-aDialogControl~CreateFont(--+----------+--,--+----------+--,-->
                               +-fontName-+     +-fontSize-+

      +----------------+
      V                |
>--"----+-THIN-------+-+--"--+--------------+--)---------------><
        +-EXTRALIGHT-+       +-,--fontWidth-+
        +-LIGHT------+
        +-MEDIUM-----+
        +-SEMIBOLD---+
        +-EXTRABOLD--+
        +-BOLD-------+
        +-HEAVY------+
        +-UNDERLINE--+
        +-ITALIC-----+
        +-STRIKEOUT--+


The CreateFont method creates a font. It returns a handle that you can use in the FontToDC method (see page FontToDC) to activate the font in a device context or in the SetItemFont method (see page SetItemFont) to change the font of a dialog or dialog item.

Arguments:

The arguments are:

fontName

The name of a font. You can look for valid fonts in the Fonts folder of your Windows Control Panel. If omitted, the SYSTEM font is used.

fontSize

The size of the font. If omitted, the standard size (10) is used.

fontStyle

One or more of the keywords listed in the syntax diagram, separated by blanks.

fontWidth

This argument is optional if it differs from fontSize.

Example:

The following example creates a 16-point italic Arial font:

hfnt = MyDialog~CreateFont("Arial", 16, "ITALIC")

DeleteFont

>>-aDialogControl~DeleteFont(--hFont--)------------------------><


The DeleteFont method deletes a font. This method is to be used to delete a font created with the CreateFont method (see page CreateFont).

Arguments:

The only argument is:

hFont

The handle of a font.

FontToDC

>>-aDialogControl~FontToDC(--dc--,hFont--)---------------------><


The FontToDC method loads a font into a device context and returns the handle of the previous font. Use the GetWindowDC, GetDC, or GetButtonDC method to retrieve a device context, and the CreateFont method to get a font handle. To reset the font to the original state, use another FontToDC call with the handle of the previous font. To release the device context, use the FreeWindowDC, FreeDC, or FreeButtonDC method.

Arguments:

The arguments are:

dc

The device context of a dialog or button.

hFont

The handle of a font.

Example:

This example loads an Arial font into the current dialog window:

hfnt = MyDialog~CreateFont("Arial", 16, "ITALIC")
dc   = MyDialog~GetDC
oldf = MyDialog~FontToDC(dc,hfnt)  /* activate font */
...
MyDialog~FontToDC(dc,oldf)         /* restore previous font */
MyDialog~FreeDC(dc)

FontColor

>>-aDialogControl~FontColor(--color--,dc--)--------------------><


The FontColor method sets the font color for a device context.

Arguments:

The arguments are:

color

The index of a color in the system's color palette.

dc

The device context.