I can't get different colors in text control windows

I've finally got static text control windows (WS_STATIC, SS_TEXT) working with a different color pres. parameter set ! Thanks, Rick, Dan and Wayne. Code as follows:

 RGB2 rgb2 ;   // RGB2 structure
 HWND hwnd ;   // window handle

 // Set RGB values for a SYSCLR_BACKGROUND (light gray) color
 rgb2.bred = 204 ;     // Found these in 'WinSetSysColors' API
 rgb2.bgreen = 204 ;
 rgb2.bblue = 204 ;
 rgb2.fcOptions = 0 ;
 // Set background color
 WinSetPresParam (hwnd, PP_BACKGROUNDCOLOR, (ULONG) sizeof (RGB2),
                  &rgb2) ;
 // Set RGB values for black
 rgb2.bred = 0 ;
 rgb2.bgreen = 0 ;
 rgb2.bblue = 0 ;
 rgb2.fcOptions = 0 ;
 // Set text foreground color
 WinSetPresParam (hwnd, PP_FOREGROUNDCOLOR, (ULONG) sizeof (RGB2),
                  &rgb2) ;
 // Set text border color (important for outline fonts)
 WinSetPresParam (hwnd, PP_BORDERCOLOR, (ULONG) sizeof (RGB2), &rgb2) ;

Three big caveats here:

  • The OS/2 internal code for static text control windows is *definitely* using RGB colors, not index colors when it draws the text string. Thus, the PP_*INDEX presentation parameter values will *not* work.
  • You *must* use a set of colors that are already loaded in the color table. If the RGB color is not found, the background will be dithered affecting the text appearance (washed out). If you are not sure the RGB color is loaded do a GpiQueryNearestColor to get the nearest color.
  • You *must* use the RGB2 structure and *not* the RGB structure. This is *NOT* documented, but it appears in general that all OS/2 2.0 APIs should use RGB2 *instead* of RGB.

    Credit: Bill Kenning


    [Back: How do I query all records in a container - tree view?]
    [Next: How can I toggle my titlebar on and off?]