Modify ↓
Opened 7 months ago
Last modified 7 months ago
#3946 new Feature Request
_ChooseFont() updated defaults
Reported by: | argumentum | Owned by: | |
---|---|---|---|
Milestone: | Component: | Standard UDFs | |
Version: | Severity: | None | |
Keywords: | Cc: |
Description
added Default(keyword) to entries and color lookup, as the default of 0x0 is not always a visible color.
; #FUNCTION# ==================================================================================================================== ; Author ........: Gary Frost (gafrost) ; Modified.......: argumentum ; =============================================================================================================================== Func _ChooseFont($sFontName = "Courier New", $iPointSize = 10, $iFontColorRef = Default, $iFontWeight = 0, $bItalic = False, $bUnderline = False, $bStrikethru = False, $hWndOwner = 0) Local $iItalic = 0, $iUnderline = 0, $iStrikeout = 0 ,$COLOR_BTNTEXT = 18 If $sFontName = Default Then $sFontName = "Courier New", If $iPointSize = Default Then $iPointSize = 10 If $iFontColorRef = Default Then $iFontColorRef = 0 $aRet = DllCall("user32.dll", "INT", "GetSysColor", "int", $COLOR_BTNTEXT) If Not @error Then $iFontColorRef = $aRet[0] EndIf If $iFontWeight = Default Then $iFontWeight = 0 If $bItalic = Default Then $bItalic = False If $bUnderline = Default Then $bUnderline = False If $bStrikethru = Default Then $bStrikethru = False, If $hWndOwner = Default Then $hWndOwner = 0 $iFontColorRef = BitOR(BitShift(BitAND($iFontColorRef, 0x000000FF), -16), BitAND($iFontColorRef, 0x0000FF00), BitShift(BitAND($iFontColorRef, 0x00FF0000), 16)) Local $hDC = __MISC_GetDC(0) Local $iHeight = Round(($iPointSize * __MISC_GetDeviceCaps($hDC, $LOGPIXELSX)) / 72, 0) __MISC_ReleaseDC(0, $hDC) Local $tChooseFont = DllStructCreate($tagCHOOSEFONT) Local $tLogFont = DllStructCreate($tagLOGFONT) DllStructSetData($tChooseFont, "Size", DllStructGetSize($tChooseFont)) DllStructSetData($tChooseFont, "hWndOwner", $hWndOwner) DllStructSetData($tChooseFont, "LogFont", DllStructGetPtr($tLogFont)) DllStructSetData($tChooseFont, "PointSize", $iPointSize) DllStructSetData($tChooseFont, "Flags", BitOR($CF_SCREENFONTS, $CF_PRINTERFONTS, $CF_EFFECTS, $CF_INITTOLOGFONTSTRUCT, $CF_NOSCRIPTSEL)) DllStructSetData($tChooseFont, "rgbColors", $iFontColorRef) DllStructSetData($tChooseFont, "FontType", 0) DllStructSetData($tLogFont, "Height", $iHeight) DllStructSetData($tLogFont, "Weight", $iFontWeight) DllStructSetData($tLogFont, "Italic", $bItalic) DllStructSetData($tLogFont, "Underline", $bUnderline) DllStructSetData($tLogFont, "Strikeout", $bStrikethru) DllStructSetData($tLogFont, "FaceName", $sFontName) Local $aCall = DllCall("comdlg32.dll", "bool", "ChooseFontW", "struct*", $tChooseFont) If @error Then Return SetError(@error, @extended, -1) If $aCall[0] = 0 Then Return SetError(-3, -3, -1) ; user selected cancel or struct settings incorrect Local $sFaceName = DllStructGetData($tLogFont, "FaceName") If StringLen($sFaceName) = 0 And StringLen($sFontName) > 0 Then $sFaceName = $sFontName If DllStructGetData($tLogFont, "Italic") Then $iItalic = 2 If DllStructGetData($tLogFont, "Underline") Then $iUnderline = 4 If DllStructGetData($tLogFont, "Strikeout") Then $iStrikeout = 8 Local $iAttributes = BitOR($iItalic, $iUnderline, $iStrikeout) Local $iSize = DllStructGetData($tChooseFont, "PointSize") / 10 Local $iColorRef = DllStructGetData($tChooseFont, "rgbColors") Local $iWeight = DllStructGetData($tLogFont, "Weight") Local $sColor_picked = Hex(String($iColorRef), 6) Return StringSplit($iAttributes & "," & $sFaceName & "," & $iSize & "," & $iWeight & "," & $iColorRef & "," & '0x' & $sColor_picked & "," & '0x' & StringMid($sColor_picked, 5, 2) & StringMid($sColor_picked, 3, 2) & StringMid($sColor_picked, 1, 2), ",") EndFunc ;==>_ChooseFont
Attachments (0)
Change History (4)
comment:1 Changed 7 months ago by argumentum
comment:3 Changed 7 months ago by argumentum
The idea for updating these aspects comes from https://www.autoitscript.com/forum/topic/209809-_choosefontex/
comment:4 Changed 7 months ago by argumentum
hmm, I changed a few more things regarding errors:
Func _ChooseFont($sFontName = "Courier New", $iPointSize = 10, $iFontColorRef = Default, $iFontWeight = 0, $bItalic = False, $bUnderline = False, $bStrikethru = False, $hWndOwner = 0) Local $iItalic = 0, $iUnderline = 0, $iStrikeout = 0, $COLOR_BTNTEXT = 18, $iRetExtended = 0 If $sFontName = Default Then $sFontName = "Courier New" If $iPointSize = Default Then $iPointSize = 10 If $iFontColorRef = Default Then $iFontColorRef = 0 Local $aRet = DllCall("user32.dll", "INT", "GetSysColor", "int", $COLOR_BTNTEXT) If @error Then $iRetExtended = @error Else $iFontColorRef = $aRet[0] EndIf EndIf If $iFontWeight = Default Then $iFontWeight = 0 If $bItalic = Default Then $bItalic = False If $bUnderline = Default Then $bUnderline = False If $bStrikethru = Default Then $bStrikethru = False If $hWndOwner = Default Then $hWndOwner = 0 $iFontColorRef = BitOR(BitShift(BitAND($iFontColorRef, 0x000000FF), -16), BitAND($iFontColorRef, 0x0000FF00), BitShift(BitAND($iFontColorRef, 0x00FF0000), 16)) Local $hDC = __MISC_GetDC(0) Local $iHeight = Round(($iPointSize * __MISC_GetDeviceCaps($hDC, $LOGPIXELSX)) / 72, 0) __MISC_ReleaseDC(0, $hDC) Local $tChooseFont = DllStructCreate($tagCHOOSEFONT) Local $tLogFont = DllStructCreate($tagLOGFONT) DllStructSetData($tChooseFont, "Size", DllStructGetSize($tChooseFont)) DllStructSetData($tChooseFont, "hWndOwner", $hWndOwner) DllStructSetData($tChooseFont, "LogFont", DllStructGetPtr($tLogFont)) DllStructSetData($tChooseFont, "PointSize", $iPointSize) DllStructSetData($tChooseFont, "Flags", BitOR($CF_SCREENFONTS, $CF_PRINTERFONTS, $CF_EFFECTS, $CF_INITTOLOGFONTSTRUCT, $CF_NOSCRIPTSEL)) DllStructSetData($tChooseFont, "rgbColors", $iFontColorRef) DllStructSetData($tChooseFont, "FontType", 0) DllStructSetData($tLogFont, "Height", $iHeight) DllStructSetData($tLogFont, "Weight", $iFontWeight) DllStructSetData($tLogFont, "Italic", $bItalic) DllStructSetData($tLogFont, "Underline", $bUnderline) DllStructSetData($tLogFont, "Strikeout", $bStrikethru) DllStructSetData($tLogFont, "FaceName", $sFontName) Local $aCall = DllCall("comdlg32.dll", "bool", "ChooseFontW", "struct*", $tChooseFont) If @error Then Return SetError(@error, @extended, -2) ; ..to differentiate from the error below If $aCall[0] = 0 Then Return SetError(-3, $iRetExtended, -1) ; user selected cancel or struct settings incorrect Local $sFaceName = DllStructGetData($tLogFont, "FaceName") If StringLen($sFaceName) = 0 And StringLen($sFontName) > 0 Then $sFaceName = $sFontName If DllStructGetData($tLogFont, "Italic") Then $iItalic = 2 If DllStructGetData($tLogFont, "Underline") Then $iUnderline = 4 If DllStructGetData($tLogFont, "Strikeout") Then $iStrikeout = 8 Local $iAttributes = BitOR($iItalic, $iUnderline, $iStrikeout) Local $iSize = DllStructGetData($tChooseFont, "PointSize") / 10 Local $iColorRef = DllStructGetData($tChooseFont, "rgbColors") Local $iWeight = DllStructGetData($tLogFont, "Weight") Local $sColor_picked = Hex(String($iColorRef), 6) Return SetError(0, $iRetExtended, StringSplit($iAttributes & "," & $sFaceName & "," & $iSize & "," & $iWeight & "," & $iColorRef & "," & _ '0x' & $sColor_picked & "," & '0x' & StringMid($sColor_picked, 5, 2) & StringMid($sColor_picked, 3, 2) & StringMid($sColor_picked, 1, 2), ",")) EndFunc ;==>_ChooseFont
So now all errors are clearly returned. I think this is my last revision. =)
Guidelines for posting comments:
- You cannot re-open a ticket but you may still leave a comment if you have additional information to add.
- In-depth discussions should take place on the forum.
For more information see the full version of the ticket guidelines here.
Note: See
TracTickets for help on using
tickets.
oops, did not test the prior code before posting. Here's the working code: