Seemed to be missing return of the font type: Bold, Italics, etc..
this basically works:
Code:
FType := ExtractInteger(StructForChooseFont, 49,0,2) & 0x07 FontType := (Ftype = 4) ? "Norm" : (Ftype = 3) ? "bold italic" : (Ftype = 2) ? "italic" : (Ftype = 1) ? "bold" : ""
and (hopefully maybe when more time allows, will come back and update), here is the very cool Select Font as a function if might be helpful for 'beginners' to clip and use:
Code:
fontselect(Font, Options)
msgbox Font: %font%`n%Options%
exitapp
FontSelect( byref Font,byref Options, x = "", y = ""){
if (!x) and (!y)
NOGUI
SizeOfStructForChooseFont = 60
OffsetToFontFaceName = 28
SizeOfFontFaceName = 32
SizeOfStructForLogFont := OffsetToFontFaceName + SizeOfFontFaceName
VarSetCapacity(StructForChooseFont, SizeOfStructForChooseFont, 0)
VarSetCapacity(StructForLogFont, SizeOfStructForLogFont) ; No need to zero it.
InsertInteger(SizeOfStructForChooseFont, StructForChooseFont, 0) ; DWORD lStructSize
if !NOGUI
gui show, x%x% y%y%
Gui, +LastFound
GuiHWND := WinExist() ; Relies on the line above to get the unique ID of GUI window.
InsertInteger(GuiHWND, StructForChooseFont, 4) ; HWND hwndOwner (makes dialog "modal").
InsertInteger(&StructForLogFont, StructForChooseFont, 12) ; LPLOGFONT lpLogFont
InsertInteger(0x101, StructForChooseFont, 20)
; Above is DWORD Flags: CF_EFFECTS = 0x100, CF_SCREENFONTS = 1 (omit printer fonts)
;ButtonSelectFont:
if not DllCall("comdlg32\ChooseFontA", str, StructForChooseFont) { ; Display the dialog.
if !NOGUI
gui, destroy
return ; The user canceled the dialog.
} ; Otherwise, the user pressed OK in the dialog, so determine what was selected.
if !NOGUI
gui, destroy
VarSetCapacity(FontFace, SizeOfFontFaceName)
DllCall("RtlMoveMemory", str, FontFace, Uint, &StructForLogFont + OffsetToFontFaceName, Uint, SizeOfFontFaceName)
; FontFace .
fontsize := ExtractInteger(StructForChooseFont, 16) // 10
SetFormat, integer, hex
Fontcolor := BGRtoRGB(ExtractInteger(StructForChooseFont, 24))SetFormat, integer, D
FType := ExtractInteger(StructForChooseFont, 49,0,2) & 0x07 ; ExtractInteger(StructForChooseFont, 48,0,2) > 8 & 0x0f
FontType := (Ftype = 4) ? "Norm" : (Ftype = 3) ? "bold italic" : (Ftype = 2) ? "italic" : (Ftype = 1) ? "bold" : ""
Font := FontFace
if fontsize
Options .= "S" . fontsize
if FontColor {
SetFormat, integer, hex ; Show RGB color extracted below in hex format.
Options .= " C" . FontColor
SetFormat, integer, d
}
if FontType
Options .= " " . FontType
return
}
ExtractInteger(ByRef pSource, pOffset = 0, pIsSigned = false, pSize = 4)
; See DllCall documentation for details.
{
SourceAddress := &pSource + pOffset ; Get address and apply the caller's offset.
result := 0 ; Init prior to accumulation in the loop.
Loop %pSize% ; For each byte in the integer:
{
result := result | (*SourceAddress << 8 * (A_Index - 1)) ; Build the integer from its bytes.
SourceAddress += 1 ; Move on to the next byte.
}
if (!pIsSigned OR pSize > 4 OR result < 0x80000000)
return result ; Signed vs. unsigned doesn't matter in these cases.
; Otherwise, convert the value (now known to be 32-bit) to its signed counterpart:
return -(0xFFFFFFFF - result + 1)
}
InsertInteger(pInteger, ByRef pDest, pOffset = 0, pSize = 4)
; To preserve any existing contents in pDest, only pSize number of bytes starting at
; pOffset are altered in it. The caller must ensure that pDest has sufficient capacity.
{
mask := 0xFF ; This serves to isolate each byte, one by one.
Loop %pSize% ; Copy each byte in the integer into the structure as raw binary data.
{
DllCall("RtlFillMemory", UInt, &pDest + pOffset + A_Index - 1, UInt, 1 ; Write one byte.
, UChar, (pInteger & mask) >> 8 * (A_Index - 1)) ; This line is auto-merged with above at load-time.
mask := mask << 8 ; Set it up for isolation of the next byte.
}
}
BGRtoRGB(oldValue)
{
Value := (oldValue & 0x00ff00)
Value += ((oldValue & 0xff0000) >> 16)
Value += ((oldValue & 0x0000ff) << 16)
return Value
}
ok, first update.. and this is a working but still slightly incomplete function , simply have not been ably yet to come back back to polish off... It does (mostly) work... ,
Code:
FontSelect( byref Font,byref Options, byref StructForChooseFont , x = "300", y = "100") {
SizeOfStructForChooseFont = 60
OffsetToFontFaceName = 28
SizeOfFontFaceName = 32
SizeOfStructForLogFont := OffsetToFontFaceName + SizeOfFontFaceName
VarSetCapacity(StructForLogFont, SizeOfStructForLogFont) ; No need to zero it.
if !StructForChooseFont {
VarSetCapacity(StructForChooseFont, SizeOfStructForChooseFont, 0)
InsertInteger(&StructForLogFont, StructForChooseFont, 12) ; LPLOGFONT lpLogFont
InsertInteger(SizeOfStructForChooseFont, StructForChooseFont, 0) ; DWORD lStructSize
InsertInteger(0x101, StructForChooseFont, 20)
; Above is DWORD Flags: CF_EFFECTS = 0x100, CF_SCREENFONTS = 1 (omit printer fonts)
}
; gui show, x%x% y%y%
Gui, +LastFound
GuiHWND := WinExist() ; Relies on the line above to get the unique ID of GUI window.
InsertInteger(GuiHWND, StructForChooseFont, 4) ; HWND hwndOwner (makes dialog "modal").
;ButtonSelectFont:
if not DllCall("comdlg32\ChooseFontA", str, StructForChooseFont) { ; Display the dialog.
; gui, destroy
return ; The user canceled the dialog.
} ; Otherwise, the user pressed OK in the dialog, so determine what was selected.
;gui, destroy
VarSetCapacity(FontFace, SizeOfFontFaceName)
DllCall("RtlMoveMemory", str, FontFace, Uint, &StructForLogFont + OffsetToFontFaceName, Uint, SizeOfFontFaceName)
; FontFace .
regexmatch(Options,"( S\d++)",hasSize)
regexmatch(Options,"( C\s*0\s*[xX]\s*[0-9ABCDEFabcdef]++)",hasColor)
regexmatch(Options,"i)(Norm|bold italic|italic|bold)",hasType)
Options =
;;tooltip % ExtractInteger(StructForChooseFont, 16) "`n" ExtractInteger(StructForChooseFont, 16) / 10
fontsize := ExtractInteger(StructForChooseFont, 16) // 10
SetFormat, integer, hex ; Show RGB color extracted below in hex format.
Fontcolor := BGRtoRGB(ExtractInteger(StructForChooseFont, 24))
SetFormat, integer, d
;SetFormat, integer, hex
;tooltip % ExtractInteger(StructForChooseFont, 48,0,4) "`n" ExtractInteger(StructForChooseFont, 49,0,2) & 0x07 "`n" ExtractInteger(StructForChooseFont, 50,0,4) "`n"
FType := ExtractInteger(StructForChooseFont, 49,0,2) & 0x07 ; ExtractInteger(StructForChooseFont, 48,0,2) > 8 & 0x0f
FontType := (Ftype = 4) ? "Norm" : (Ftype = 3) ? "bold italic" : (Ftype = 2) ? "italic" : (Ftype = 1) ? "bold" : ""
;tooltip % Ftype " " FontType
Font := FontFace
Options .= (fontsize) ? " S" . fontsize : hasSize
if (FontColor != "") {
SetFormat, integer, hex ; Show RGB color extracted below in hex format.
Options .= " C" . FontColor
SetFormat, integer, d
} else
Options .= hasColor
Options .= (FontType) ? " " . FontType : " " . hasType
return
}