DIALOG SET COLOR statement

Purpose | Set the background color of a dialog to a specific RGB color.
Syntax | DIALOG SET COLOR hDlg, foreclr&, backclr&
Remarks | hDlg identifies the dialog to colorize. Color values foreclr& and backclr& must be in the range of &H0 to &H00FFFFFF, while the value -1& is used to specify the system default color. RGB can be a useful function to derive a 32-bit color value from discrete Red, Green and Blue values.
foreclr& | In the current implementation of PowerBASIC, the dialog foreground color parameter foreclr& is not used, but the syntax is retained for future implementation. It is recommended that the foreground color parameter be set to -1&.

backclr&

In 16-bit or greater color-depth mode, the RGB color specified is used when the background of the dialog is drawn. If backclr& = -1&, the default dialog background color is used. If backclr& = -2&, the dialog background is not painted, allowing the content behind the dialog to become visible through the dialog.

In 16-bit or greater color-depth mode, the specified RGB color is used when the background of the dialog is drawn. However, in 8-bit (256-color) mode, the color system works quite differently. Behind the scenes in Windows, the base system palette usually contains 20 solid colors that are not dithered when drawn on a dialog background. These solid-colors are ideal for background colors with DDT dialogs in 256-color mode.

Conversely, when using a non-solid RGB color value, Windows will dither (approximate) the color to draw the dialog, using combinations of two or more colors. This usually produces an undesirable pattern effect.

To avoid these problems when in 256-color mode, dialogs should either be colored with one of the 20 standard (solid) system colors, or the default color should be used instead. PowerBASIC includes the following 10 built-in equates for help with the selection of a standard solid color:

%RGB_BLACK %RGB_BLUE %RGB_GREEN %RGB_CYAN %RGB_RED

%RGB_MAGENTA %RGB_YELLOW %RGB_WHITE %RGB_GRAY %RGB_LIGHTGRAY

Many non standard colors are also built into the compiler, see the Built In RGB Color Equates topic for a complete list.

If you prefer to disable color in 256-color mode, the number of colors can be easily tested with the following code:

' Determine number of colors

LOCAL hDC AS DWORD, iColors AS LONG

hDC = GetWindowDC(GetDeskTopWindow())

iColors = 2& ^ (GetDeviceCaps(hDC, %BITSPIXEL) * GetDeviceCaps(hDC, %PLANES))

ReleaseDC GetDeskTopWindow(), hDC

IF iColors > 256 THEN _

DIALOG SET COLOR hDlg, -1, RGB(0,100,192)

In 256-color mode on most computers, the values of the standard 20 system colors can be found by requesting the first and last 10 (0 to 9, and 246 to 255 inclusive) entries from the GetSystemPaletteEntries API function, as follows:

' Fill array with solid colors

DIM hDC AS DWORD, Cols AS LONG, x AS LONG

hDC = GetWindowDC(GetDesktopWindow)

Cols = GetDeviceCaps(hDC, %NUMRESERVED)

REDIM lp(1 TO Cols) AS LONG

x& = GetSystemPaletteEntries(hDC, 0, Cols \ 2, BYVAL VARPTR(lp(1)))

x& = GetSystemPaletteEntries(hDC, 256 - x&, Cols - x&, BYVAL VARPTR(lp(x& + 1)))

ReleaseDc GetDesktopWindow, hDC

' Array lp() now contains the solid color table

For more information on working with palettes in 256-color mode, please consult WIN32.HLP or visit http://msdn.microsoft.com.

When dynamically changing colors of a dialog from within a callback (i.e., after the DIALOG SHOWstatement), a DIALOG SET COLOR statement should be immediately followed by an explicit DIALOG REDRAW statement.

Without a forced dialog redraw, the dialog background color change may not become evident to the user until the dialog is eventually repainted in the normal course of user interaction. For example, a normal repaint may only occur if the dialog becomes obscured and then uncovered by another window. Ensuring a timely repaint of the dialog will guarantee the dialog maintains an up-to-date appearance at all times.

See also | Built In RGB Color Equates, Dynamic Dialog Tools, CONTROL REDRAW, DIALOG REDRAW, CONTROL SET COLOR, DIALOG SET ICON
Example | DIALOG NEW 0, "Dialog",,, 160, 120, TO hDlg ' Set the color with an RGB value DIALOG SET COLOR hDlg, -1, RGB(0,0,255) ' Or we could use the built-in %BLUE equate: DIALOG SET COLOR hDlg, -1, %BLUE