MattyD Posted October 10, 2025 Posted October 10, 2025 well, to be fair the win8 part is based on nothing - I doubt we even had dark mode back then... but yep, certainly it could just be a busted func. Especially if the others work as expected.
ioa747 Posted October 15, 2025 Posted October 15, 2025 (edited) trick for ToolTip with timer Func _ToolTip($sText, $iX = Default, $iY = Default, $sTitle = "", $iIcon = 0, $iTimeout = 1500, $iOptions = 0) AdlibUnRegister("_ToolTipKiller") ; This prevents the previous timer from closing the new tooltip. ToolTip($sText, $iX, $iY, $sTitle, $iIcon, $iOptions) AdlibRegister("_ToolTipKiller", $iTimeout) EndFunc ;==>_ToolTip Func _ToolTipKiller() ToolTip("") ; Hide the tooltip AdlibUnRegister("_ToolTipKiller") ; unregister itself. EndFunc ;==>_ToolTipKiller Example expandcollapse popup; https://www.autoitscript.com/forum/topic/139260-autoit-snippets/page/28/#findComment-1546696 ;---------------------------------------------------------------------------------------- ; Title...........: Trick for ToolTip with timer ; Description.....: Displays a native tooltip with timer. ; AutoIt Version..: 3.3.16.1 Author: ioa747 Script Version: 0.1 ; Note............: Testet in Win10 22H2 Date:16/10/2025 ;---------------------------------------------------------------------------------------- #AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 -w 7 #include <GUIConstantsEx.au3> Forms() Func Forms() Local $hGui = GUICreate(@ScriptName, 250, 150, -1, -1) Local $idBtn1 = GUICtrlCreateButton("Button 1", 10, 10, 100, 25) Local $idBtn2 = GUICtrlCreateButton("Button 2", 10, 40, 100, 25) Local $idBtn3 = GUICtrlCreateButton("Button 3", 10, 70, 100, 25) Local $idBtn4 = GUICtrlCreateButton("Button 4", 10, 100, 100, 25) GUISetState(@SW_SHOW, $hGui) While 1 Local $aWPos = WinGetPos($hGui) Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop Case $idBtn1 _ToolTip("...is clicked", $aWPos[0], $aWPos[1] - 15, "Button 1", 1) Case $idBtn2 _ToolTip("...is clicked", $aWPos[0], $aWPos[1] - 15, "Button 2", 1) Case $idBtn3 _ToolTip("...is clicked", $aWPos[0], $aWPos[1] - 15, "Button 3", 1) Case $idBtn4 _ToolTip("...is clicked", $aWPos[0], $aWPos[1] - 15, "Button 4", 1) EndSwitch WEnd GUIDelete($hGui) EndFunc ;==>Forms Func _ToolTip($sText, $iX = Default, $iY = Default, $sTitle = "", $iIcon = 0, $iTimeout = 1500, $iOptions = 0) AdlibUnRegister("_ToolTipKiller") ; This prevents the previous timer from closing the new tooltip. ToolTip($sText, $iX, $iY, $sTitle, $iIcon, $iOptions) AdlibRegister("_ToolTipKiller", $iTimeout) EndFunc ;==>_ToolTip Func _ToolTipKiller() ToolTip("") ; Hide the tooltip AdlibUnRegister("_ToolTipKiller") ; unregister itself. EndFunc ;==>_ToolTipKiller Edited October 15, 2025 by ioa747 prettify robertocm and Dan_555 2 I know that I know nothing
wakillon Posted October 28, 2025 Posted October 28, 2025 (edited) Trick for display your favorite directories in FileSaveDialog and FileOpenDialog with Win 11 The favorite directories are set in registry to : HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Policies\comdlg32\Placesbar Example of Placesbar Reg File Windows Registry Editor Version 5.00 [HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Policies\comdlg32\Placesbar] "Place1"="C:\\" "Place2"="C:\\Program Files (x86)\\AutoIt3\\Include" "Place4"="D:\\" "Place0"=dword:00000011 "Place3"=dword:00000010 11 is "My Computer" and 10 the Desktop #Region ;************ Includes ************ #Include <WinAPITheme.au3> #EndRegion ;************ Includes ************ $hGui = GUICreate('', 500, 500) GUISetState() ; Default display FileSaveDialog('Save file', @WorkingDir, 'Scripts (*.au3)', $FD_PATHMUSTEXIST, '', $hGui) ; ; Display with PlacesBar _WinAPI_SetThemeAppProperties($STAP_ALLOW_NONCLIENT) FileSaveDialog('Save file', @WorkingDir, 'Scripts (*.au3)', $FD_PATHMUSTEXIST, '', $hGui) FileOpenDialog('Select a file', @WorkingDir & '\', 'Images (*.jpg;*.bmp)', $FD_FILEMUSTEXIST, '', $hGui) ; ; Reset default display _WinAPI_SetThemeAppProperties(-1) FileSaveDialog('Save file', @WorkingDir, 'Scripts (*.au3)', $FD_PATHMUSTEXIST, '', $hGui) GUIDelete($hGui) Exit Edited October 28, 2025 by wakillon ioa747 and argumentum 2 AutoIt 3.3.18.0 X86 - SciTE 5.5.7 - WIN 11 24H2 X64 - Other Examples Scripts
FadeSoft Posted November 11, 2025 Posted November 11, 2025 (edited) Windows Efficiency Killer, makes every attempt to try and stop it from activating again! #RequireAdmin #include <MsgBoxConstants.au3> Local $sPSCmd = "Get-Process | ForEach-Object {" & _ " try {" & _ " $_.PriorityClass = 'Normal';" & _ " Write-Host ('Set normal priority for ' + $_.ProcessName)" & _ " } catch {" & _ " Write-Host ('Failed to change ' + $_.ProcessName + ': ' + $_.Exception.Message)" & _ " }" & _ " }" Local $sCmd = 'powershell -NoProfile -ExecutionPolicy Bypass -Command "' & StringReplace($sPSCmd, '"', '\"') & '"' RunWait('powercfg /setactive SCHEME_MIN', "", @SW_HIDE) RunWait(@ComSpec & " /c " & $sCmd, "", @SW_HIDE) RegWrite("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Power", "PowerThrottlingOff", "REG_DWORD", 1) MsgBox($MB_ICONINFORMATION, "Efficiency Mode", "All processes set to Normal priority (Efficiency Mode disabled).") Edited November 11, 2025 by FadeSoft
WildByDesign Posted November 13, 2025 Posted November 13, 2025 System Tray Menu Auto-Light/Dark Mode: If your system theme is a light mode theme, it will make the system tray menu light. Dark theme will show dark tray menu. I used to apply dark mode to the system tray menu before by creating a GUI that was never shown. But now I realized that I don't have to create that GUI and simply get the handle for the hidden AutoIt window and apply to that handle. expandcollapse popup#NoTrayIcon #include <MsgBoxConstants.au3> #include <StringConstants.au3> #include <TrayConstants.au3> #include <SendMessage.au3> #include <WindowsNotifsConstants.au3> Global $hTray = _GetHwndFromPID(@AutoItPID) Global $bIsDarkMode = _WinAPI_ShouldAppsUseDarkMode() ; DPI Awareness DllCall("User32.dll", "bool", "SetProcessDpiAwarenessContext" , "HWND", "DPI_AWARENESS_CONTEXT" -2) Opt("TrayMenuMode", 3) Example() Func Example() ; Create a tray item with the radio item parameter selected. TrayCreateItem("Radio 1", -1, -1, $TRAY_ITEM_RADIO) TrayItemSetState(-1, $TRAY_CHECKED) TrayCreateItem("Radio 2", -1, -1, $TRAY_ITEM_RADIO) TrayCreateItem("Radio 3", -1, -1, $TRAY_ITEM_RADIO) TrayCreateItem("") ; Create a separator line. Local $idExit = TrayCreateItem("Exit") TraySetState($TRAY_ICONSTATE_SHOW) ; Show the tray menu. If $bIsDarkMode Then DarkMode($hTray, True) While 1 Switch TrayGetMsg() Case $idExit ; Exit the loop. ExitLoop EndSwitch WEnd EndFunc ;==>Example ;-------------------------------------------------------------------------------------------------------------------------------- ; https://www.autoitscript.com/forum/topic/211475-darkmode-udf-for-autoits-win32guis/#comment-1530103 ;-------------------------------------------------------------------------------------------------------------------------------- Func DarkMode($hWnd, $bDarkMode = True) ; DarkMode Local Enum $DWMWA_USE_IMMERSIVE_DARK_MODE = (@OSBuild <= 18985) ? 19 : 20 Local $iRet = _WinAPI_DwmSetWindowAttribute_unr($hWnd, $DWMWA_USE_IMMERSIVE_DARK_MODE, $bDarkMode) If Not $iRet Then Return SetError(1, 0, -1) _SetCtrlColorMode($hWnd, $bDarkMode) EndFunc ;==>DarkMode ;-------------------------------------------------------------------------------------------------------------------------------- Func _SetCtrlColorMode($hWnd, $bDarkMode = True, $sName = Default) ; 'Explorer', 'CFD', 'DarkMode_ItemsView', etc. If $sName = Default Then $sName = $bDarkMode ? 'DarkMode_Explorer' : 'Explorer' $bDarkMode = Not Not $bDarkMode ; https://www.vbforums.com/showthread.php?900444-Windows-10-Dark-Mode-amp-VB6-apps If Not IsHWnd($hWnd) Then $hWnd = GUICtrlGetHandle($hWnd) Local Enum $eDefault, $eAllowDark, $eForceDark, $eForceLight, $eMax ; enum PreferredAppMode DllCall('uxtheme.dll', 'bool', 133, 'hwnd', $hWnd, 'bool', $bDarkMode) ; fnAllowDarkModeForWindow = 133 DllCall('uxtheme.dll', 'int', 135, 'int', ($bDarkMode ? $eForceDark : $eForceLight)) ; fnAllowDarkModeForApp = 135 _WinAPI_SetWindowTheme_unr($hWnd, $sName) ; https://www.autoitscript.com/forum/index.php?showtopic=211475&view=findpost&p=1530103 DllCall('uxtheme.dll', 'none', 104) ; fnRefreshImmersiveColorPolicyState = 104 ; not needed ? _SendMessage($hWnd, $WM_THEMECHANGED, 0, 0) ; not needed ? EndFunc ;==>_SetCtrlColorMode ;-------------------------------------------------------------------------------------------------------------------------------- Func _WinAPI_SetWindowTheme_unr($hWnd, $sName = Null, $sList = Null) ; #include <WinAPITheme.au3> ; unthoughtful unrestricting mod. ;Causes a window to use a different set of visual style information than its class normally uses Local $sResult = DllCall('UxTheme.dll', 'long', 'SetWindowTheme', 'hwnd', $hWnd, 'wstr', $sName, 'wstr', $sList) If @error Then Return SetError(@error, @extended, 0) If $sResult[0] Then Return SetError(10, $sResult[0], 0) Return 1 EndFunc ;==>_WinAPI_SetWindowTheme_unr ;-------------------------------------------------------------------------------------------------------------------------------- Func _WinAPI_DwmSetWindowAttribute_unr($hWnd, $iAttribute, $iData) ; #include <WinAPIGdi.au3> ; unthoughtful unrestricting mod. ;Sets the value of the specified attributes for non-client rendering to apply to the window Local $aCall = DllCall('dwmapi.dll', 'long', 'DwmSetWindowAttribute', 'hwnd', $hWnd, 'dword', $iAttribute, _ 'dword*', $iData, 'dword', 4) If @error Then Return SetError(@error, @extended, 0) If $aCall[0] Then Return SetError(10, $aCall[0], 0) Return 1 EndFunc ;==>_WinAPI_DwmSetWindowAttribute_unr ;-------------------------------------------------------------------------------------------------------------------------------- Func _WinAPI_ShouldAppsUseDarkMode() Local $fnShouldAppsUseDarkMode = 132 Local $aResult = DllCall('UxTheme.dll', 'bool', $fnShouldAppsUseDarkMode) If @error Then Return SetError(@error, @extended, False) Return $aResult[0] EndFunc ;==>_WinAPI_ShouldAppsUseDarkMode ;-------------------------------------------------------------------------------------------------------------------------------- ; Function for getting HWND from PID Func _GetHwndFromPID($PID) $hWnd = 0 $winlist = WinList() For $i = 1 To $winlist[0][0] If $winlist[$i][0] <> "" Then $iPID2 = WinGetProcess($winlist[$i][1]) If $iPID2 = $PID Then $hWnd = $winlist[$i][1] ExitLoop EndIf EndIf Next Return $hWnd EndFunc ;==>_GetHwndFromPID ioa747 1
argumentum Posted December 2, 2025 Posted December 2, 2025 How do you translate "Desktop" to the user's language ? #include <WinAPIRes.au3> Exit ConsoleWrite(@CRLF & '>' & _LoadString_shell32(4162) & '<' & @CRLF & @CRLF) Func _LoadString_shell32($iID) ; 4162 = "Desktop" Local $sText = "", $hInstance = _WinAPI_LoadLibraryEx("shell32.dll", $LOAD_LIBRARY_AS_DATAFILE) If $hInstance Then $sText = _WinAPI_LoadString($hInstance, $iID) _WinAPI_FreeLibrary($hInstance) EndIf Return SetError(@error, @extended, $sText) EndFunc ;==>_LoadString_shell32 If your GUI is simple, you may just find all the strings you use in shell32.dll ioa747, wakillon, CYCho and 1 other 3 1 Follow the link to my code contribution ( and other things too ). FAQ - Please Read Before Posting.
Nine Posted December 8, 2025 Posted December 8, 2025 (edited) Here a generic reader of any WMI class : expandcollapse popup;#RequireAdmin ;#AutoIt3Wrapper_UseX64=y #include <Constants.au3> #include <Array.au3> #include <WinAPI.au3> #include <WindowsConstants.au3> ; #GenericRead# ==================================================================================================================== ; Name ..........: GenericRead.AU3 ; Description ...: Lists properties and objects generically from any WMI Class ; Author ........: Nine ; Created .......: 2025-12-08 ; Modified ......: ; Remarks .......: if MsgBox is too large to fit the screen, you can use mouse wheel to scroll up/down, left to top, right to bottom ; ================================================================================================================================== Opt("MustDeclareVars", True) Global Const $tagMOUSEHOOKSTRUCT = $tagPOINT & ";hwnd hwnd;uint wHitTestCode;ulong_ptr dwExtraInfo;dword mouseData;" Global $oHandler = ObjEvent("AutoIt.Error", ErrFunc) Global $hHook ;ReadClass ("Win32_Service") ;ReadClass("MSFT_PhysicalDisk", Default, Default, "\root\Microsoft\Windows\Storage") ReadClass("WMIMonitorID", Default, Default, "\root\wmi") Func ReadClass($sClass, $sProp = "*", $sWhere = "", $sNameSpace = "\root\CIMV2") If $sProp = Default Then $sProp = "*" If $sWhere = Default Then $sWhere = "" If $sNameSpace = Default Then $sNameSpace = "\root\CIMV2" Local $oWMIService = ObjGet("winmgmts:\\" & @ComputerName & $sNameSpace) Local $oItems = $oWMIService.ExecQuery('SELECT ' & $sProp & ' FROM ' & $sClass & ($sWhere <> "" ? ' WHERE ' & $sWhere : "")) If Not IsObj($oItems) Then Exit MsgBox($MB_OK, "Error", "Not an object") If Not $oItems.count Then Exit MsgBox($MB_OK, "Error", "Not found") Local $hStub = DllCallbackRegister(WH_MOUSE, "LRESULT", "int;wparam;lparam") $hHook = _WinAPI_SetWindowsHookEx($WH_MOUSE, DllCallbackGetPtr($hStub), 0, _WinAPI_GetCurrentThreadId()) Local $sList, $sProperty, $bFirst, $aTmp, $iCount = 0 For $oItem In $oItems $iCount += 1 $bFirst = True For $oProperty In $oItem.Properties_ If $bFirst Then $sList = "Origin = " & $oProperty.origin & @CRLF $bFirst = False EndIf If IsArray($oProperty.Value) Then $aTmp = $oProperty.Value $sProperty = _ArrayToString($aTmp) Else $sProperty = $oProperty.Value EndIf $sList &= $oProperty.Name & " = " & $sProperty & @CRLF Next If MsgBox($MB_OKCANCEL, $iCount & "/" & $oItems.count, $sList) = $IDCANCEL Then ExitLoop Next _WinAPI_UnhookWindowsHookEx($hHook) DllCallbackFree($hStub) EndFunc ;==>ReadClass Func WH_MOUSE($iMsg, $wParam, $lParam) If $iMsg Then Return _WinAPI_CallNextHookEx($hHook, $iMsg, $wParam, $lParam) Local $tMouse = DllStructCreate($tagMOUSEHOOKSTRUCT, $lParam) Local $hWnd = _WinAPI_GetAncestor($tMouse.hwnd, $GA_ROOT) If $wParam = $WM_MOUSEWHEEL Then Local $iDir = _WinAPI_HiWord($tMouse.mouseData) WinMove($hWnd, "", WinGetPos($hWnd)[0], WinGetPos($hWnd)[1] + ($iDir / 3)) ElseIf $wParam = $WM_LBUTTONDOWN Then If $tMouse.hwnd = $hWnd Then WinMove($hWnd, "", WinGetPos($hWnd)[0], 0) ElseIf $wParam = $WM_RBUTTONDOWN Then WinMove($hWnd, "", WinGetPos($hWnd)[0], @DesktopHeight - WinGetPos($hWnd)[3] - 50) EndIf Return _WinAPI_CallNextHookEx($hHook, $iMsg, $wParam, $lParam) EndFunc ;==>WH_MOUSE Func ErrFunc($oError) ConsoleWrite(@ScriptName & " (" & $oError.scriptline & ") : ==> Global COM error handler - COM Error intercepted !" & @CRLF & _ @TAB & "err.number is: " & @TAB & @TAB & "0x" & Hex($oError.number) & "/" & $oError.number & @CRLF & _ @TAB & "err.windescription:" & @TAB & $oError.windescription & @CRLF & _ @TAB & "err.description is: " & @TAB & $oError.description & @CRLF & _ @TAB & "err.source is: " & @TAB & @TAB & $oError.source & @CRLF & _ @TAB & "err.helpfile is: " & @TAB & $oError.helpfile & @CRLF & _ @TAB & "err.helpcontext is: " & @TAB & $oError.helpcontext & @CRLF & _ @TAB & "err.lastdllerror is: " & @TAB & $oError.lastdllerror & @CRLF & _ @TAB & "err.scriptline is: " & @TAB & $oError.scriptline & @CRLF & _ @TAB & "err.retcode is: " & @TAB & "0x" & Hex($oError.retcode) & @CRLF & @CRLF) EndFunc ;==>ErrFunc Edited December 8, 2025 by Nine WildByDesign, ioa747 and mLipok 2 1 “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Debug Messages Monitor UDF Screen Scraping Round Corner GUI UDF Multi-Threading Made Easy Interface Object based on Tag
Popular Post wakillon Posted December 22, 2025 Popular Post Posted December 22, 2025 Drag and drop any Control in place of an other expandcollapse popup#Region ;************ Includes ************ #include <ButtonConstants.au3> #include <GuiConstantsEx.au3> #include <WinAPIGdi.au3> #EndRegion ;************ Includes ************ Opt('MustDeclareVars', 1) #Region ------ Global Variables ------------------------------ Global $hGui, $iButtonCount = 20, $iButtonSize = 40, $idMovingButton, $iHMargin = 10, $iVMargin = 10, $idMsg, $x, $y Global $aButtonId[$iButtonCount], $aButtonPos[$iButtonCount][2], $aCursorInfo #EndRegion ------ Global Variables ------------------------------ #Region ------ Gui Creation ------------------------------ $hGui = GUICreate('', 110, 510) GUISetFont(9.5, $FW_BOLD, $GUI_FONTNORMAL, 'Consolas') GUISetBkColor(0xA8A8A8) For $i = 0 To UBound($aButtonId) - 1 $aButtonPos[$i][0] = $iVMargin + ($iVMargin + $iButtonSize) * ($i > 9) ; x coord $aButtonPos[$i][1] = $iHMargin + ($iButtonSize + $iVMargin) * $i - 500 * ($i > 9) ; y coord $aButtonId[$i] = GUICtrlCreateRadio($i + 1, _ $aButtonPos[$i][0], _ $aButtonPos[$i][1], _ $iButtonSize, _ $iButtonSize, _ BitOR($BS_ICON, $BS_PUSHLIKE, $BS_FLAT, $BS_CENTER)) GUICtrlSetCursor(-1, 0) Next GUISetState() #EndRegion ------ Gui Creation ------------------------------ #Region ------ Main Loop ------------------------------ While 1 $idMsg = GUIGetMsg() Switch $idMsg Case $GUI_EVENT_CLOSE Exit Case $GUI_EVENT_PRIMARYDOWN Sleep(150) Do $aCursorInfo = GUIGetCursorInfo($hGui) If Not @error Then $idMovingButton = $aCursorInfo[4] Until $idMovingButton If $aCursorInfo[2] Then Do $aCursorInfo = GUIGetCursorInfo($hGui) If Not @error Then ControlMove($hGui, _ '', _ $idMovingButton, _ $aCursorInfo[0] - $iButtonSize / 2, _ $aCursorInfo[1] - $iButtonSize / 2) Sleep(10) Until Not $aCursorInfo[2] $x = -1 For $i = 0 To UBound($aButtonPos) - 1 ; check if Moving ctrl is over an other ctrl If $i <> ($idMovingButton - $aButtonId[0]) And _WinAPI_PtInRectEx($aCursorInfo[0], _ $aCursorInfo[1], _ $aButtonPos[$i][0], _ ; x $aButtonPos[$i][1], _ ; y $aButtonPos[$i][0] + $iButtonSize, _ ; w $aButtonPos[$i][1] + $iButtonSize) Then ; h ControlMove($hGui, _ '', _ $aButtonId[$i], _ $aButtonPos[$idMovingButton - $aButtonId[0]][0], _ $aButtonPos[$idMovingButton - $aButtonId[0]][1]) ControlMove($hGui, _ '', _ $idMovingButton, _ $aButtonPos[$i][0], _ $aButtonPos[$i][1]) GUICtrlSetState($aButtonId[$i], $GUI_FOCUS) ; Save new positions $x = $aButtonPos[$idMovingButton - $aButtonId[0]][0] $y = $aButtonPos[$idMovingButton - $aButtonId[0]][1] $aButtonPos[$idMovingButton - $aButtonId[0]][0] = $aButtonPos[$i][0] $aButtonPos[$idMovingButton - $aButtonId[0]][1] = $aButtonPos[$i][1] $aButtonPos[$i][0] = $x $aButtonPos[$i][1] = $y ConsoleWrite('!->-- [' & StringFormat('%03i', @ScriptLineNumber) & '] Button ' & _ $idMovingButton - $aButtonId[0] + 1 & ' was moved in place of Button ' & $i + 1 & @CRLF) ExitLoop EndIf Next If $x = -1 Then ; place moved ctrl to his previous pos ControlMove($hGui, _ '', _ $idMovingButton, _ $aButtonPos[$idMovingButton - $aButtonId[0]][0], _ $aButtonPos[$idMovingButton - $aButtonId[0]][1]) ConsoleWrite('>->-- [' & StringFormat('%03i', @ScriptLineNumber) & '] Button ' & _ $idMovingButton - $aButtonId[0] + 1 & ' was moved but has been moved back to his previous position' & @CRLF) EndIf Else ConsoleWrite('+->-- [' & StringFormat('%03i', @ScriptLineNumber) & '] Button ' & _ $idMovingButton - $aButtonId[0] + 1 & ' was clicked' & @CRLF) EndIf Beep(1200, 50) EndSwitch Sleep(10) WEnd #EndRegion ------ Main Loop ------------------------------ Dan_555, ioa747, robertocm and 2 others 5 AutoIt 3.3.18.0 X86 - SciTE 5.5.7 - WIN 11 24H2 X64 - Other Examples Scripts
UEZ Posted Friday at 09:52 PM Posted Friday at 09:52 PM (edited) Convert Emojis to GDI+ using Direct2D / DWrite. expandcollapse popup;Coded by UEZ build 2026-01-10 ;Direct2D code by Eukalyptus / trancexx #include <GDIPlus.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <WinAPIGdi.au3> 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 _GDIPlus_Startup() Global $hGUI = GUICreate("DirectWrite Color Emoji -> GDI+ Bitmap", 600, 280) GUISetBkColor(0xF5F5F5) Global $hEmoji1 = D2D1_RenderEmojiToGDIpBitmap($oD2DFactory, $oWICFactory, $oDWriteFactory, _EmojiFromCodePoint(0x1F600), 96) ; 😀 Global $hEmoji2 = D2D1_RenderEmojiToGDIpBitmap($oD2DFactory, $oWICFactory, $oDWriteFactory, _EmojiFromCodePoint(0x1F525), 96) ; 🔥 Global $hEmoji3 = D2D1_RenderEmojiToGDIpBitmap($oD2DFactory, $oWICFactory, $oDWriteFactory, _EmojiFromCodePoint(0x1F680), 96) ; 🚀 Global $hEmoji4 = D2D1_RenderEmojiToGDIpBitmap($oD2DFactory, $oWICFactory, $oDWriteFactory, _EmojiFromCodePoint(0x2764), 96) ; ❤ GUISetState(@SW_SHOW) GUIRegisterMsg($WM_PAINT, "_OnPaint") _WinAPI_RedrawWindow($hGUI) While 1 Local $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE _Cleanup() Exit EndSwitch WEnd Func _OnPaint($hWnd, $iMsg, $wParam, $lParam) Local $tPaintStruct = DllStructCreate($tagPAINTSTRUCT) Local $hDC = _WinAPI_BeginPaint($hWnd, $tPaintStruct) If @error Then Return $GUI_RUNDEFMSG Local $hGraphics = _GDIPlus_GraphicsCreateFromHDC($hDC) _GDIPlus_GraphicsClear($hGraphics, 0xFFFFFFFF) _GDIPlus_GraphicsSetSmoothingMode($hGraphics, $GDIP_SMOOTHINGMODE_HIGHQUALITY) _GDIPlus_GraphicsSetTextRenderingHint($hGraphics, $GDIP_TEXTRENDERINGHINTANTIALIAS) Local $xPos = 80 If $hEmoji1 Then _GDIPlus_GraphicsDrawImage($hGraphics, $hEmoji1, $xPos, 30) If $hEmoji2 Then _GDIPlus_GraphicsDrawImage($hGraphics, $hEmoji2, $xPos + 110, 30) If $hEmoji3 Then _GDIPlus_GraphicsDrawImage($hGraphics, $hEmoji3, $xPos + 220, 30) If $hEmoji4 Then _GDIPlus_GraphicsDrawImage($hGraphics, $hEmoji4, $xPos + 330, 30) Local $hFamily = _GDIPlus_FontFamilyCreate("Segoe UI") Local $hFont = _GDIPlus_FontCreate($hFamily, 22, 1) Local $hFormat = _GDIPlus_StringFormatCreate() _GDIPlus_StringFormatSetAlign($hFormat, 1) Local $tLayout = _GDIPlus_RectFCreate(0, 160, 600, 50) $hBrush = _GDIPlus_BrushCreateSolid(0xFF1B5E20) _GDIPlus_GraphicsDrawStringEx($hGraphics, "DirectWrite + Direct2D + GDI+", $hFont, $tLayout, $hFormat, $hBrush) _GDIPlus_BrushDispose($hBrush) _GDIPlus_StringFormatDispose($hFormat) _GDIPlus_FontDispose($hFont) _GDIPlus_FontFamilyDispose($hFamily) _GDIPlus_GraphicsDispose($hGraphics) _WinAPI_EndPaint($hWnd, $tPaintStruct) Return $GUI_RUNDEFMSG EndFunc ;==>_OnPaint Func D2D1_RenderEmojiToGDIpBitmap($oD2DFactory, $oWICFactory, $oDWriteFactory, $sEmoji, $iSize) 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, "Segoe UI Emoji", $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 = $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 Return $hBitmap EndFunc ;==>D2D1_RenderEmojiToGDIpBitmap Func _Cleanup() If $hEmoji1 Then _GDIPlus_ImageDispose($hEmoji1) If $hEmoji2 Then _GDIPlus_ImageDispose($hEmoji2) If $hEmoji3 Then _GDIPlus_ImageDispose($hEmoji3) If $hEmoji4 Then _GDIPlus_ImageDispose($hEmoji4) _GDIPlus_Shutdown() GUIDelete($hGUI) DllClose($__g_hDWriteDLL) ;DllClose($__g_hD2D1DLL) ;crashing EndFunc ;==>_Cleanup ;https://unicode.org/emoji/charts/full-emoji-list.html Func _EmojiFromCodePoint($iCodePoint) ; Basic Multilingual Plane (BMP): U+0000 to U+FFFF If $iCodePoint <= 0xFFFF Then Return ChrW($iCodePoint) Local $iAdjusted = $iCodePoint - 0x10000 Local $iHigh = 0xD800 + BitShift($iAdjusted, 10) Local $iLow = 0xDC00 + BitAND($iAdjusted, 0x3FF) Return ChrW($iHigh) & ChrW($iLow) EndFunc ;==>_EmojiFromCodePoint 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 Edited 14 hours ago by UEZ small update ioa747, argumentum, mLipok and 1 other 2 2 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!¯\_(ツ)_/¯ ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ
mLipok Posted Friday at 10:04 PM Posted Friday at 10:04 PM @UEZ Do you have any link to a list of supported emoji ? Could you extend this example by making mask for this emoji which will act as a clickable area ? Thank you in advance Signature beginning:* Please remember: "AutoIt"..... * Wondering who uses AutoIt and what it can be used for ? * Forum Rules ** ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Code * for other useful stuff click the following button: Spoiler Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind. My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAP * WinSCP UDF * GHAPI UDF - modest begining - comunication with GitHub REST API * ErrorLog.au3 UDF - A logging Library * Include Dependency Tree (Tool for analyzing script relations) * Show_Macro_Values.au3 * My contribution to others projects or UDF based on others projects: * _sql.au3 UDF * POP3.au3 UDF * RTF Printer - UDF * XML.au3 UDF * ADO.au3 UDF * SMTP Mailer UDF * Dual Monitor resolution detection * * 2GUI on Dual Monitor System * _SciLexer.au3 UDF * SciTE - Lexer for console pane * Useful links: * Forum Rules * Forum etiquette * Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * Wiki: * Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Good coding practices in AutoIt * OpenOffice/LibreOffice/XLS Related: WriterDemo.au3 * XLS/MDB from scratch with ADOX IE Related: * How to use IE.au3 UDF with AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * IE in TaskScheduler * IE Embedded Control Versioning (use IE9+ and HTML5 in a GUI) * PDF Related: * How to get reference to PDF object embeded in IE * IE on Windows 11 * I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions * EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *I also encourage you to check awesome @trancexx code: * Create COM objects from modules without any demand on user to register anything. * Another COM object registering stuff * OnHungApp handler * Avoid "AutoIt Error" message box in unknown errors * HTML editor * winhttp.au3 related : * https://www.autoitscript.com/forum/topic/206771-winhttpau3-download-problem-youre-speaking-plain-http-to-an-ssl-enabled-server-port/ "Homo sum; humani nil a me alienum puto" - Publius Terentius Afer"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming" , be and \\//_. Anticipating Errors : "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty." Signature last update: 2023-04-24
UEZ Posted Friday at 11:12 PM Posted Friday at 11:12 PM (edited) 1 hour ago, mLipok said: @UEZ Do you have any link to a list of supported emoji ? Could you extend this example by making mask for this emoji which will act as a clickable area ? Thank you in advance What you see is GDI+ bitmaps which can be used in picture controls when converted to GDI bitmap format. Picture control is clickable. In D2D you can perform Hit Testing on a Text Layout using HitTestPoint. I never used it. You can refer to https://unicode.org/emoji/charts/full-emoji-list.html. Depending on your Windows version you can use them. Edited Friday at 11:20 PM by UEZ mLipok 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!¯\_(ツ)_/¯ ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ
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