Dempsey
Scripting Contest Winner
http://AdamDempsey.net
Posts: 2395 Reputation: 53
38 / /
Joined: Jul 2003
|
O.P. RE: Font Dialog - Enhanced Colour
I'm guessing it's probably because I don't set some parts of the CHOOSEFONT structure correctly, here's the code I use:
code: function ChooseFont(){
var CF = Interop.Allocate(60);
CF.WriteDWORD(0, CF.Size); //lStructSize
CF.WriteDWORD(4, 0); //hwndOwner
CF.WriteDWORD(8, 0); //hDC
var LF = Interop.Allocate(92);
LF.WriteDWORD(0,0); //lfHeight
LF.WriteDWORD(4,0); //lfWidth
LF.WriteDWORD(8,0); //lfEscapement
LF.WriteDWORD(12,0); //lfOrientation
LF.WriteDWORD(16,0); //lfWeight
LF.SetAt(20,0); //lfItalic
LF.SetAt(21,0); //lfUnderline
LF.SetAt(22,0); //lfStrikethru
LF.SetAt(23,0); //lfCharSet
LF.SetAt(24,0); //lfOutPrecision
LF.SetAt(25,0); //lfClipPrecision
LF.SetAt(26,0); //lfQuality
LF.SetAt(27,0); //lfPitchAndFamily
LF.WriteString(28, ""); // lfFaceName
CF.WriteDWORD(12, LF.DataPtr); //LPLF
var iPointSize = Interop.Allocate(4);
CF.WriteDWORD(16, iPointSize.DataPtr); //iPointSize
CF.WriteDWORD(20, CF_INITTOLFSTRUCT | CF_SCREENFONTS | CF_EFFECTS ); //Flags
CF.WriteDWORD(24, 0); // rgbColors
CF.WriteDWORD(28, 0); // lCustData
CF.WriteDWORD(32, 0); // lpfnHook
CF.WriteDWORD(36, 0); // lpTemplateName
CF.WriteDWORD(40, 0); // hInstance
var lpszStyle = Interop.Allocate(514);
CF.WriteDWORD(44, lpszStyle.DataPtr); // lpszStyle
CF.WriteWORD(48, 0x2000); // nFontType
CF.WriteDWORD(50, 0); // nSizeMin
CF.WriteDWORD(54, 0); // nSizeMax
var result = Interop.Call("comdlg32.dll", "ChooseFontW", CF);
if(result > 0){
Debug.Trace('Font: ' + LF.ReadString(28));
Debug.Trace('Size: ' + LF.ReadDWORD( 0));
//var weight = LF.ReadDWORD(16);
if (LF.ReadDWORD(16) == 700){
Debug.Trace('Bold: 1');
}else{
Debug.Trace('Bold: 0');
}
Debug.Trace('Italic: ' +LF.GetAt(20));
Debug.Trace('Underline: ' + LF.GetAt(21));
Debug.Trace('Strkethru: ' + LF.GetAt(22));
}else{
var error = Interop.Call('ComDlg32', 'CommDlgExtendedError');
if(error > 0){
LF.WriteDWORD(0,0);
//An error occurred, "error" contains the error code
}else{
LF.WriteDWORD(0,0);
//User closed font dialog
}
}
return LF;
}
|
|