1. Re: Colored Text in Win32Lib
- Posted by David Cuny <dcuny at LANSET.COM>
Sep 23, 1998
-
Last edited Sep 24, 1998
Michael Sabal wrote:
> Is there any way to change the font or color of controls?
I think so. I lucked out by running across the WM_CTLCOLORBTN event in the
Win32 help file, and eventually puzzled the code out. But I'm hardly an
expert on this stuff, so if someone has a clue on this, send me an e-mail,
please...
Look in line 4014 of Win32Lib.e. and you'll see something like:
-- NEW! Matches controls against background color!
elsif iMsg = WM_CTLCOLORBTN
or iMsg = WM_CTLCOLORSTATIC
-- or iMsg = WM_CTLCOLOREDIT -- these do NOT adjust the color
-- or iMsg = WM_CTLCOLORLISTBOX
-- or iMsg = WM_CTLCOLORMSGBOX
-- or iMsg = WM_CTLCOLORDLG
-- or iMsg = WM_CTLCOLORSCROLLBAR
This event is triggered just before a control is drawn. As you can see from
the comments, I'm only trapping on the button and static control. The
actual setting is done here:
-- set text background color to the window background color
if c_func(xSetBkColor, {wParam, window_bcolor[id]} ) = CLR_INVALID
then
abortErr( "SetBkColor in wndProc failed." )
end if
The color of the background window is initially set to white in create()
when the window is created, and modified when you make a call to
setWindowBackColor. The rgb value is stored in window_bcolor.
Finally, the routine returns a pointer back to the resource:
-- get the parent's background color brush
return c_func( xGetClassLong, {window_handle[id],
GCL_HBRBACKGROUND} )
Now, past this point, I get a little fuzzy.
1. I *think* that you should be able to use setTextColor() to set the color
of the text control. But I'm not sure. You can do what I did to test it out:
fool around with various values.
2. The function returns a long pointer to a *resource*. The resource is
created when the window is initialized, and modified in
setWindowBackColor(). If you take a peek at setWindowBackColor, you can see
that I dispose of the old resource after replacing it. I'm worried that if
you just stuck resources (other than the pre-defined brushes), you'll end up
with a memory leak. I'm pretty paranoid about this resource leak thing after
getting burned big time when I started working with graphics.
In any event, now you know just about everything about it that I do. If
anyone has any clue how to set the text color here, please drop me a hint,
and I'll see what I can do.
> global constant MLEText = MleText
Good thought. I'll probably forget, so harass me again...
-- David Cuny
dcuny at lanset.com