Jump to content

WinQueryControlColors

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

This function queries the colors currently being used by a control window. Note: If you are interested in the default colors used by PM controls, see Colors Used by PM Controls.

Syntax

WinQueryControlColors(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: Query global default colors (default).
CCF_APPLICATION: Query application default colors (used on current thread).
CCF_COUNTCOLORS: Return the number of color indexes used by a control window.
CCF_ALLCOLORS: Return information on all colors used by a control window.
cCtlColor (ULONG) - input
Number of items available in pCtlColor. If CCF_ALLCOLORS is specified, this value is the maximum number of items that can be returned in pCtlColor. Otherwise, this value is the number of color indexes being queried in pCtlColor. If CCF_COUNTCOLORS is specified, this value is 0.
pCtlColor (PCTLCOLOR) - in/out
Array of control colors, each comprising an index and value pair.
rc (LONG) - returns
Number of control colors returned in pCtlColor:
TRUE: Number of control colors returned.
FALSE: Error, invalid parameters.

Remarks

This function returns the colors (one or more) that are currently being used by a control window of the type specified by clrType. If hwnd is a valid control window handle, the colors being used by that window are returned, including any presentation parameters it might be using. If hwnd is set to HWND_DESKTOP, the default colors being used by that window are returned.

To find out the default control colors for the current thread, specify CCF_APPLICATION. Be sure to issue the call to WinQueryColors from the same thread that created the control windows, otherwise the information returned will be incorrect.

To get all the colors used by a control window returned at once, specify CCF_ALLCOLORS. You can call WinQueryColors with CCF_COUNTCOLORS first to determine the buffer size you will need for the color information.

Each item in the returned array contains an index and value pair (CTLCOLOR). If CCF_ALLCOLORS and CCF_COUNTCOLORS are not set, each item's index should be set to a valid CCI_* constant for which a value is to be returned. The values returned in the array are always valid RGB colors (including SYSCLR_* values, which are actually indexes but can be used by graphics functions in RGB mode).

If an invalid CCI_* index is specified, CCV_NOTFOUND is returned. Note: This function can only be used for querying 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 available 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 = WinQueryControlColors(hwnd, clrType,
                           fCtlColor, cCtlColor, pCtlColor);

This example first queries the count of colors used by a push button. Then it queries all the colors used by 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  */

Related Functions