Jump to content

DdfSetFontStyle

From EDM2
Revision as of 03:18, 14 May 2025 by Martini (talk | contribs) (Created page with "{{DISPLAYTITLE:DdfSetFontStyle}} This function specifies a text font style in the DDF buffer. ==Syntax== DdfSetFontStyle(hddf, fFontStyle) ==Parameters== ;hddf (HDDF) - input :Handle to DDF returned by DdfInitialize. ;fFontStyle (ULONG) - input :Font style flag. A NULL value for this parameter will set the font style back to the default. Any of the following values can be specified: :* FM_SEL_ITALIC :* FM_SEL_BOLD :* FM_SEL_UNDERSCORE :These values can be O...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

This function specifies a text font style in the DDF buffer.

Syntax

DdfSetFontStyle(hddf, fFontStyle)

Parameters

hddf (HDDF) - input
Handle to DDF returned by DdfInitialize.
fFontStyle (ULONG) - input
Font style flag. A NULL value for this parameter will set the font style back to the default. Any of the following values can be specified:
  • FM_SEL_ITALIC
  • FM_SEL_BOLD
  • FM_SEL_UNDERSCORE
These values can be ORed together to combine different font styles.

Returns

rc (BOOL) - returns
Success indicator.
TRUE Successful completion
FALSE Error occurred

Remarks

There is a 4-byte ESC code overhead in the DDF internal buffer for the `fFontStyle` parameter.

Possible errors include:

  • HMERR_DDF_MEMORY (0x3001) Not enough memory is available.
  • HMERR_DDF_FONTSTYLE (0x3005) The font style is not valid.

Example Code

Declaration:

#define INCL_DDF
#include <os2.h>

HDDF     hddf;        /*  Handle to DDF returned by DdfInitialize. */
ULONG    fFontStyle;  /*  Font style flag. */
BOOL     rc;          /*  Success indicator. */

rc = DdfSetFontStyle(hddf, fFontStyle);

After initializing a DDF buffer with DdfInitialize, this example uses `DdfPara` to start a new paragraph, `DdfSetFont` and `DdfSetFontStyle` to display text in a large, bold Courier font, `DdfSetColor` to change the text color, and `DdfText` to place text in the buffer.

For a more detailed example and discussion of initializing DDF, see the DdfInitialize sample.

#define INCL_WINWINDOWMGR       /* General window management    */
#define INCL_WINMESSAGEMGR      /* Message management           */
#define INCL_DDF                /* Dynamic Data Facility        */
#include <os2.h>
#include <pmhelp.h>

MRESULT WindowProc(HWND hwnd, ULONG ulMsg, MPARAM mp1, MPARAM mp2)
{
    HWND   hwndParent;
    HWND   hwndInstance;    /* help instance window                 */
    HDDF   hDdf;            /* DDF handle                           */

    switch (ulMsg)
    {
    case HM_QUERY_DDF_DATA:
        /* get the help instance */
        hwndParent = WinQueryWindow(hwnd, QW_PARENT);
        hwndParent = WinQueryWindow(hwndParent, QW_PARENT);
        hwndInstance = (HWND)WinSendMsg(hwndParent, HM_QUERY,
                                        MPFROMSHORT(HMQW_INSTANCE), NULL);

        /* Allocate 1K Buffer (default) */
        hDdf = DdfInitialize(
                    hwndInstance,  /* Handle of help instance */
                    0L,            /* Default buffer size     */
                    0L             /* Default increment       */
                    );

        if (hDdf == NULLHANDLE)       /* Check return code */
        {
            return (MRESULT)FALSE;
        }

        /* create paragraph in DDF buffer */
        if (!DdfPara(hDdf))
        {
            return (MRESULT)FALSE;
        }

        /* Change to large (100 x 100 dimensions) Courier font */
        if (!DdfSetFont(hDdf, "Courier", 100L, 100L))
        {
            return (MRESULT)FALSE;
        }

        /* make the font BOLDFACE */
        if (!DdfSetFontStyle(hDdf, FM_SEL_BOLD))
        {
            return (MRESULT)FALSE;
        }

        /* make the text display as BLUE on a PALE GRAY background */
        if (!DdfSetColor(hDdf, CLR_PALEGRAY, CLR_BLUE))
        {
            return (MRESULT)FALSE;
        }

        /* Write data into the buffer */
        if (!DdfText(hDdf, "Sample Text"))
        {
            return (MRESULT)FALSE;
        }

        return (MRESULT)hDdf;
    }
    return WinDefWindowProc(hwnd, ulMsg, mp1, mp2);
}

Related Functions