Silverfrost Logo About Us | Contact Us
 

Colouring the text and background

The grave accent is used with %tc in order to provide the text colour for a %eb edit box. %`tc then takes an integer argument which is the RGB value for the text colour. This colour can be changed under program control. Here is some sample code that illustrates the concept:

        INTEGER clr
        clr=RGB@(255,255,0)
        ...
        i=winio@('%`tc&', clr)
        i=winio@('%20.20eb', buffer, 10000)
        ...

In order to update the colour of the whole text in the edit box, the following code would appear in a call-back (obvously, you could use RGB@ instead of GetSysColour):

        ...
        clr=GetSysColor(COLOR_HIGHLIGHT)
        CALL window_update@(clr)

In order to change the colours of selected parts of the text dynamically, you should supply the user_colours option to %eb (use %^`eb[user_colours] in a winio@ call) together with an EDIT_INFO array and a call-back function.

Extra invocations of your call-back function will be made for each line of text when it is about to be displayed. This call-back will be indicated by a non-zero value of the n_chars_to_colour component of the EDIT_INFO array. In this case text_colours and background_colours are the addresses of arrays of 4-byte colour values, such as those created by using RGB@. These values will have already been initialised to the default values including colour changes associated with text selection, but you are able to modify the values as required. Note that the colours may be adjusted by display drivers using a limited number of colours.

It is very important to ensure that the function which alters the display colours does not itself perform any screen I/O. At the point when the colouring request is made, Windows has issued a WM_PAINT message, and Windows will become unstable if this rule is not followed.

Since the colours are stored as 4-byte integers, this leaves the top byte of each colour otherwise unused (it is set to zero by RGB@). With %eb, you can set the following bits in the foreground colour:

Z'40000000'

Force underline.

Z'20000000'

Force italic.

Z'10000000'

Force bold.

Z'08000000'

Hide the character.


These bits only add attributes, so if the basic font for the edit box has been set bold (say) the bold bit will have no effect. The 'hide character' bit removes the corresponding character (and the space it occupies) from the screen. This is useful for implementing magic text sequences to achieve special effects. For example, suppose you were writing a program to display some text containing URL's. If you surrounded the URL's with some special character sequences to identify them:

$$$http://www.salford.ac.uk/ssl-$$$

your program could recognise these sequences and make them invisible while changing the colour/attributes of the characters comprising the URL.

The following functions have been added to help manipulate edit boxes:

 

 

Copyright © 1999-2017 Silverfrost Limited