quote:
Originally posted by SmokingCookie
It may be a bit late, but how about using colours in the font?
You need a few changes for that, but it's quite simple.
Note that this
ONLY applies when you're about to use the Choose Font dialog through the Choose() dialog. The LOGFONT itself doesn't have a COLORREF entry, but the CHOOSEFONT structure does.
In the constructor function of Font, add the ColorRef parameter to the end, so you get:
code:
function Font(Height, Width, Escapement, Orientation, Weight, Italic, Underline, StrikeOut, CharSet, OutPrecision, ClipPrecision, Quality, PitchAndFamily, FaceName, ColorRef) {
Then, between "this.FaceName =" and "this.LOGFONT =", add this line:
code:
this.ColorRef = typeof(ColorRef) == "undefined" ? 0x0 : ColorRef;
Now, in the Choose method, make the following modifications. The added lines are in red.
code:
...
this.CHOOSEFONT.WriteDWORD(20, Flags);
this.CHOOSEFONT.WriteDWORD(24, this.ColorRef);
...
if(Interop.Call("comdlg32.dll", "ChooseFontW", this.CHOOSEFONT.DataPtr)) {
this.Height = this.CHOOSEFONT.ReadDWORD(16).toLogical() / 10;
this.ColorRef = this.CHOOSEFONT.ReadDWORD(24);
this.UpdateHFONT();
...
And that's it! You can now use
Font.ColorRef to get or set the new color in 0x00bbggrr format, or add it as last parameter for the Font class constructor. When calling Choose(), you'll receive the selected color in Font.ColorRef and, when you're using the CF_INITTOLOGFONTSTRUCT flag, the color will be set in the Choose Font dialog according to the ColorRef property.
This doesn't include support for Load(Cache) and Save(), but I think you can figure that out yourself if you'd need it.
(It's quite funny, as I were doing this exact thing myself before you asked. I noticed you reading this topic and thought: "Hey, a font class! Could come handy.")
Besides, awesome class! Really helpful!