FB II Compiler

PG PRO

Debugging

Memory

System

Mathematics

Resources

Disk I/O

Windows

Controls

Menus

Mouse

Keyboard

Text

Fonts

Drawing

Sound

Clipboard

Printing

Communication

ASM

Made with FB

WINDOWS

Change the background colour of a window


The following is a code snippet that allows you to change a windows' content color. Changing the content color is useful if your window uses a BG color other than white and you want your control rect backgrounds (especially radios and checkboxes) to be filled with the appropriate color. It's not a difficult process, but there *were* some pitfalls -- things that weren't really documented well in my older versions of IM -- so I thought I'd pass it along. Note: This example uses windows which are built programmatically.

'='Set window content color
'='
'In ResEdit -- open your application's resource file:
'
'First create a resource of type WIND
'Choose custom from the WIND editor
'Choose your content/bg color (from the pop-up -- which will be a color picker)
'This creates a 'wctb' resource with the WIND ID
'Close the WIND editor
'
'Since it's a rather primitive approach to have to eyeball your content/bg
'color from that tiny little picker, do this:
'
'Delete the WIND resource (since we don't need it anyway...)
'Open the 'wctb' resource -- which is now in a value-editable form
'Enter your bg RGB values (long values in hex, of course) into the appropriate
'fields of Part Code 0 (zero) (Part Code 0 is the content color Part Code)
'
'**Very important** Mark the 'wctb' to allocate in the System Heap
'**and to be Non-purgable
'
'Implemeted as:

'Build your FB window
'Window *must* be built as invisible!!!
'
WINDOW #-1,"Test Window", @winRect,_docNoGrow
'
'Get a pointer to the window
wPtr&=WINDOW(_wndPointer)
'
'Get the color table handle using the ID of the 'wctb' resource you created
cTabHand&=FN GETRESOURCE(_"wctb",id)
'
LONG IF cTabHand&
'It may not be necessary to lock this handle, but why take chances ;)
  err%=FN HLOCK(cTabHand&)
'
'Set to new color table
  CALL SETWINCOLOR(wPtr&,cTabHand&)
'
  err%=FN HUNLOCK(cTabHand&)
'
'Do *not* call RELEASERESOURCE here
'
END IF
'
'Prepare your window elements
'
'Make your window visible
WINDOW #1
'=

This code works fine, but if anyone sees anything that I missed, please comment.

Deb Lake