Jump to content

DdfSetColor

From EDM2
Revision as of 03:14, 14 May 2025 by Martini (talk | contribs) (Created page with "{{DISPLAYTITLE:DdfSetColor}} This function sets the background and foreground colors of the displayed text. ==Syntax== DdfSetColor(hddf, fBackColor, fForColor) ==Parameters== ;hddf (HDDF) - input :Handle to DDF returned by DdfInitialize. ;fBackColor (COLOR) - input :Specifies the desired background color. ;fForColor (COLOR) - input :Specifies the desired foreground color. The following color value constants may be used for the foreground and background...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)


This function sets the background and foreground colors of the displayed text.

Syntax

DdfSetColor(hddf, fBackColor, fForColor)

Parameters

hddf (HDDF) - input
Handle to DDF returned by DdfInitialize.
fBackColor (COLOR) - input
Specifies the desired background color.
fForColor (COLOR) - input
Specifies the desired foreground color. The following color value constants may be used for the foreground and background colors:
  • CLR_DEFAULT - used to set IPF default text color
  • CLR_BLACK
  • CLR_BLUE
  • CLR_RED
  • CLR_PINK
  • CLR_GREEN
  • CLR_CYAN
  • CLR_YELLOW
  • CLR_BROWN
  • CLR_DARKGRAY
  • CLR_DARKBLUE
  • CLR_DARKRED
  • CLR_DARKPINK
  • CLR_DARKGREEN
  • CLR_DARKCYAN
  • CLR_PALEGRAY

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 foreground color, and a 4-byte overhead for the background color, with this function.

Possible errors include:

  • HMERR_DDF_MEMORY (0x3001) Not enough memory is available.
  • HMERR_DDF_BACKCOLOR (0x3003) The background color is not valid.
  • HMERR_DDF_FORECOLOR (0x3004) The foreground color is not valid.

Example Code

Declaration:

#define INCL_DDF
#include <os2.h>

HDDF     hddf;        /*  Handle to DDF returned by DdfInitialize. */
COLOR    fBackColor;  /*  Specifies the desired background color. */
COLOR    fForColor;   /*  Specifies the desired foreground color. */
BOOL     rc;          /*  Success indicator. */

rc = DdfSetColor(hddf, fBackColor, fForColor);

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