ioa747 Posted yesterday at 12:50 AM Posted yesterday at 12:50 AM (edited) Fake checkbox's management ✅ Supports both "Outline" (✅/🔲) and "Solid" (☑️/⬛) styles. expandcollapse popup; https://www.autoitscript.com/forum/topic/213626-fake-checkboxs/#findComment-1551358 ;---------------------------------------------------------------------------------------- ; Title...........: UniCheckBox.au3 ; Description.....: Unicode checkbox's management ; AutoIt Version..: 3.3.18.0 Author: ioa747 Script Version: 4 ; Note............: Testet in Windows 11 Pro 25H2 Date:07/04/2025 ;---------------------------------------------------------------------------------------- #AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 -w 7 #include <GUIConstants.au3> _Main() Func _Main() Local $hGUI = GUICreate("UniCheckBox Example", 320, 200) GUISetFont(12) Local $idFCheck_Dark = GUICtrlCreateLabel("🔲 Dark Mode", 10, 10) Local $idFCheck_Solid = GUICtrlCreateLabel("🔲 Solid Mode", 160, 10) Local $idFCheck_Test1 = GUICtrlCreateLabel("Test1 🔲", 10, 50) Local $idFCheck_Test2 = GUICtrlCreateLabel("Test2 🔲", 10, 80) GUISetState(@SW_SHOW) ; Array of controls for mass updates Local $aFCheck[5] = [4, $idFCheck_Dark, $idFCheck_Solid, $idFCheck_Test1, $idFCheck_Test2] While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit Case $idFCheck_Dark ; Toggle Dark Mode and get new status Local $bIsDark = _FCheckSet($idFCheck_Dark) ConsoleWrite("Dark Mode set to: " & $bIsDark & @CRLF) ; Update UI Colors Local $iBgCol = ($bIsDark ? 0x202020 : 0xF0F0F0) Local $iFgCol = ($bIsDark ? 0xF0F0F0 : 0x202020) GUISetBkColor($iBgCol, $hGUI) For $i = 1 To $aFCheck[0] GUICtrlSetBkColor($aFCheck[$i], $iBgCol) GUICtrlSetColor($aFCheck[$i], $iFgCol) Next Case $idFCheck_Solid ; Toggle Solid Style for all labels Local $bIsSolid = _FCheckSet($idFCheck_Solid) ConsoleWrite("Solid Mode set to: " & $bIsSolid & @CRLF) For $i = 1 To $aFCheck[0] Local $sTxt = GUICtrlRead($aFCheck[$i]) If $bIsSolid Then $sTxt = StringReplace(StringReplace($sTxt, "✅", "☑"), "🔲", "⬛") Else $sTxt = StringReplace(StringReplace($sTxt, "☑", "✅"), "⬛", "🔲") EndIf GUICtrlSetData($aFCheck[$i], $sTxt) Next Case $idFCheck_Test1 _FCheckSet($idFCheck_Test1) Case $idFCheck_Test2 _FCheckSet($idFCheck_Test2) EndSwitch WEnd EndFunc ;==>_Main ; #FUNCTION# ==================================================================================================================== ; Name...........: _IsFChecked ; Description ...: Checks the current state of a custom Unicode checkbox label. ; Parameters ....: $idControlID - The control identifier (ID) of the label. ; Return values .: True if checked (✅ or ☑), False if unchecked (🔲 or ⬛). ; Error values ..: 0 - Success. @extended contains the symbol's position. ; 1 - No supported symbols found. ; Author ........: ioa747 ; Remarks .......: This function strips the Unicode Variation Selector (U+FE0F) for better compatibility. ; =============================================================================================================================== Func _IsFChecked($idControlID) Local $sTxt = GUICtrlRead($idControlID) ; Clean up potential "Variation Selector" characters to avoid match failures $sTxt = StringReplace($sTxt, ChrW(0xFE0F), "") Local $iPos $iPos = StringInStr($sTxt, "✅") If $iPos > 0 Then Return SetError(0, $iPos, True) $iPos = StringInStr($sTxt, "☑") If $iPos > 0 Then Return SetError(0, $iPos, True) $iPos = StringInStr($sTxt, "🔲") If $iPos > 0 Then Return SetError(0, $iPos, False) $iPos = StringInStr($sTxt, "⬛") If $iPos > 0 Then Return SetError(0, $iPos, False) Return SetError(1, 0, False) EndFunc ;==>_IsFChecked ; #FUNCTION# ==================================================================================================================== ; Name...........: _FCheckSet ; Description ...: Sets or toggles the state of a custom Unicode checkbox label. ; Parameters ....: $idControlID - The control identifier (ID) of the label. ; $vStatus - [Optional] True to check, False to uncheck, Default to toggle current state. ; Return values .: The new state of the checkbox (True for Checked, False for Unchecked). ; Author ........: ioa747 ; Remarks .......: Automatically handles style preservation (Light/Solid). ; =============================================================================================================================== Func _FCheckSet($idControlID, $vStatus = Default) Local $sTxt = GUICtrlRead($idControlID) Local $bCurrent = _IsFChecked($idControlID) If $vStatus = Default Then $vStatus = Not $bCurrent Local $sNewTxt = StringReplace($sTxt, ChrW(0xFE0F), "") ; Clean string If $vStatus Then $sNewTxt = StringReplace(StringReplace($sNewTxt, "🔲", "✅"), "⬛", "☑") Else $sNewTxt = StringReplace(StringReplace($sNewTxt, "✅", "🔲"), "☑", "⬛") EndIf GUICtrlSetData($idControlID, $sNewTxt) Return $vStatus EndFunc ;==>_FCheckSet Please, every comment is appreciated! leave your comments and experiences here! Thank you very much Edited 15 hours ago by ioa747 Version: 4 argumentum, WildByDesign and UEZ 3 I know that I know nothing
argumentum Posted yesterday at 02:12 AM Posted yesterday at 02:12 AM It don't show as intended in my PC: 25H2 26200.8039 Windows Feature Experience Pack 1000.26100.300.0 ioa747 1 Follow the link to my code contribution ( and other things too ). FAQ - Please Read Before Posting.
FadeSoft Posted 22 hours ago Posted 22 hours ago That's really neat, I didn't even know that was possible. Thank you! ioa747 1
ioa747 Posted 18 hours ago Author Posted 18 hours ago (edited) @argumentum Reapproaching with a clear mind See if it appears as it should What changed? Instead of ☑️ use ☑. Instead of ✅️ use ✅. Automatic removal of U+FE0F (Variation Selector-16), for better compatibility (This "invisible" character tells the system: "Show the previous character as a colored Emoji and not as plain text") Edited 15 hours ago by ioa747 argumentum 1 I know that I know nothing
WildByDesign Posted 16 hours ago Posted 16 hours ago This is really nice. I like the idea. And it works very well. Question: How does it render the checkbox? My guess is that the font used for the GUI must render based on the checkbox character from in the code. Is that right? I notice that the label range for clicking on the checkbox is too big. For example, add $WS_BORDER to the end of one of the labels and you can see how big the range is. It is allowing to click on checkbox when cursor is about 12 pixels below the checkbox. My suggestion would be to use -1 for width and -1 for height for the checkbox labels to fit the text size better. ioa747 1
ioa747 Posted 15 hours ago Author Posted 15 hours ago @WildByDesign You are absolutely right! The checkbox is rendered as a Unicode character supported by the system's default font. Regarding the label size, using -1 for width and height is a great suggestion to make the clickable area fit the text perfectly and avoid 'ghost' clicks below the symbol. I have updated the code to use autosizing for the labels. argumentum and WildByDesign 1 1 I know that I know nothing
argumentum Posted 14 hours ago Posted 14 hours ago ...nice hmmm, should we ask to "fix" AutoIt3 to work with emoji ? ( make a trac entry ) Spoiler expandcollapse popup; https://www.autoitscript.com/forum/topic/213626-fake-checkboxs/#findComment-1551358 ;---------------------------------------------------------------------------------------- ; Title...........: UniCheckBox.au3 ; Description.....: Unicode checkbox's management ; AutoIt Version..: 3.3.18.0 Author: ioa747 Script Version: 4 ; Note............: Testet in Windows 11 Pro 25H2 Date:07/04/2025 ; Remarks.........: argumentum is curious about stuff 🤷♂️ ;---------------------------------------------------------------------------------------- #AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 -w 7 #include <GUIConstants.au3> Global Const $g_sChkMrk_LC = ChrW(0x2705) ; "✅" Global Const $g_sChkMrk_DC = ChrW(0x2611) ; "☑" Global Const $g_sChkMrk_LU = _ChrW_Ex(0x01F532) ; "🔲" ; hi/low surrogate stuff Global Const $g_sChkMrk_DU = ChrW(0x2B1B) ; "⬛" ;~ Global Const $g_sChkMrk_LC = "✅" ;~ Global Const $g_sChkMrk_DC = "☑" ;~ Global Const $g_sChkMrk_LU = "🔲" ;~ Global Const $g_sChkMrk_DU = "⬛" ConsoleWrite('- ' & "✅" & @TAB & '0x' & Hex(_AscW_Ex("✅"), 6) & @CRLF) ; 0x2705 ConsoleWrite('- ' & "☑" & @TAB & '0x' & Hex(_AscW_Ex("☑"), 6) & @CRLF) ; 0x2611 ConsoleWrite('- ' & "🔲" & @TAB & '0x' & Hex(_AscW_Ex("🔲"), 6) & @CRLF) ; 0x01F532 ConsoleWrite('- ' & "⬛" & @TAB & '0x' & Hex(_AscW_Ex("⬛"), 6) & @CRLF) ; 0x2B1B _Main() Func _Main() Local $hGUI = GUICreate("UniCheckBox Example", 320, 200) GUISetFont(12) Local $idFCheck_Dark = GUICtrlCreateLabel($g_sChkMrk_LU & " Dark Mode", 10, 10) Local $idFCheck_Solid = GUICtrlCreateLabel($g_sChkMrk_LU & " Solid Mode", 160, 10) Local $idFCheck_Test1 = GUICtrlCreateLabel("Test1 " & $g_sChkMrk_LU, 10, 50) Local $idFCheck_Test2 = GUICtrlCreateLabel("Test2 " & $g_sChkMrk_LU, 10, 80) GUISetState(@SW_SHOW) ; Array of controls for mass updates Local $aFCheck[5] = [4, $idFCheck_Dark, $idFCheck_Solid, $idFCheck_Test1, $idFCheck_Test2] While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit Case $idFCheck_Dark ; Toggle Dark Mode and get new status Local $bIsDark = _FCheckSet($idFCheck_Dark) ConsoleWrite("Dark Mode set to: " & $bIsDark & @CRLF) ; Update UI Colors Local $iBgCol = ($bIsDark ? 0x202020 : 0xF0F0F0) Local $iFgCol = ($bIsDark ? 0xF0F0F0 : 0x202020) GUISetBkColor($iBgCol, $hGUI) For $i = 1 To $aFCheck[0] GUICtrlSetBkColor($aFCheck[$i], $iBgCol) GUICtrlSetColor($aFCheck[$i], $iFgCol) Next Case $idFCheck_Solid ; Toggle Solid Style for all labels Local $bIsSolid = _FCheckSet($idFCheck_Solid) ConsoleWrite("Solid Mode set to: " & $bIsSolid & @CRLF) For $i = 1 To $aFCheck[0] Local $sTxt = GUICtrlRead($aFCheck[$i]) If $bIsSolid Then $sTxt = StringReplace(StringReplace($sTxt, $g_sChkMrk_LC, $g_sChkMrk_DC), $g_sChkMrk_LU, $g_sChkMrk_DU) Else $sTxt = StringReplace(StringReplace($sTxt, $g_sChkMrk_DC, $g_sChkMrk_LC), $g_sChkMrk_DU, $g_sChkMrk_LU) EndIf GUICtrlSetData($aFCheck[$i], $sTxt) Next Case $idFCheck_Test1 _FCheckSet($idFCheck_Test1) Case $idFCheck_Test2 _FCheckSet($idFCheck_Test2) EndSwitch WEnd EndFunc ;==>_Main ; #FUNCTION# ==================================================================================================================== ; Name...........: _IsFChecked ; Description ...: Checks the current state of a custom Unicode checkbox label. ; Parameters ....: $idControlID - The control identifier (ID) of the label. ; Return values .: True if checked (✅ or ☑), False if unchecked (🔲 or ⬛). ; Error values ..: 0 - Success. @extended contains the symbol's position. ; 1 - No supported symbols found. ; Author ........: ioa747 ; Remarks .......: This function strips the Unicode Variation Selector (U+FE0F) for better compatibility. ; =============================================================================================================================== Func _IsFChecked($idControlID) Local $sTxt = GUICtrlRead($idControlID) ; Clean up potential "Variation Selector" characters to avoid match failures ;~ $sTxt = StringReplace($sTxt, ChrW(0xFE0F), "") Local $iPos $iPos = StringInStr($sTxt, $g_sChkMrk_LC) If $iPos > 0 Then Return SetError(0, $iPos, True) $iPos = StringInStr($sTxt, $g_sChkMrk_DC) If $iPos > 0 Then Return SetError(0, $iPos, True) $iPos = StringInStr($sTxt, $g_sChkMrk_LU) If $iPos > 0 Then Return SetError(0, $iPos, False) $iPos = StringInStr($sTxt, $g_sChkMrk_DU) If $iPos > 0 Then Return SetError(0, $iPos, False) Return SetError(1, 0, False) EndFunc ;==>_IsFChecked ; #FUNCTION# ==================================================================================================================== ; Name...........: _FCheckSet ; Description ...: Sets or toggles the state of a custom Unicode checkbox label. ; Parameters ....: $idControlID - The control identifier (ID) of the label. ; $vStatus - [Optional] True to check, False to uncheck, Default to toggle current state. ; Return values .: The new state of the checkbox (True for Checked, False for Unchecked). ; Author ........: ioa747 ; Remarks .......: Automatically handles style preservation (Light/Solid). ; =============================================================================================================================== Func _FCheckSet($idControlID, $vStatus = Default) Local $sTxt = GUICtrlRead($idControlID) Local $bCurrent = _IsFChecked($idControlID) If $vStatus = Default Then $vStatus = Not $bCurrent Local $sNewTxt = $sTxt ; StringReplace($sTxt, ChrW(0xFE0F), "") ; Clean string If $vStatus Then $sNewTxt = StringReplace(StringReplace($sNewTxt, $g_sChkMrk_LU, $g_sChkMrk_LC), $g_sChkMrk_DU, $g_sChkMrk_DC) Else $sNewTxt = StringReplace(StringReplace($sNewTxt, $g_sChkMrk_LC, $g_sChkMrk_LU), $g_sChkMrk_DC, $g_sChkMrk_DU) EndIf GUICtrlSetData($idControlID, $sNewTxt) Return $vStatus EndFunc ;==>_FCheckSet Func _AscW_Ex($sString) Local $iFirst = AscW($sString) ; Check if this is a High Surrogate (0xD800 to 0xDBFF) If $iFirst >= 0xD800 And $iFirst <= 0xDBFF Then Local $iSecond = AscW(StringMid($sString, 2, 1)) ; Combine pairs using the UTF-16 formula Return 0x10000 + BitShift($iFirst - 0xD800, -10) + ($iSecond - 0xDC00) EndIf Return $iFirst ;~ ; Testing with White Square Button (🔳) ;~ Local $sEmoji = "🔳" ;~ MsgBox(0, "Unicode Code Point", "0x" & Hex(_AscW_Ex($sEmoji), 4)) ;~ ; Returns 0x1F533 EndFunc Func _ChrW_Ex($iCodePoint) If $iCodePoint <= 0xFFFF Then Return ChrW($iCodePoint) ; Calculate surrogates for codes above 0xFFFF Local $iTemp = $iCodePoint - 0x10000 Local $iHigh = BitOR(0xD800, BitShift($iTemp, 10)) Local $iLow = BitOR(0xDC00, BitAND($iTemp, 0x3FF)) Return ChrW($iHigh) & ChrW($iLow) ;~ ; Testing with the result from above ;~ MsgBox(0, "Result", _ChrW_Ex(0x1F533)) ; Displays 🔳 EndFunc because ..., I was expecting ChrW() to give me the whole enchilada but I have to be aware of stuff I don't understand as a scripter 🤔 Programmers know about bitwise stuff and what a surrogate is, but me.. 🤷♂️ @jpm what do you think ? ( because it would fall into your lap anyway ) ioa747 and WildByDesign 2 Follow the link to my code contribution ( and other things too ). FAQ - Please Read Before Posting.
UEZ Posted 14 hours ago Posted 14 hours ago (edited) How about colored checkboxes? expandcollapse popup;Coded by UEZ build 2026-04-07 ;Direct2D code by Eukalyptus / trancexx ;Proof of concept version #include <GDIPlus.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <WinAPIGdi.au3> #region D2D init If @OSBuild < 9600 Then Exit MsgBox($MB_ICONERROR, "ERROR", "Windows 8.1 or higher required!", 30) Global Const $WICERR_NOOBJ = 0x800710D8 Global Const $sGUID_WICPixelFormat32bppPBGRA = "{6fddc324-4e03-4bfe-b185-3d77768dc910}" Global Const $sCLSID_WICImagingFactory = "{cacaf262-9370-4615-a13b-9f5539da4c0a}" Global Const $sIID_IWICImagingFactory = "{ec5ec8a9-c395-4314-9c77-54d7a935ff70}" Global Const $sIID_IWICBitmap = "{00000121-a8f2-4877-ba0a-fd2b6645fb94}" Global Const $tagIWICBitmapSource = "GetSize hresult(uint*;uint*);" & "GetPixelFormat hresult(struct*);" & "GetResolution hresult(double*;double*);" & "CopyPalette hresult(struct*);" & "CopyPixels hresult(struct*;uint;uint;struct*);" Global Const $tagIWICImagingFactory = "CreateDecoderFromFilename hresult(wstr;struct*;uint;uint;ptr*);" & "CreateDecoderFromStream hresult(struct*;struct*;uint;ptr*);" & "CreateDecoderFromFileHandle hresult(handle;struct*;uint;ptr*);" & "CreateComponentInfo hresult(struct*;ptr*);" & "CreateDecoder hresult(struct*;struct*;ptr*);" & "CreateEncoder hresult(struct*;struct*;ptr*);" & "CreatePalette hresult(ptr*);" & "CreateFormatConverter hresult(ptr*);" & "CreateBitmapScaler hresult(ptr*);" & "CreateBitmapClipper hresult(ptr*);" & "CreateBitmapFlipRotator hresult(ptr*);" & "CreateStream hresult(ptr*);" & "CreateColorContext hresult(ptr*);" & "CreateColorTransformer hresult(ptr*);" & "CreateBitmap hresult(uint;uint;struct*;uint;ptr*);" & "CreateBitmapFromSource hresult(struct*;uint;ptr*);" & "CreateBitmapFromSourceRect hresult(struct*;uint;uint;uint;uint;ptr*);" & "CreateBitmapFromMemory hresult(uint;uint;struct*;uint;uint;struct*;ptr*);" & "CreateBitmapFromHBITMAP hresult(handle;handle;uint;ptr*);" & "CreateBitmapFromHICON hresult(handle;ptr*);" & "CreateComponentEnumerator hresult(uint;uint;ptr*);" & "CreateFastMetadataEncoderFromDecoder hresult(struct*;ptr*);" & "CreateFastMetadataEncoderFromFrameDecode hresult(struct*;ptr*);" & "CreateQueryWriter hresult(struct*;struct*;ptr*);" & "CreateQueryWriterFromReader hresult(struct*;struct*;ptr*);" Global Const $tagIWICBitmap = $tagIWICBitmapSource & "Lock hresult(struct*;uint;ptr*);" & "SetPalette hresult(struct*);" & "SetResolution hresult(double;double);" Global Const $DWRITEERR_NOOBJ = 0x800710D8 Global Const $sIID_IDWriteFactory = "{b859ee5a-d838-4b5b-a2e8-1adc7d93db48}" Global Const $sIID_IDWriteTextFormat = "{9c906818-31d7-4fd3-a151-7c5e225db55a}" Global Const $tagIDWriteFactory = "GetSystemFontCollection hresult(ptr*;bool);" & "CreateCustomFontCollection hresult(struct*;struct*;uint;ptr*);" & "RegisterFontCollectionLoader hresult(struct*);" & "UnregisterFontCollectionLoader hresult(struct*);" & "CreateFontFileReference hresult(wstr;struct*;ptr*);" & "CreateCustomFontFileReference hresult(struct*;uint;struct*;ptr*);" & "CreateFontFace hresult(uint;uint;struct*;uint;uint;ptr*);" & "CreateRenderingParams hresult(ptr*);" & "CreateMonitorRenderingParams hresult(handle;ptr*);" & "CreateCustomRenderingParams hresult(float;float;float;uint;uint;ptr*);" & "RegisterFontFileLoader hresult(struct*);" & "UnregisterFontFileLoader hresult(struct*);" & "CreateTextFormat hresult(wstr;struct*;uint;uint;uint;float;wstr;ptr*);" & "CreateTypography hresult(ptr*);" & "GetGdiInterop hresult(ptr*);" & "CreateTextLayout hresult(wstr;uint;struct*;float;float;ptr*);" & "CreateGdiCompatibleTextLayout hresult(wstr;uint;struct*;float;float;float;struct*;bool;ptr*);" & "CreateEllipsisTrimmingSign hresult(struct*;ptr*);" & "CreateTextAnalyzer hresult(ptr*);" & "CreateNumberSubstitution hresult(uint;wstr;bool;ptr*);" & "CreateGlyphRunAnalysis hresult(struct*;float;struct*;uint;uint;float;float;ptr*);" Global Const $tagIDWriteTextFormat = "SetTextAlignment hresult(uint);" & "SetParagraphAlignment hresult(uint);" & "SetWordWrapping hresult(uint);" & "SetReadingDirection hresult(uint);" & "SetFlowDirection hresult(uint);" & "SetIncrementalTabStop hresult(float);" & "SetTrimming hresult(struct*;ptr*);" & "SetLineSpacing hresult(uint;float;float);" & "GetTextAlignment uint();" & "GetParagraphAlignment uint();" & "GetWordWrapping uint();" & "GetReadingDirection uint();" & "GetFlowDirection uint();" & "GetIncrementalTabStop float();" & "GetTrimming hresult(struct*;ptr*);" & "GetLineSpacing hresult(uint*;float*float*);" & "GetFontCollection hresult(ptr*);" & "GetFontFamilyNameLength uint(wstr;uint);" & "GetFontFamilyName hresult();" & "GetFontWeight uint();" & "GetFontStyle uint();" & "GetFontStretch uint();" & "GetFontSize float();" & "GetLocaleNameLength uint();" & "GetLocaleName hresult(wstr;uint);" Global Const $D2DERR_NOOBJ = 0x800710D8 Global Const $D2DERR_UFAIL = 0x8000FFFF Global Const $tagD2D1_MATRIX_3X2_F = "struct; float M11; float M12; float M21; float M22; float M31; float M32; endstruct;" Global Const $tagD2D1_COLOR_F = "struct; float R; float G; float B; float A; endstruct;" Global Const $tagD2D1_RECT_F = "struct; float Left; float Top; float Right; float Bottom; endstruct;" Global Const $tagD2D1_BRUSH_PROPERTIES = "struct; float Opacity; float M11; float M12; float M21; float M22; float M31; float M32; endstruct;" Global Const $tagD2D1_RENDER_TARGET_PROPERTIES = "struct; uint Type; uint PixelFormat; uint AlphaMode; float DpiX; float DpiY; uint Usage; uint MinLevel; endstruct;" Global Const $sIID_ID2D1SolidColorBrush = "{2cd906a9-12e2-11dc-9fed-001143a055f9}" Global Const $sIID_ID2D1RenderTarget = "{2cd90694-12e2-11dc-9fed-001143a055f9}" Global Const $sIID_ID2D1Factory = "{06152247-6f50-465a-9245-118bfd3b6007}" Global Const $tagID2D1Resource = "GetFactory none(ptr*);" Global Const $tagID2D1Brush = $tagID2D1Resource & "SetOpacity none(float);" & "SetTransform none(struct*);" & "GetOpacity float();" & "GetTransform none(struct*);" Global Const $tagID2D1SolidColorBrush = $tagID2D1Brush & "SetColor none(struct*);" & "GetColor ptr(struct*);" Global Const $tagID2D1RenderTarget = $tagID2D1Resource & "CreateBitmap hresult(struct;struct*;uint;struct*;ptr*);" & "CreateBitmapFromWicBitmap hresult(struct*;struct*;ptr*);" & "CreateSharedBitmap hresult(struct*;struct*;struct*;ptr*);" & "CreateBitmapBrush hresult(struct*;struct*;struct*;ptr*);" & "CreateSolidColorBrush hresult(struct*;struct*;ptr*);" & "CreateGradientStopCollection hresult(struct*;uint;uint;uint;ptr*);" & "CreateLinearGradientBrush hresult(struct*;struct*;struct*;ptr*);" & "CreateRadialGradientBrush hresult(struct*;struct*;struct*;ptr*);" & "CreateCompatibleRenderTarget hresult(struct*;struct*;struct*;uint;ptr*);" & "CreateLayer hresult(struct*;ptr*);" & "CreateMesh hresult(ptr*);" & "DrawLine none(struct;struct;struct*;float;struct*);" & "DrawRectangle none(struct*;struct*;float;struct*);" & "FillRectangle none(struct*;struct*);" & "DrawRoundedRectangle none(struct*;struct*;float;struct*);" & "FillRoundedRectangle none(struct*;struct*);" & "DrawEllipse none(struct*;struct*;float;struct*);" & "FillEllipse none(struct*;struct*);" & "DrawGeometry none(struct*;struct*;float;struct*);" & "FillGeometry none(struct*;struct*;struct*);" & "FillMesh none(struct*;struct*);" & "FillOpacityMask none(struct*;struct*;uint;struct*;struct*);" & "DrawBitmap none(struct*;struct*;float;uint;struct*);" & "DrawText none(wstr;uint;struct*;struct*;struct*;uint;uint);" & "DrawTextLayout none(struct;struct*;struct*;uint);" & "DrawGlyphRun none(struct;struct*;struct*;uint);" & "SetTransform none(struct*);" & "GetTransform none(struct*);" & "SetAntialiasMode none(uint);" & "GetAntialiasMode uint();" & "SetTextAntialiasMode none(uint);" & "GetTextAntialiasMode uint();" & "SetTextRenderingParams none(struct*);" & "GetTextRenderingParams none(ptr*);" & "SetTags none(uint64;uint64);" & "GetTags none(uint64*;uint64*);" & "PushLayer none(struct*;struct*);" & "PopLayer none();" & "Flush hresult(uint64*;uint64*);" & "SaveDrawingState none(struct*);" & "RestoreDrawingState none(struct*);" & "PushAxisAlignedClip none(struct*;uint);" & "PopAxisAlignedClip none();" & "Clear none(struct*);" & "BeginDraw none();" & "EndDraw hresult(uint64*;uint64*);" & "GetPixelFormat ptr(struct*);" & "SetDpi none(float;float);" & "GetDpi none(float*;float*);" & "GetSize ptr(struct*);" & "GetPixelSize ptr(struct*);" & "GetMaximumBitmapSize uint();" & "IsSupported bool(struct*);" Global Const $tagID2D1Factory = "ReloadSystemMetrics hresult();" & "GetDesktopDpi none(float*;float*);" & "CreateRectangleGeometry hresult(struct*;ptr*);" & "CreateRoundedRectangleGeometry hresult(struct*;ptr*);" & "CreateEllipseGeometry hresult(struct*;ptr*);" & "CreateGeometryGroup hresult(uint;struct*;uint;ptr*);" & "CreateTransformedGeometry hresult(struct*;struct*;ptr*);" & "CreatePathGeometry hresult(ptr*);" & "CreateStrokeStyle hresult(struct*;struct*;uint;ptr*);" & "CreateDrawingStateBlock hresult(struct*;struct*;ptr*);" & "CreateWicBitmapRenderTarget hresult(struct*;struct*;ptr*);" & "CreateHwndRenderTarget hresult(struct*;struct*;ptr*);" & "CreateDxgiSurfaceRenderTarget hresult(struct*;struct*;ptr*);" & "CreateDCRenderTarget hresult(struct*;ptr*);" Global Const $D2D1_TEXT_ANTIALIAS_MODE_DEFAULT = 0 Global Const $D2D1_TEXT_ANTIALIAS_MODE_CLEARTYPE = 1 Global Const $D2D1_TEXT_ANTIALIAS_MODE_GRAYSCALE = 2 Global Const $D2D1_TEXT_ANTIALIAS_MODE_ALIASED = 3 Global Const $DWRITE_TEXT_ALIGNMENT_LEADING = 0 Global Const $DWRITE_TEXT_ALIGNMENT_TRAILING = 1 Global Const $DWRITE_TEXT_ALIGNMENT_CENTER = 2 Global Const $DWRITE_PARAGRAPH_ALIGNMENT_NEAR = 0 Global Const $DWRITE_PARAGRAPH_ALIGNMENT_FAR = 1 Global Const $DWRITE_PARAGRAPH_ALIGNMENT_CENTER = 2 Global Const $D2D1_ANTIALIAS_MODE_PER_PRIMITIVE = 0 Global Const $D2D1_ANTIALIAS_MODE_ALIASED = 1 Global Const $D2D1_DRAW_TEXT_OPTIONS_ENABLE_COLOR_FONT = 4 Global Const $DWRITE_MEASURING_MODE_NATURAL = 0 Global Const $__g_hD2D1DLL = DllOpen("d2d1.dll") Global Const $__g_hDWriteDLL = DllOpen("dwrite.dll") Global $oD2DFactory = _D2D_Factory_Create() If Not IsObj($oD2DFactory) Then MsgBox(16, "Error", "Failed to create D2D Factory!") Exit EndIf Global $oWICFactory = _WIC_ImagingFactory_Create() If Not IsObj($oWICFactory) Then MsgBox(16, "Error", "Failed to create WIC Imaging Factory!") Exit EndIf Global $oDWriteFactory = _DWrite_Factory_Create() If Not IsObj($oDWriteFactory) Then MsgBox(16, "Error", "Failed to create DWrite Factory!") Exit EndIf #EndRegion _GDIPlus_Startup() Global $hBmpUnchecked1 = D2D1_RenderEmojiToGDIpBitmap($oD2DFactory, $oWICFactory, $oDWriteFactory, "🔲", 16) Global $hBmpChecked1 = D2D1_RenderEmojiToGDIpBitmap($oD2DFactory, $oWICFactory, $oDWriteFactory, "✅", 16) Global $hBmpUnchecked2 = D2D1_RenderEmojiToGDIpBitmap($oD2DFactory, $oWICFactory, $oDWriteFactory, "⬛", 16) Global $hBmpChecked2 = D2D1_RenderEmojiToGDIpBitmap($oD2DFactory, $oWICFactory, $oDWriteFactory, "☑️", 16) Global $hGUI = GUICreate("Custom Checkbox using colored Emojis by UEZ", 237, 143) GUISetBkColor(0x282828) Global $bState1 = False Global $Pic1 = GUICtrlCreatePic("", 8, 8, 16, 16) GUICtrlSendMsg($Pic1, 0x0172, $IMAGE_BITMAP, $hBmpUnchecked1) Global $Label1 = GUICtrlCreateLabel("Checkbox1", 28, 8, 97, 17) GUICtrlSetColor(-1, 0xF0F0F0) GUICtrlSetCursor($Pic1, 0) GUICtrlSetCursor($Label1, 0) Global $bState2 = True Global $Pic2 = GUICtrlCreatePic("", 8, 40, 16, 16) GUICtrlSendMsg($Pic2, 0x0172, $IMAGE_BITMAP, $hBmpUnchecked2) Global $Label2 = GUICtrlCreateLabel("Checkbox2", 28, 40, 97, 17) GUICtrlSetColor(-1, 0xF0F0F0) GUICtrlSetCursor($Pic2, 0) GUICtrlSetCursor($Label2, 0) GUISetState(@SW_SHOW) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE _WinAPI_DeleteObject($hBmpChecked1) _WinAPI_DeleteObject($hBmpUnchecked1) _WinAPI_DeleteObject($hBmpChecked2) _WinAPI_DeleteObject($hBmpUnchecked2) _GDIPlus_Shutdown() Exit Case $Pic1, $Label1 $bState1 = Not $bState1 If $bState1 Then GUICtrlSendMsg($Pic1, 0x0172, $IMAGE_BITMAP, $hBmpChecked1) Else GUICtrlSendMsg($Pic1, 0x0172, $IMAGE_BITMAP, $hBmpUnchecked1) EndIf Case $Pic2, $Label2 $bState2 = Not $bState2 If $bState2 Then GUICtrlSendMsg($Pic2, 0x0172, $IMAGE_BITMAP, $hBmpChecked2) Else GUICtrlSendMsg($Pic2, 0x0172, $IMAGE_BITMAP, $hBmpUnchecked2) EndIf EndSwitch WEnd #Region D2D functions Func D2D1_RenderEmojiToGDIpBitmap($oD2DFactory, $oWICFactory, $oDWriteFactory, $sEmoji, $iSize, $bGDI = True) Local $oWICBitmap = _WIC_ImagingFactory_CreateBitmap($oWICFactory, $iSize, $iSize, $sGUID_WICPixelFormat32bppPBGRA, 0x1) If Not IsObj($oWICBitmap) Then Return SetError(-1, 0, 0) Local $oRenderTarget = _D2D_Factory_CreateWicBitmapRenderTarget($oD2DFactory, $oWICBitmap) If Not IsObj($oRenderTarget) Then $oWICBitmap = 0 Return SetError(-2, 0, 0) EndIf Local $oTextFormat = _DWrite_Factory_CreateTextFormat($oDWriteFactory, "Arial", $iSize * 0.75) If Not IsObj($oTextFormat) Then $oRenderTarget = 0 $oWICBitmap = 0 Return SetError(-3, 0, 0) EndIf $oTextFormat.SetTextAlignment($DWRITE_TEXT_ALIGNMENT_CENTER) $oTextFormat.SetParagraphAlignment($DWRITE_PARAGRAPH_ALIGNMENT_CENTER) $oRenderTarget.SetTextAntialiasMode($D2D1_TEXT_ANTIALIAS_MODE_ALIASED) $oRenderTarget.SetAntialiasMode($D2D1_ANTIALIAS_MODE_ALIASED) $oRenderTarget.BeginDraw() _D2D_RenderTarget_Clear($oRenderTarget, 0, 0, 0, 0) Local $oBrush = _D2D_RenderTarget_CreateSolidColorBrush($oRenderTarget, 0, 0, 0, 0) $oRenderTarget.DrawText($sEmoji, StringLen($sEmoji), $oTextFormat, _D2D1_RECT_F(0, 0, $iSize, $iSize), $oBrush, $D2D1_DRAW_TEXT_OPTIONS_ENABLE_COLOR_FONT, $DWRITE_MEASURING_MODE_NATURAL) $oRenderTarget.EndDraw(Null, Null) Local $hBitmap = _GDIPlus_BitmapCreateFromScan0($iSize, $iSize, $GDIP_PXF32ARGB) If Not $hBitmap Then $oBrush = 0 $oTextFormat = 0 $oRenderTarget = 0 $oWICBitmap = 0 Return SetError(-4, 0, 0) EndIf Local $tBitmapData = _GDIPlus_BitmapLockBits($hBitmap, 0, 0, $iSize, $iSize, $GDIP_ILMWRITE, $GDIP_PXF32ARGB) Local $pScan0 = $tBitmapData.Scan0 Local $iStride = BitAND(($iSize * 4 + 3), 0xFFFFFFFC) ;$iSize * 4 Local $tRect = DllStructCreate($tagRECT) $tRect.Left = 0 $tRect.Top = 0 $tRect.Right = $iSize $tRect.Bottom = $iSize $oWICBitmap.CopyPixels($tRect, $iStride, $iStride * $iSize, $pScan0) _GDIPlus_BitmapUnlockBits($hBitmap, $tBitmapData) $oBrush = 0 $oTextFormat = 0 $oRenderTarget = 0 $oWICBitmap = 0 If $bGDI Then Local $hGDI_Bmp = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hBitmap) If @error Or Not $hGDI_Bmp Then _GDIPlus_ImageDispose($hBitmap) Return SetError(-4, 0, 0) EndIf _GDIPlus_ImageDispose($hBitmap) Return $hGDI_Bmp EndIf Return $hBitmap EndFunc ;==>D2D1_RenderEmojiToGDIpBitmap Func _WIC_ImagingFactory_Create() Local $oObj = ObjCreateInterface($sCLSID_WICImagingFactory, $sIID_IWICImagingFactory, $tagIWICImagingFactory) If Not IsObj($oObj) Then Return SetError(0x80080001, 0, False) Return $oObj EndFunc ;==>_WIC_ImagingFactory_Create Func _WIC_ImagingFactory_CreateBitmap(Const ByRef $oIImagingFactory, $iWidth, $iHeight, $sPixelFormat = $sGUID_WICPixelFormat32bppPBGRA, $iOption = 0x2) If Not IsObj($oIImagingFactory) Then Return SetError($WICERR_NOOBJ, 0, False) Local $tGUID = _WinAPI_GUIDFromString($sPixelFormat) If @error Or Not IsDllStruct($tGUID) Then Return SetError(0x80070057, 1, False) Local $pBitmap Local $iHResult = $oIImagingFactory.CreateBitmap($iWidth, $iHeight, $tGUID, $iOption, $pBitmap) If $iHResult Or Not $pBitmap Then Return SetError($iHResult, 2, False) Local $oBitmap = ObjCreateInterface($pBitmap, $sIID_IWICBitmap, $tagIWICBitmap) If Not IsObj($oBitmap) Then Return SetError(0x80080001, 3, False) Return $oBitmap EndFunc ;==>_WIC_ImagingFactory_CreateBitmap Func _D2D_Factory_Create() Local $tIID_ID2D1Factory = _WinAPI_GUIDFromString($sIID_ID2D1Factory) Local $aResult = DllCall($__g_hD2D1DLL, "int", "D2D1CreateFactory", "uint", 0, "struct*", $tIID_ID2D1Factory, "uint*", 0, "ptr*", 0) If @error Then Return SetError($D2DERR_UFAIL, 1, False) If $aResult[0] Or Not $aResult[4] Then Return SetError($aResult[0], 2, False) Local $oFactory = ObjCreateInterface($aResult[4], $sIID_ID2D1Factory, $tagID2D1Factory) If Not IsObj($oFactory) Then Return SetError(0x80080001, 3, False) Return $oFactory EndFunc ;==>_D2D_Factory_Create Func _D2D_Factory_CreateWicBitmapRenderTarget(Const ByRef $oIFactory, Const ByRef $oWICBitmap, $iPixelFormat = 87, $iAlphaMode = 1, $fDpiX = 0, $fDpiY = 0, $iUsage = 0x00000000) If Not IsObj($oIFactory) Then Return SetError($D2DERR_NOOBJ, 0, False) If Not IsObj($oWICBitmap) Then Return SetError($D2DERR_NOOBJ, 1, False) Local $tD2D1_RENDER_TARGET_PROPERTIES = _D2D1_RENDER_TARGET_PROPERTIES(1, $iPixelFormat, $iAlphaMode, $fDpiX, $fDpiY, $iUsage, 0) Local $pRenderTarget Local $iHResult = $oIFactory.CreateWicBitmapRenderTarget($oWICBitmap, $tD2D1_RENDER_TARGET_PROPERTIES, $pRenderTarget) If $iHResult Or Not $pRenderTarget Then Return SetError($iHResult, 2, False) Local $oRenderTarget = ObjCreateInterface($pRenderTarget, $sIID_ID2D1RenderTarget, $tagID2D1RenderTarget) If Not IsObj($oRenderTarget) Then Return SetError(0x80080001, 3, False) Return $oRenderTarget EndFunc ;==>_D2D_Factory_CreateWicBitmapRenderTarget Func _D2D_RenderTarget_CreateSolidColorBrush(Const ByRef $oIRenderTarget, $fRed = 0, $fGreen = 0, $fBlue = 0, $fAlpha = 1, $fOpacity = 1) If Not IsObj($oIRenderTarget) Then Return SetError($D2DERR_NOOBJ, 0, False) Local $pSolidColorBrush Local $iHResult = $oIRenderTarget.CreateSolidColorBrush(_D2D1_COLOR_F($fRed, $fGreen, $fBlue, $fAlpha), _D2D1_BRUSH_PROPERTIES($fOpacity), $pSolidColorBrush) If $iHResult Or Not $pSolidColorBrush Then Return SetError($iHResult, 1, False) Local $oSolidColorBrush = ObjCreateInterface($pSolidColorBrush, $sIID_ID2D1SolidColorBrush, $tagID2D1SolidColorBrush) If Not IsObj($oSolidColorBrush) Then Return SetError(0x80080001, 2, False) Return $oSolidColorBrush EndFunc ;==>_D2D_RenderTarget_CreateSolidColorBrush Func _D2D_RenderTarget_Clear(Const ByRef $oIRenderTarget, $fR = 0, $fG = 0, $fB = 0, $fA = 1) If Not IsObj($oIRenderTarget) Then Return SetError($D2DERR_NOOBJ, 0, False) $oIRenderTarget.Clear(_D2D1_COLOR_F($fR, $fG, $fB, $fA)) Return True EndFunc ;==>_D2D_RenderTarget_Clear Func _D2D1_COLOR_F($fR = 0, $fG = 0, $fB = 0, $fA = 1) Local $tStruct = DllStructCreate($tagD2D1_COLOR_F) $tStruct.R = $fR $tStruct.G = $fG $tStruct.B = $fB $tStruct.A = $fA Return $tStruct EndFunc ;==>_D2D1_COLOR_F Func _D2D1_RECT_F($fLeft = 0, $fTop = 0, $fRight = 0, $fBottom = 0) Local $tStruct = DllStructCreate($tagD2D1_RECT_F) $tStruct.Left = $fLeft $tStruct.Top = $fTop $tStruct.Right = $fRight $tStruct.Bottom = $fBottom Return $tStruct EndFunc ;==>_D2D1_RECT_F Func _D2D1_SIZEOF(Const ByRef $sTag) Local $tStruct = DllStructCreate($sTag) Return DllStructGetSize($tStruct) EndFunc ;==>_D2D1_SIZEOF Func _D2D1_BRUSH_PROPERTIES($fOpacity = 0, $tMatrix = Null) Local $tStruct = DllStructCreate($tagD2D1_BRUSH_PROPERTIES) $tStruct.Opacity = $fOpacity If IsDllStruct($tMatrix) Then DllCall("kernel32.dll", "none", "RtlMoveMemory", "struct*", DllStructGetPtr($tStruct) + 4, "struct*", $tMatrix, "ulong_ptr", _D2D1_SIZEOF($tagD2D1_MATRIX_3X2_F)) Else $tStruct.M11 = 1 $tStruct.M22 = 1 EndIf Return $tStruct EndFunc ;==>_D2D1_BRUSH_PROPERTIES Func _D2D1_RENDER_TARGET_PROPERTIES($iType = 2, $iPixelFormat = 0, $iAlphaMode = 0, $fDpiX = 0, $fDpiY = 0, $iUsage = 0x00000000, $iMinLevel = 0) Local $tStruct = DllStructCreate($tagD2D1_RENDER_TARGET_PROPERTIES) $tStruct.Type = $iType $tStruct.PixelFormat = $iPixelFormat $tStruct.AlphaMode = $iAlphaMode $tStruct.DpiX = $fDpiX $tStruct.DpiY = $fDpiY $tStruct.Usage = $iUsage $tStruct.MinLevel = $iMinLevel Return $tStruct EndFunc ;==>_D2D1_RENDER_TARGET_PROPERTIES Func _DWrite_Factory_Create() Local $tIID_IDWriteFactory = _WinAPI_GUIDFromString($sIID_IDWriteFactory) Local $aResult = DllCall($__g_hDWriteDLL, "int", "DWriteCreateFactory", "uint", 0, "struct*", $tIID_IDWriteFactory, "ptr*", 0) If @error Or $aResult[0] Then Return SetError(1, 1, False) Local $oObj = ObjCreateInterface($aResult[3], $sIID_IDWriteFactory, $tagIDWriteFactory) If Not IsObj($oObj) Then Return SetError(0x80080001, 2, False) Return $oObj EndFunc ;==>_DWrite_Factory_Create Func _DWrite_Factory_CreateTextFormat(Const ByRef $oIFactory, $sFontFamilyName = "Arial", $fFontSize = 48, $iFontWeight = 400, $iFontStyle = 0, $iFontStretch = 5, $oFontCollection = Null, $sLocaleName = "en-us") If Not IsObj($oIFactory) Then Return SetError($DWRITEERR_NOOBJ, 0, False) If $oFontCollection <> Null And Not IsObj($oFontCollection) Then Return SetError($DWRITEERR_NOOBJ, 1, False) Local $pTextFormat Local $iHResult = $oIFactory.CreateTextFormat($sFontFamilyName, $oFontCollection, $iFontWeight, $iFontStyle, $iFontStretch, $fFontSize, $sLocaleName, $pTextFormat) If $iHResult Or Not $pTextFormat Then Return SetError($iHResult, 2, False) Local $oTextFormat = ObjCreateInterface($pTextFormat, $sIID_IDWriteTextFormat, $tagIDWriteTextFormat) If Not IsObj($oTextFormat) Then Return SetError(0x80080001, 3, False) Return $oTextFormat EndFunc ;==>_DWrite_Factory_CreateTextFormat #EndRegion 4 hours ago, ioa747 said: @argumentum Reapproaching with a clear mind Had too much Ouzo? 😉 Edited 13 hours ago by UEZ ioa747, argumentum and WildByDesign 2 1 Please don't send me any personal message and ask for support! I will not reply! Selection of finest graphical examples at Codepen.io The own fart smells best! ✌Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!¯\_(ツ)_/¯ ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ
ioa747 Posted 13 hours ago Author Posted 13 hours ago I didn't know/believed that there was a way to insert colored emojis in Autoit Thanks for the enlightenment I know that I know nothing
WildByDesign Posted 13 hours ago Posted 13 hours ago Just a curious thought: I wonder if it would be possible to use the Segoe Fluent Icons (with fallback to Segoe MDL2 Assets for Win10 users) as checkboxes and to actually color those font resources. Actually, now that I think about it, coloring it would be easy since it is a font within a label. Anyway, the thought just crossed my mind and figured I should share it. ioa747 1
ioa747 Posted 12 hours ago Author Posted 12 hours ago That is a very spot-on observation! Transitioning from Emojis to Segoe Fluent Icons (or MDL2 for Win10) is a great way to make the UI look more 'professional' and integrated with the OS. is far more efficient WildByDesign 1 I know that I know nothing
WildByDesign Posted 12 hours ago Posted 12 hours ago (edited) I’m not sure how far you plan to go with this script, so this is just an idea. To make the functionality feel more “alive”, I would suggest adding a very subtle text color change when the cursor hovers over any of the labels. I would probably use _WinAPI_ColorAdjustLuma with a very minor change to the current text color on hover. I suppose that could extend further if wanted to have a brief/quick text color change on click as well. But I think the hover is more important than click. Anyway, just some ideas that came to mind. Edited 12 hours ago by WildByDesign
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now