[comp.windows.ms.programmer] visible colours

rdb@oasis.icl.co.uk (Roger Binns) (05/30/91)

I have a little problem I wonder if you can help me with.  I am drawing a
set of buttons (owner draw) for the user to select a background and
foreground colour from.

    Background            Foreground

    +-----------+         +------------+
    |  Black    |         |  Black     |
    +-----------+         +------------+

    +-----------+         +------------+
    |  White    |         |  White     |
    +-----------+         +------------+

         /                      \
	 \                      /
         /                      \

    +-----------+         +------------+
    |  Yellow   |         |  Yellow    |
    +-----------+         +------------+


    In the background column, I have the text in black or white, and the
    background the colour I want.  In the foreground column, I have the
    background in COLOR_WINDOW and the text in the colour I want.  I am
    only using 8 pure colours (black, white, red, green, blue, cyan,
    magenta, yellow).

    The problem is that I have to make sure the text is always visible.  In
    8+ colour systems, the background column is fine.  However, in the
    foreground column, it is ok, unless COLOR_WINDOW is the same as one of
    my foreground colours in which case the text becomes invisible.

    Therefore, I was wondering if anyone has a function which when given
    a foreground and a background colour will return if it will be visible
    or not on that system, and if not, suggest an alternative colour for
    the foreground or background.  It needs to work no matter what the
    device or how many colours it has.


    example:

    struct {
	       BOOL  visible;
               COLORREF foreground;
               COLORREF background;
         } info;

    the function will take a pointer to this structure and then alter the
    fields - set visible if the foreground/background colours will be
    visible against each other, and if they aren't, set foreground to a
    value that with my background would be visible, and set background, so
    that it will visible with my foreground.  It would have to check what
    the hardware will map the colours to, so it will probably need a device
    context as well.

    please can you email replies to me and if there are enough I will
    summarise and post results.  I cannot read news at the moment cause our
    entire news feed is down (and has been for 3 weeks :-( )

    thank you,

    roger binns

    rdb@oasis.icl.co.uk       International Computers Limited, Bracknell, UK.

             British ingenuity:  putting the `u' into colour!