Jump to content

DdfText

From EDM2
Revision as of 03:22, 14 May 2025 by Martini (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

This function adds text to the DDF buffer.

Syntax

DdfText(hddf, pszText)

Parameters

hddf (HDDF) - input
Handle to DDF returned by DdfInitialize.
pszText (PCSZ) - input
Pointer to the text buffer to be formatted.
rc (BOOL) - returns
Success indicator.

Returns

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

Remarks

There is a 3-byte ESC code overhead in the DDF internal buffer for each word in the text buffer. There is a 1-byte ESC code overhead for each blank and for each newline character.

Example Code

Declaration:

#define INCL_DDF
#include <os2.h>

HDDF    hddf;     /*  Handle to DDF returned by DdfInitialize. */
PCSZ    pszText;  /*  Pointer to the text buffer to be formatted. */
BOOL    rc;       /*  Success indicator. */

rc = DdfText(hddf, pszText);

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