Jump to content

WinSetControlColors

From EDM2
Revision as of 17:04, 24 April 2025 by Martini (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Code snippet

This function sets the colors to be used by a control window. See Colors Used by PM Controls.

Syntax

WinSetControlColors(hwnd, clrType, fCtlColor, cCtlColor, pCtlColor);

Parameters

hwnd (HWND) - input
Window handle.
clrType (LONG) - input
Control color index. Must be one of the following control color indexes:
CCT_STATIC: Static bitmap.
CCT_STATICTEXT: Static text.
CCT_GROUPBOX: Group Box.
CCT_PUSHBUTTON: Push button.
CCT_CHECKBOX: Check box.
CCT_RADIOBUTTON: Radio button.
CCT_ENTRYFIELD: Entry field.
CCT_LISTBOX: List box.
CCT_COMBOBOX: Combo box.
CCT_SCROLLBAR: Scroll bar.
CCT_FRAME: Window frame.
CCT_MENU: Menu.
CCT_TITLEBAR: Title bar.
CCT_SPINBUTTON: Spin button.
CCT_SLIDER: Slider.
CCT_CIRCULARSLIDER: Circular slider.
CCT_VALUESET: Value set.
CCT_MLE: Multiple line entry field.
CCT_CONTAINER: Container.
CCT_NOTEBOOK: Notebook.
fCtlColor (ULONG) - input
Control Color Flags:
CCF_GLOBAL: Set global default colors (default).
CCF_APPLICATION: Set application default colors (used on current thread).
cCtlColor (ULONG) - input
Number of items being passed in pCtlColor.
pCtlColor (PCTLCOLOR) - in/out
Array of control colors, each comprising an index and value pair.

Returns

rc (LONG) - returns
Number of control colors returned in pCtlColor:
TRUE: Successful completion.
FALSE: Error occurred, invalid parameters.

Remarks

This function sets one or more of the colors to be used by a control window of the type specified by ColorType. If hwnd is a valid control window handle, the colors are set as presentation parameters for that window. If hwnd is set to HWND_DESKTOP, the default colors being used by that type of control window are set.

To set the default control colors for the current thread, specify CCF_APPLICATION. Be sure to issue the call to WinSetColors from the same thread that created the control windows, otherwise the call to WinSetControlColors will have no effect. To set all the colors used by a control window at once, specify CCF_GLOBAL, which is the default.

Each item in the array should contain a valid index and value pair (CTLCOLOR). The control color index must be a valid CCI_ constant. The control color value can be one of the following:

   A valid RGB color Note: Valid RGB colors include SYSCLR_ values, which are actually indexes but can be used by graphics functions in RGB mode.
   CCV_DEFAULT, which sets the color to its default value
   CCV_IGNORE, which leaves the color for this index unchanged.

If CCV_DEFAULT is used when hwnd is a valid control window, the presentation parameter that maps to the specified CCI_ index is removed.

If an RGB value that is not a pure color is specified as one of the color values, and if that color is used to draw lines with the control, the end result is not defined. Although dithered colors are okay for filled areas such as backgrounds, they cannot be used for lines.

This function can only be used for setting the colors of standard PM controls.

Example Code

#define INCL_WINSYS /* Or use INCL_WIN, INCL_PM, */
#include <os2.h>

HWND        hwnd;      /* Window handle. */
LONG        clrType;   /* Control color index. */
ULONG       fCtlColor; /* Control Color Flags. */
ULONG       cCtlColor; /* Number of items being passed in pCtlColor. */
PCTLCOLOR   pCtlColor; /* Array of control colors, each comprising an index and value pair. */
LONG        rc;        /* Number of control colors returned in pCtlColor. */

rc = WinSetControlColors(hwnd, clrType, fCtlColor,
                           cCtlColor, pCtlColor);

This example sets new border colors for all the push buttons in the application.

/******************************************************************/
/* Query the number of colors used by a push button.              */
/******************************************************************/

cCount = WinQueryControlColors(
                HWND_DESKTOP,            /* Desktop window handle  */
                CCT_PUSHBUTTON,          /* Select push button     */
                CCF_COUNTCOLORS,         /* Count number of colors */
                0, 0);

pactlColor = (PCTLCOLOR)malloc(sizeof(CTLCOLOR) * cCount);

/******************************************************************/
/* Query all the colors used by push buttons in application.      */
/******************************************************************/

WinQueryControlColors(HWND_DESKTOP,            /* Desktop window handle  */
                CCT_PUSHBUTTON,          /* Select push button     */
                CCF_ALLCOLORS |           /* Return all colors ...  */
                CCF_APPLICATION,         /* ... for application    */
                cCount,                  /* Size of array          */
                pactlColor);             /* Buffer for color data  */

/******************************************************************/
/* Give the global push button borders a red color.                */
/******************************************************************/

for (i = 0; i < cCount; i++)
{
    switch (pactlColor[i].clrIndex)
    {
        case CCI_BORDERLIGHT:

            pactlColor[i].clrValue = 0x00FFC0C0;      /* Light red      */
            break;

        case CCI_BORDERDARK:

            pactlColor[i].clrValue = 0x00C00000;      /* Dark red       */
            break;

        default:

            pactlColor[i].clrValue = CCV_DEFAULT;     /* Default color  */
            break;
    }
}
/******************************************************************/
/* Set the new border colors for all push buttons in application. */
/******************************************************************/

WinSetControlColors(HWND_DESKTOP,            /* Desktop window handle  */
                CCT_PUSHBUTTON,          /* Select push button     */
                CCF_APPLICATION,         /* Application colors     */
                cCount,                  /* Number of colors       */
                pactlColor);             /* Buffer for color data  */


Related Functions