-
Posts
7,432 -
Joined
-
Last visited
-
Days Won
93
UEZ last won the day on January 15
UEZ had the most liked content!
About UEZ

- Birthday 12/03/2007
Profile Information
-
Member Title
Never say never
-
Location
Germany
-
Interests
Computer, watching movies, football (soccer), being lazy :-)
UEZ's Achievements
-
Danyfirex reacted to a post in a topic:
Low-Polygon Maker v0.70 build 2026-02-20
-
argumentum reacted to a post in a topic:
Low-Polygon Maker v0.70 build 2026-02-20
-
wakillon reacted to a post in a topic:
Low-Polygon Maker v0.70 build 2026-02-20
-
mutleey reacted to a post in a topic:
Low-Polygon Maker v0.70 build 2026-02-20
-
Code updated. Added Cartoon mode for more arty results but very slow calculation.
-
mLipok reacted to a post in a topic:
Follow-up question regarding _WinAPI PrintWindow()
-
Follow-up question regarding _WinAPI PrintWindow()
UEZ replied to mLipok's topic in AutoIt General Help and Support
1) This is not necessary, as it is only relevant for scaling purposes 2) This is a Windows GDI requirement. SelectObject always returns the previously selected object, and you must restore it before deleting the DC. If you don't, you're deleting a DC that still "owns" your bitmap, which can cause resource leaks or undefined behavior. 3) The shadow margins from DWM only apply to top-level windows with a drop shadow (the typical WS_OVERLAPPEDWINDOW style). In these cases: Cropping needed: Standard top-level windows (GUICreate, CreateWindowEx with default styles) — they have DWM shadow margins, so the captured bitmap is slightly larger than the visible content. Cropping not needed / potentially harmful: Borderless windows, child windows, embedded controls (WebView, IE, DebenuViewer), or windows with WS_POPUP and no shadow. Here DWMWA_EXTENDED_FRAME_BOUNDS equals the window rect, so all margins would be 0 anyway — but it's worth checking, since forcing a crop on such windows could cut off actual content. So your observation is correct: questions 1 and 3 are essentially the same issue — both assume scaling or size differences that may not actually exist. -
mLipok reacted to a post in a topic:
Follow-up question regarding _WinAPI PrintWindow()
-
Follow-up question regarding _WinAPI PrintWindow()
UEZ replied to mLipok's topic in AutoIt General Help and Support
Here my suggestion: #include <GUIConstantsEx.au3> #include <GDIPlus.au3> #include <StaticConstants.au3> #include <WinAPIGdi.au3> #include <WindowsConstants.au3> Const $PW_RENDERFULLCONTENT = 2 _Example() Func _Example() ; Launch Calculator and wait for it to finish opening ShellExecuteWait(@SystemDir & "\calc.exe") Local $hWnd = WinWaitActive("[REGEXPCLASS:CalcFrame|ApplicationFrameWindow]", "", 3) If Not $hWnd Then Exit ; Abort if the window didn't appear in time Sleep(500) ; Wait for the window to fully render and skip the open animation ; Create a GUI slightly larger than the Calculator window Local $aSize = WinGetPos($hWnd) Local $hGUI = GUICreate("Test " & StringReplace(@ScriptName, ".au3", "()"), $aSize[2] + 80, $aSize[3] + 80) GUISetBkColor(0x404040, $hGUI) ; Dark gray background Local $idPic = GUICtrlCreatePic("", 48, 48, $aSize[2], $aSize[3]) ; Placeholder for the captured bitmap GUISetState(@SW_SHOW) ; Capture the Calculator window as a GDI bitmap (cropped, client area, GDI-compatible) Local $hGDIBitmap = _WinAPI_CreateBitmapFromPrintWindow($hWnd, True, $PW_RENDERFULLCONTENT, True) ; Assign the bitmap to the picture control, delete any previously set bitmap Local $hHBmp = GUICtrlSendMsg($idPic, $STM_SETIMAGE, $IMAGE_BITMAP, $hGDIBitmap) If $hHBmp Then _WinAPI_DeleteObject($hHBmp) Do Until GUIGetMsg() = $GUI_EVENT_CLOSE ; Cleanup _WinAPI_DeleteObject($hGDIBitmap) WinClose($hWnd, "") GUIDelete($hGUI) EndFunc ;==>_Example ; Captures a window's content using PrintWindow and returns a GDI+ or GDI bitmap. ; $bCrop - Crop the bitmap to the visible frame using DWM (removes window shadow/frame margins) ; $iClientMode - PrintWindow flags passed directly to PrintWindow (1 = PW_CLIENTONLY). PW_RENDERFULLCONTENT (required for UWP/DX windows) ; $bBmpGDI - Return a GDI HBITMAP instead of a GDI+ bitmap handle Func _WinAPI_CreateBitmapFromPrintWindow($hWnd, $bCrop = True, $iClientMode = 1, $bBmpGDI = False) Local $aWinSize = WinGetPos($hWnd) If @error Then Return SetError(1, 0, 0) ; Set up a memory DC with a compatible bitmap to draw into Local Const $hDC_Capture = _WinAPI_GetDC($hWnd) If @error Then Return SetError(2, 0, 0) Local Const $hMemDC = _WinAPI_CreateCompatibleDC($hDC_Capture) Local Const $hHBmp = _WinAPI_CreateCompatibleBitmap($hDC_Capture, $aWinSize[2], $aWinSize[3]) Local Const $hObjectOld = _WinAPI_SelectObject($hMemDC, $hHBmp) ; Use HALFTONE for better quality when stretching/scaling during capture _WinAPI_SetStretchBltMode($hDC_Capture, $HALFTONE) ; Capture the window content using the specified PrintWindow flags _WinAPI_PrintWindow($hWnd, $hMemDC, $iClientMode) ; Restore and release DC resources _WinAPI_SelectObject($hMemDC, $hObjectOld) _WinAPI_DeleteDC($hMemDC) _WinAPI_ReleaseDC($hWnd, $hDC_Capture) ; Skip GDI+ conversion if no cropping is needed and a raw HBITMAP (GDI) was requested If $bCrop = False And $bBmpGDI = True Then Return $hHBmp _GDIPlus_Startup() ; Convert the HBITMAP to a GDI+ bitmap Local $hBitmap = _GDIPlus_BitmapCreateFromHBITMAP($hHBmp) _WinAPI_DeleteObject($hHBmp) ; Optionally crop the bitmap to the visible window area, excluding shadow/frame margins If $bCrop Then Local $iLeft, $iTop, $iRight, $iBottom, $pX, $pY ; Query the actual visible frame bounds via DWM to get the exact shadow margins Local $tRECT = _WinAPI_DwmGetWindowAttribute($hWnd, $DWMWA_EXTENDED_FRAME_BOUNDS) ; Calculate the margin on each side $iLeft = $tRECT.left - $aWinSize[0] $iTop = $tRECT.top - $aWinSize[1] $iRight = $aWinSize[0] + $aWinSize[2] - $tRECT.right $iBottom = $aWinSize[1] + $aWinSize[3] - $tRECT.bottom Local $hBitmap_Cropped = _GDIPlus_BitmapCloneArea($hBitmap, $iLeft, $iTop, $aWinSize[2] - $iLeft - $iRight, $aWinSize[3] - $iTop - $iBottom) _GDIPlus_BitmapDispose($hBitmap) $hBitmap = $hBitmap_Cropped EndIf ; Optionally convert to a GDI HBITMAP (needed for use with STM_SETIMAGE etc.) If $bBmpGDI Then Local $hBitmap_GDI = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hBitmap) _GDIPlus_BitmapDispose($hBitmap) _GDIPlus_Shutdown() Return $hBitmap_GDI EndIf _GDIPlus_Shutdown() Return $hBitmap EndFunc ;==>_WinAPI_CreateBitmapFromPrintWindow _WinAPI_CreateBitmapFromPrintWindow is from here: -
kara2004 reacted to a post in a topic:
Low-Polygon Maker v0.70 build 2026-02-20
-
Parsix reacted to a post in a topic:
Low-Polygon Maker v0.70 build 2026-02-20
-
Danyfirex reacted to a post in a topic:
Low-Polygon Maker v0.70 build 2026-02-20
-
SOLVE-SMART reacted to a post in a topic:
Low-Polygon Maker v0.70 build 2026-02-20
-
I enhanced the Delaunay function in my _GDIPlus_BitmapApplyFilter Dll and created a front-end GUI to generate Low-Polygon images: Code: ;Coded by UEZ v0.70build 2026-02-20 ;Requires 3.3.15.0+ version #AutoIt3Wrapper_Version=p #AutoIt3Wrapper_UseX64=y #AutoIt3Wrapper_Res_HiDpi=y #include <Array.au3> #include <ButtonConstants.au3> #include <ComboConstants.au3> #include <EditConstants.au3> #include <GDIPlus.au3> #include <GUIConstantsEx.au3> #include <GuiStatusBar.au3> #include <ScreenCapture.au3> #include <StaticConstants.au3> #include <WinAPIGdi.au3> #include <WinAPISysWin.au3> #include <WindowsConstants.au3> #include "_GDIPlus_BitmapApplyFilter.au3" Global Const $hDLL = _GDIPlus_BitmapApplyFilter_Open() Global Const $sVer = _GDIPlus_BitmapApplyFilter_Ver2() Global $tokenVer = StringRegExpReplace($sVer, "v(.+?)\h+.+", "$1") Global $tokenBuild = StringRegExpReplace($sVer, ".+build\h+(.+?)\hbeta", "$1") If Not CheckVer($tokenVer, "1.0.0") Or $tokenBuild < "2026-02-19" Then MsgBox(16, "Error", "Requires at least DLL v1.0.0 build 2026-02-19." & @CRLF & "Found: " & $sVer) Exit EndIf Global Const $hGUI = GUICreate("Low-Polygon Maker v0.70", 252, 874, 4, 10, -1, BitOR($WS_EX_ACCEPTFILES, $WS_EX_TOPMOST)) GUISetFont(8, 400, 0, "Consolas") GUISetBkColor(0xABCDEF, $hGUI) Global $iInp_x = 96, $iInp_w = 100, $y = 60, $y2 = 92, $p Global Const $iLbl_Title = GUICtrlCreateLabel("Low-Polygon Maker", 0, 8, 238, 32, $SS_CENTER) GUICtrlSetFont(-1, 18, 400, 0, "Consolas") Global Const $iLbl_EdgeDetection = GUICtrlCreateLabel("Edge Detection", 4, $y, 88, 17) GUICtrlSetFont(-1, 8.5, 400, 0, "Consolas") Global Const $iCombo_EdgeDetection = GUICtrlCreateCombo("", 96, $y - 4, 145, 25, BitOR($CBS_DROPDOWNLIST, $CBS_AUTOHSCROLL)) GUICtrlSetFont(-1, 10, 400, 0, "Consolas") GUICtrlSetData($iCombo_EdgeDetection, "SOBEL|" & _ "SCHARR|" & _ "PREWITT|" & _ "SOVELVSPREWITT|" & _ "FREI_CHEN|" & _ "ROBINSON_COMPASS|" & _ "KAYYALI|" & _ "ROBERTS_CROSS|" & _ "RIDGE_DETECTION|" & _ "DIAGONAL_EDGES|" & _ "OUTLINE3X3|" & _ "LAPLACE3x3_1|" & _ "LAPLACE3x3_2|" & _ "LAPLACE5x5|" & _ "EDGE_DETECTION1|" & _ "EDGE_DETECTION2|" & _ "EDGE_DETECTION3|" & _ "EDGE_DETECTION4|" & _ "EDGE_DETECTION5|" & _ "EDGE_DETECTION6|" & _ "EMBOSS1|" & _ "EMBOSS2|" & _ "EMBOSS3|" & _ "EMBOSS4|" & _ "KIRSCH|" & _ "ISOTROPIC_SOBEL", _ "ROBERTS_CROSS") $y += 36 Global $aRet = _GDIPlus_BitmapCreateVerticalText("Coded by UEZ 2026", 21.75, "Consolas", 0x380000FF, 0x28000000, 2, 1) Global Const $iPic_Label = GUICtrlCreatePic("", 204, $y - 4, $aRet[1], $aRet[2]) _WinAPI_DeleteObject(GUICtrlSendMsg($iPic_Label, $STM_SETIMAGE, $IMAGE_BITMAP, $aRet[0])) Global Const $iLbl_Threshold = GUICtrlCreateLabel("ED Threshold", 4, $y, 76, 17) GUICtrlSetFont(-1, 8.5, 400, 0, "Consolas") Global Const $iInp_Threshold = GUICtrlCreateInput(1.2, $iInp_x, $y2, $iInp_w, 21) GUICtrlSetFont(-1, 10, 400, 0, "Consolas") GUICtrlSetTip(-1, "The lower the value, the larger the triangles.") Global Const $iLbl_Blur = GUICtrlCreateLabel("Blur Level", 4, $y + 1 * 32, 64, 17) GUICtrlSetFont(-1, 8.5, 400, 0, "Consolas") Global Const $iInp_Blur = GUICtrlCreateInput(1, $iInp_x, $y2 + 1 * 32, $iInp_w, 21, BitOR($GUI_SS_DEFAULT_INPUT, $ES_NUMBER)) GUICtrlSetFont(-1, 10, 400, 0, "Consolas") Global Const $iLbl_Colors = GUICtrlCreateLabel("Max. Colors", 4, $y + 2 * 32, 70, 17) GUICtrlSetFont(-1, 8.5, 400, 0, "Consolas") Global Const $iInp_Colors = GUICtrlCreateInput(256, $iInp_x, $y2 + 2 * 32, $iInp_w, 21, BitOR($GUI_SS_DEFAULT_INPUT, $ES_NUMBER)) GUICtrlSetFont(-1, 10, 400, 0, "Consolas") GUICtrlSetTip(-1, "Valid values are: 2, 16, 256") Global Const $iLbl_MinSpace = GUICtrlCreateLabel("Min Space", 4, $y + 3 * 32, 58, 17) GUICtrlSetFont(-1, 8.5, 400, 0, "Consolas") Global Const $iInp_MinSpace = GUICtrlCreateInput(8, $iInp_x, $y2 + 3 * 32, $iInp_w, 21, BitOR($GUI_SS_DEFAULT_INPUT, $ES_NUMBER)) GUICtrlSetFont(-1, 10, 400, 0, "Consolas") Global Const $iLbl_MaxSpace = GUICtrlCreateLabel("Max Space", 4, $y + 4 * 32, 58, 17) GUICtrlSetFont(-1, 8.5, 400, 0, "Consolas") Global Const $iInp_MaxSpace = GUICtrlCreateInput(45, $iInp_x, $y2 + 4 * 32, $iInp_w, 21, BitOR($GUI_SS_DEFAULT_INPUT, $ES_NUMBER)) GUICtrlSetFont(-1, 10, 400, 0, "Consolas") Global Const $iLbl_BorderSpaceX = GUICtrlCreateLabel("Border Space X", 4, $y + 5 * 32, 88, 17) GUICtrlSetFont(-1, 8.5, 400, 0, "Consolas") Global Const $iInp_BorderSpaceX = GUICtrlCreateInput(8, $iInp_x, $y2 + 5 * 32, $iInp_w, 21, BitOR($GUI_SS_DEFAULT_INPUT, $ES_NUMBER)) GUICtrlSetFont(-1, 10, 400, 0, "Consolas") Global Const $iLbl_BorderSpaceY = GUICtrlCreateLabel("Border Space Y", 4, $y + 6 * 32, 88, 17) GUICtrlSetFont(-1, 8.5, 400, 0, "Consolas") Global Const $iInp_BorderSpaceY = GUICtrlCreateInput(8, $iInp_x, $y2 + 6 * 32, $iInp_w, 21, BitOR($GUI_SS_DEFAULT_INPUT, $ES_NUMBER)) GUICtrlSetFont(-1, 10, 400, 0, "Consolas") Global Const $iLbl_Alpha = GUICtrlCreateLabel("Edges Alpha", 4, $y + 7 * 32, 70, 17) GUICtrlSetFont(-1, 8.5, 400, 0, "Consolas") Global Const $iInp_Alpha = GUICtrlCreateInput(24, $iInp_x, $y2 + 7 * 32, $iInp_w, 21, BitOR($GUI_SS_DEFAULT_INPUT, $ES_NUMBER)) GUICtrlSetFont(-1, 10, 400, 0, "Consolas") Global Const $iLbl_PosterizeLvl = GUICtrlCreateLabel("Posterize Lvl", 4, $y + 8 * 32, 85, 17) GUICtrlSetFont(-1, 8.5, 400, 0, "Consolas") Global Const $iInp_PosterizeLvl = GUICtrlCreateInput(10, $iInp_x, $y2 + 8 * 32, $iInp_w, 21, BitOR($GUI_SS_DEFAULT_INPUT, $ES_NUMBER)) GUICtrlSetFont(-1, 10, 400, 0, "Consolas") GUICtrlSetTip(-1, "When the posterization level is set, the value for 'Max. Colors' input is ignored.") Global Const $iLbl_Denoise = GUICtrlCreateLabel("Denoise Lvl", 4, $y + 9 * 32, 85, 17) GUICtrlSetFont(-1, 8.5, 400, 0, "Consolas") Global Const $iInp_DenoiseLvl = GUICtrlCreateInput(1, $iInp_x, $y2 + 9 * 32, $iInp_w, 21, BitOR($GUI_SS_DEFAULT_INPUT, $ES_NUMBER)) GUICtrlSetFont(-1, 10, 400, 0, "Consolas") GUICtrlSetTip(-1, "The higher the value, the slower the operation.") Global Const $iLbl_EdgePoints = GUICtrlCreateLabel("Edge Points", 4, $y + 10 * 32, 85, 17) GUICtrlSetFont(-1, 8.5, 400, 0, "Consolas") Global Const $iInp_EdgePoints = GUICtrlCreateInput(16, $iInp_x, $y2 + 10 * 32, $iInp_w, 21, BitOR($GUI_SS_DEFAULT_INPUT, $ES_NUMBER)) GUICtrlSetFont(-1, 10, 400, 0, "Consolas") GUICtrlSetTip(-1, "The lower the value, the more triangles.") Global Const $iLbl_CartoonRadius = GUICtrlCreateLabel("Cartoon Radius", 4, $y + 11 * 32, 85, 17) GUICtrlSetFont(-1, 8.5, 400, 0, "Consolas") Global Const $iInp_CartoonRadius = GUICtrlCreateInput(7, $iInp_x, $y2 + 11 * 32, $iInp_w, 21, BitOR($GUI_SS_DEFAULT_INPUT, $ES_NUMBER)) GUICtrlSetFont(-1, 10, 400, 0, "Consolas") GUICtrlSetTip(-1, "The higher the value, the slower the operation.") Global Const $iLbl_CartoonIntens = GUICtrlCreateLabel("Cartoon Intens", 4, $y + 12 * 32, 85, 17) GUICtrlSetFont(-1, 8.5, 400, 0, "Consolas") Global Const $iInp_CartoonIntens = GUICtrlCreateInput(150.00, $iInp_x, $y2 + 12 * 32, $iInp_w, 21) GUICtrlSetFont(-1, 10, 400, 0, "Consolas") $y2 += 102 $p = 10 Global Const $iChkB_ShowEdges = GUICtrlCreateCheckbox("Show Edges", 4, $y2 + $p * 32, 233, 17) GUICtrlSetFont(-1, 8.5, 400, 0, "Consolas") GUICtrlSetState(-1, $GUI_CHECKED) $p += 1 Global Const $iChkB_Wireframe = GUICtrlCreateCheckbox("Show Wireframes only", 4, $y2 + $p * 32, 233, 17) GUICtrlSetFont(-1, 8.5, 400, 0, "Consolas") $p += 1 Global Const $iChkB_GIFAnim = GUICtrlCreateCheckbox("Convert all GIF frames", 4, $y2 + $p * 32, 233, 17) GUICtrlSetFont(-1, 8.5, 400, 0, "Consolas") $p += 1 Global Const $iChkB_CartoonMode = GUICtrlCreateCheckbox("Enable Cartoon Mode", 4, $y2 + $p * 32, 233, 17) GUICtrlSetFont(-1, 8.5, 400, 0, "Consolas") GUICtrlSetState(-1, $GUI_CHECKED) GUICtrlSetTip(-1, "Very CPU intensive calculation.") $p += 1 $y2 += $p * 32 $p = 0 Global Const $iBtn_Apply = GUICtrlCreateButton("&Apply", 8, $y2 + $p * 72, 235, 57, $BS_DEFPUSHBUTTON) GUICtrlSetFont(-1, 12, 400, 0, "Consolas") GUICtrlSetBkColor(-1, 0xCCCCFF) GUICtrlSetState($iBtn_Apply, $GUI_DISABLE) $p += 1 Global Const $iBtn_Load = GUICtrlCreateButton("&Load Image", 8, $y2 + $p * 72, 235, 57) GUICtrlSetFont(-1, 12, 400, 0, "Consolas") GUICtrlSetBkColor(-1, 0xCCCCFF) $p += 1 Global Const $iBtn_Save = GUICtrlCreateButton("&Save Image", 8, $y2 + $p * 72, 235, 57) GUICtrlSetFont(-1, 12, 400, 0, "Consolas") GUICtrlSetBkColor(-1, 0xCCCCFF) GUICtrlSetState($iBtn_Save, $GUI_DISABLE) Global $aParts[1] = [-1] Global Const $hStatusBar = _GUICtrlStatusBar_Create($hGUI, $aParts, "Ready") Local $hFont = _WinAPI_CreateFont(12, 0, 0, 0, $FW_MEDIUM, False, False, False, $DEFAULT_CHARSET, $OUT_DEFAULT_PRECIS, $CLIP_DEFAULT_PRECIS, $DRAFT_QUALITY, 0, "Segoe UI") _WinAPI_SetFont($hStatusBar, $hFont, True) GUISetState(@SW_SHOW) Global $aAccelKeys[4][2] = [["^s", $iBtn_Save], ["^l", $iBtn_Load], ["^a", $iBtn_Apply], ["{ENTER}", $iBtn_Apply]] GUISetAccelerators($aAccelKeys) GUIRegisterMsg($WM_COMMAND, "_WM_COMMAND") GUIRegisterMsg($WM_DROPFILES, "_WM_DROPFILES") Global $aMsg, $hImage, $sImgFile, $hGUI_Display = 0, $hGDI_LowPoly, $sFileLowPoly ConsoleWrite("Screen: " & @DesktopWidth & "x" & @DesktopHeight & @CRLF) Dim $aFrameDelays[1], $aFramesGDI[1], $aFrames_LowPoly[1] Global $iCurrentFrame = 0, $iAnimFrameCount = 0, $bIsGIF, $iPic_LowPoly, $iSeed, $i, $r, $hImage_OrginalSize, $iDummy_Load = GUICtrlCreateDummy() While 1 $aMsg = GUIGetMsg(1) Switch $aMsg[1] Case $hGUI Switch $aMsg[0] Case $GUI_EVENT_CLOSE GUIRegisterMsg($WM_COMMAND, "") GUIRegisterMsg($WM_DROPFILES, "") AdlibUnRegister("PlayGIFAnimPreview") If $hGDI_LowPoly Then $r = MsgBox(BitOR($MB_ICONQUESTION, $MB_YESNO), "Question", "Save image before closing?", 5) If $r = $IDYES Then SaveImage() EndIf GUIDelete($hGUI) If UBound($aFrameDelays) > 1 Then For $i = 0 To UBound($aFramesGDI) - 1 _WinAPI_DeleteObject($aFramesGDI[$i]) Next For $i = 1 To $aFrames_LowPoly[0] _GDIPlus_ImageDispose($aFrames_LowPoly[$i]) Next EndIf If $hImage_OrginalSize Then _GDIPlus_ImageDispose($hImage_OrginalSize) _GDIPlus_BitmapApplyFilter_Close() Exit Case $iBtn_Load $sImgFile = FileOpenDialog("Select a GDI+ supported image", "", "Images (*.bmp;*.gif;*.png;*.jpg;*.tif)", $FD_FILEMUSTEXIST, "", $hGUI) If @error Then ContinueLoop If Not FileExists($sImgFile) Then MsgBox($MB_ICONERROR, "Error", $sImgFile & " doesn't exist", 30) ContinueLoop EndIf LoadImage($sImgFile) Case $iBtn_Save If $sImgFile = "" Or ($bIsGIF ? UBound($aFrames_LowPoly) < 2 : $hGDI_LowPoly = 0) Then ContinueLoop SaveImage() Case $iBtn_Apply If $sImgFile = "" Or $hImage = 0 Then ContinueLoop GUICtrlSetState($iBtn_Apply, $GUI_DISABLE) GUICtrlSetState($iBtn_Load, $GUI_DISABLE) GUICtrlSetState($iBtn_Save, $GUI_DISABLE) $iCurrentFrame = 0 EncodeAndDisplay($hImage) GUICtrlSetState($iBtn_Apply, $GUI_ENABLE) GUICtrlSetState($iBtn_Load, $GUI_ENABLE) GUICtrlSetState($iBtn_Save, $GUI_ENABLE) Case $iDummy_Load LoadImage($sImgFile) EndSwitch Case $hGUI_Display Switch $aMsg[0] Case $GUI_EVENT_CLOSE AdlibUnRegister("PlayGIFAnimPreview") GUIDelete($hGUI_Display) $hGUI_Display = 0 EndSwitch EndSwitch WEnd Func Min($a, $b) Return $a < $b ? $a : $b EndFunc ;==>Min Func Max($a, $b) Return $a > $b ? $a : $b EndFunc ;==>Max Func EncodeAndDisplay($hImage, $ResizeinGUI = True) Local $iW = _GDIPlus_ImageGetWidth($hImage), $iH = _GDIPlus_ImageGetHeight($hImage) If $iW = 0 Or $iH = 0 Then Return SetError(1, 0, 0) Local $iMode = 0, $fScaleX, $fScaleY, $fFactor = 0.925 ConsoleWrite("Original: " & $iW & "x" & $iH & @CRLF) If $ResizeinGUI Then If $iH > @DesktopHeight And $iW < @DesktopWidth + 1 Then $fScaleY = @DesktopHeight / $iH $iW *= $fScaleY $iH *= $fScaleY $iMode = 1 ElseIf $iH < @DesktopHeight + 1 And $iW > @DesktopWidth Then $fScaleX = @DesktopWidth / $iW $iW *= $fScaleX $iH *= $fScaleX $iMode = 2 ElseIf $iH > @DesktopHeight And $iW > @DesktopWidth Then If $iH > $iW Then $fScaleY = @DesktopHeight / $iH $iH *= $fScaleY $iW *= $fScaleY Else $fScaleX = @DesktopWidth / $iW $iH *= $fScaleX $iW *= $fScaleX EndIf $iMode = 3 EndIf If $iMode Then $iW *= $fFactor $iH *= $fFactor EndIf EndIf ConsoleWrite("Display: " & Int($iW) & "x" & Int($iH) & @CRLF) Static $iWp = 0, $iHp = 0 If ($iW <> $iWp Or $iH <> $iHp) Or $hGUI_Display = 0 Then If $hGUI_Display Then GUIDelete($hGUI_Display) $hGUI_Display = GUICreate("", $iW, $iH, -1, -1, $WS_POPUP, $WS_EX_OVERLAPPEDWINDOW) $iPic_LowPoly = GUICtrlCreatePic("", 0, 0, $iW - 1, $iH - 1, -1, $GUI_WS_EX_PARENTDRAG) GUISetState(@SW_SHOWNORMAL, $hGUI_Display) WinActivate($hGUI) EndIf $iWp = $iW $iHp = $iH If $hGDI_LowPoly Then _WinAPI_DeleteObject($hGDI_LowPoly) $hGDI_LowPoly = 0 ;~ ConsoleWrite("Blur level: " & Number(GUICtrlRead($iInp_Blur)) & @CRLF & _ ;~ "Kernel: " & Execute("$" & GUICtrlRead($iCombo_EdgeDetection)) & @CRLF & _ ;~ "Threshold: " & Number(GUICtrlRead($iInp_Threshold), $NUMBER_DOUBLE) & @CRLF & _ ;~ "Amount of Colors: " & Number(GUICtrlRead($iInp_Colors)) & @CRLF & _ ;~ "Min Space: " & Number(GUICtrlRead($iInp_MinSpace)) & @CRLF & _ ;~ "Max Space: " & Number(GUICtrlRead($iInp_MaxSpace)) & @CRLF & _ ;~ "Border Space X: " & Number(GUICtrlRead($iInp_BorderSpaceX)) & @CRLF & _ ;~ "Border Space Y: " & Number(GUICtrlRead($iInp_BorderSpaceY)) & @CRLF & _ ;~ "Show Edges Checked: " & Int(BitAND(GUICtrlRead($iChkB_ShowEdges), $GUI_CHECKED) = $GUI_CHECKED) & @CRLF & _ ;~ "Alpha Value: " & Number(GUICtrlRead($iInp_Alpha)) & @CRLF & _ ;~ "Wireframe Checked: " & Int(BitAND(GUICtrlRead($iChkB_Wireframe), $GUI_CHECKED) = $GUI_CHECKED) & @CRLF & _ ;~ "Posterize level: " & Number(GUICtrlRead($iInp_PosterizeLvl)) & @CRLF & _ ;~ "GIF Mode Checked: " & Int(BitAND(GUICtrlRead($iChkB_GIFAnim), $GUI_CHECKED) = $GUI_CHECKED) & @CRLF & _ ;~ "Posterize Lvl: " & Number(GUICtrlRead($iInp_PosterizeLvl)) & @CRLF & _ ;~ "Denoise Lvl: " & Number(GUICtrlRead($iInp_DenoiseLvl)) & @CRLF & _ ;~ "EdgePoints): " & Number(GUICtrlRead($iInp_EdgePoints)) & @CRLF & _ ;~ "CornerPoints: " & Number(GUICtrlRead($iInp_CornerPoints)) & @CRLF) ;~ ConsoleWrite("-----------------------------------------------------------------------" & @CRLF) AdlibUnRegister("PlayGIFAnimPreview") Local $i Local $iAnimDimCount = _GDIPlus_GIFAnimGetFrameDimensionsCount($hImage) Local $tGUID = _GDIPlus_GIFAnimGetFrameDimensionsList($hImage, $iAnimDimCount) $iAnimFrameCount = _GDIPlus_GIFAnimGetFrameCount($hImage, $tGUID) $aFrameDelays = _GDIPlus_GIFAnimGetFrameDelays($hImage, $iAnimFrameCount) If $iAnimFrameCount Then _GDIPlus_GIFAnimSelectActiveFrame($hImage, $tGUID, 0) _GUICtrlStatusBar_SetText($hStatusBar, "Calculation has started. Please wait...", 0, $SBT_POPOUT) Local Const $fTimer = TimerInit() If Int(BitAND(GUICtrlRead($iChkB_GIFAnim), $GUI_CHECKED) = $GUI_CHECKED) And $bIsGIF And $iAnimFrameCount > 1 Then If UBound($aFramesGDI) > 1 Then For $i = 0 To UBound($aFramesGDI) - 1 _WinAPI_DeleteObject($aFramesGDI[$i]) _GDIPlus_ImageDispose($aFrames_LowPoly[$i + 1]) Next EndIf ReDim $aFramesGDI[$iAnimFrameCount] ReDim $aFrames_LowPoly[$iAnimFrameCount + 1] $aFrames_LowPoly[0] = $iAnimFrameCount For $i = 0 To $iAnimFrameCount - 1 _GDIPlus_GIFAnimSelectActiveFrame($hImage, $tGUID, $i) $aFrames_LowPoly[$i + 1] = _GDIPlus_BitmapApplyFilter_Delaunay3($hImage, _ Number(GUICtrlRead($iInp_Blur)), _ Execute("$" & GUICtrlRead($iCombo_EdgeDetection)), _ Number(GUICtrlRead($iInp_Threshold), $NUMBER_DOUBLE), _ Number(GUICtrlRead($iInp_Colors)), _ Number(GUICtrlRead($iInp_MinSpace)), _ Number(GUICtrlRead($iInp_MaxSpace)), _ Number(GUICtrlRead($iInp_BorderSpaceX)), _ Number(GUICtrlRead($iInp_BorderSpaceY)), _ Int(BitAND(GUICtrlRead($iChkB_ShowEdges), $GUI_CHECKED) = $GUI_CHECKED), _ Number(GUICtrlRead($iInp_Alpha)), _ Int(BitAND(GUICtrlRead($iChkB_Wireframe), $GUI_CHECKED) = $GUI_CHECKED), _ Number(GUICtrlRead($iInp_PosterizeLvl)), _ $iSeed, _ 0xFFFFFFFF, _ Number(GUICtrlRead($iInp_DenoiseLvl)), _ Number(GUICtrlRead($iInp_EdgePoints)), _ 50, _ Int(BitAND(GUICtrlRead($iChkB_CartoonMode), $GUI_CHECKED) = $GUI_CHECKED), _ Number(GUICtrlRead($iInp_CartoonRadius)), _ Number(GUICtrlRead($iInp_CartoonIntens), $NUMBER_DOUBLE), _ False) $aFramesGDI[$i] = _GDIPlus_BitmapCreateHBITMAPFromBitmap($aFrames_LowPoly[$i + 1]) _GDIPlus_BitmapConvertTo8Bit($aFrames_LowPoly[$i + 1], 256, $GDIP_DitherTypeNone, $GDIP_PaletteTypeFixedHalftone256) ToolTip($i + 1 & "/" & $iAnimFrameCount & " : " & Round(($i + 1) / UBound($aFrameDelays) * 100, 2) & "%", MouseGetPos(0), MouseGetPos(1) + 30, "", 0, $TIP_CENTER) Next ToolTip("") AdlibRegister("PlayGIFAnimPreview", 10) Else $hGDI_LowPoly = _GDIPlus_BitmapApplyFilter_Delaunay3($hImage, _ Number(GUICtrlRead($iInp_Blur)), _ Execute("$" & GUICtrlRead($iCombo_EdgeDetection)), _ Number(GUICtrlRead($iInp_Threshold), $NUMBER_DOUBLE), _ Number(GUICtrlRead($iInp_Colors)), _ Number(GUICtrlRead($iInp_MinSpace)), _ Number(GUICtrlRead($iInp_MaxSpace)), _ Number(GUICtrlRead($iInp_BorderSpaceX)), _ Number(GUICtrlRead($iInp_BorderSpaceY)), _ Int(BitAND(GUICtrlRead($iChkB_ShowEdges), $GUI_CHECKED) = $GUI_CHECKED), _ Number(GUICtrlRead($iInp_Alpha)), _ Int(BitAND(GUICtrlRead($iChkB_Wireframe), $GUI_CHECKED) = $GUI_CHECKED), _ Number(GUICtrlRead($iInp_PosterizeLvl)), _ $iSeed, _ 0, _ Number(GUICtrlRead($iInp_DenoiseLvl)), _ Number(GUICtrlRead($iInp_EdgePoints)), _ 50, _ Int(BitAND(GUICtrlRead($iChkB_CartoonMode), $GUI_CHECKED) = $GUI_CHECKED), _ Number(GUICtrlRead($iInp_CartoonRadius)), _ Number(GUICtrlRead($iInp_CartoonIntens), $NUMBER_DOUBLE), _ True) If $hGDI_LowPoly = 0 Then GUIDelete($hGUI_Display) $hGUI_Display = 0 Return SetError(1, 0, 0) EndIf If $iMode Then ResizeImage($hGDI_LowPoly, $iW, $iH) Local $hHBmp = GUICtrlSendMsg($iPic_LowPoly, $STM_SETIMAGE, $IMAGE_BITMAP, $hGDI_LowPoly) If $hHBmp Then _WinAPI_DeleteObject($hHBmp) EndIf _GUICtrlStatusBar_SetText($hStatusBar, "Generated in: " & Round(TimerDiff($fTimer), 2) & " ms. Dimension: " & _GDIPlus_ImageGetWidth($hImage) & "x" & _GDIPlus_ImageGetHeight($hImage), 0, $SBT_POPOUT) _WinAPI_InvalidateRect($hGUI_Display) _WinAPI_RedrawWindow($hGUI_Display) EndFunc ;==>EncodeAndDisplay Func PlayGIFAnimPreview() AdlibUnRegister("PlayGIFAnimPreview") Local $iDelay = $aFrameDelays[$iCurrentFrame] Local Static $iTimerCurrentFrame = TimerInit() _WinAPI_DeleteObject(GUICtrlSendMsg($iPic_LowPoly, 0x0172, 0, $aFramesGDI[$iCurrentFrame])) ;$STM_SETIMAGE = 0x0172, $IMAGE_BITMAP = 0 If TimerDiff($iTimerCurrentFrame) > $iDelay Then $iCurrentFrame += 1 $iTimerCurrentFrame = TimerInit() EndIf If $iCurrentFrame > UBound($aFrameDelays) - 1 Then $iCurrentFrame = 0 AdlibRegister("PlayGIFAnimPreview", 10) EndFunc ;==>PlayGIFAnimPreview Func ResizeImage(ByRef $hBitmapGDI, $newW, $newH) Local $hImage = _GDIPlus_BitmapCreateFromHBITMAP($hBitmapGDI) If $hImage_OrginalSize Then _GDIPlus_ImageDispose($hImage_OrginalSize) $hImage_OrginalSize = _GDIPlus_ImageClone($hImage) Local $hImageResized = _GDIPlus_ImageResize($hImage, $newW, $newH) _WinAPI_DeleteObject($hBitmapGDI) $hBitmapGDI = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hImageResized, 0) _GDIPlus_ImageDispose($hImageResized) EndFunc ;==>ResizeImage Func _WM_COMMAND($hWnd, $Msg, $wParam, $lParam) Local $iNotifyCode = BitShift($wParam, 16) Local $iCtrlID = BitAND($wParam, 0x0000FFFF) Local $var If $iNotifyCode = $EN_KILLFOCUS Then Switch $iCtrlID Case $iInp_Blur $val = GUICtrlRead($iInp_Blur) If $val = "" Then $val = 5 $val = Number($val) If $val < 0 Then $val = 0 If $val > 127 Then $val = 127 GUICtrlSetData($iInp_Blur, $val) Case $iInp_Threshold $val = GUICtrlRead($iInp_Threshold) If $val = "" Then $val = 0.35 $val = Number($val) If $val < 0 Then $val = 0 If $val > 10 Then $val = 10 GUICtrlSetData($iInp_Threshold, StringFormat("%.2f", $val)) Case $iInp_Colors $val = GUICtrlRead($iInp_Colors) If $val = "" Then $val = 32 $val = Number($val) If $val < 2 Then $val = 2 If $val > 255 Then $val = 255 GUICtrlSetData($iInp_Colors, $val) Case $iInp_MinSpace $val = GUICtrlRead($iInp_MinSpace) If $val = "" Then $val = 1 $val = Number($val) If $val < 1 Then $val = 1 GUICtrlSetData($iInp_MinSpace, $val) Case $iInp_MaxSpace $val = GUICtrlRead($iInp_MaxSpace) If $val = "" Then $val = 8 $val = Number($val) If $val < 1 Then $val = 2 GUICtrlSetData($iInp_MaxSpace, $val) Case $iInp_BorderSpaceX, $iInp_BorderSpaceY $val = GUICtrlRead($iCtrlID) If $val = "" Then $val = 2 $val = Number($val) If $val < 1 Then $val = 1 If $val > 4096 Then $val = 4096 GUICtrlSetData($iCtrlID, $val) Case $iInp_Alpha $val = GUICtrlRead($iInp_Alpha) If $val = "" Then $val = 32 $val = Number($val) If $val < 0 Then $val = 0 If $val > 255 Then $val = 255 GUICtrlSetData($iInp_Alpha, $val) Case $iInp_PosterizeLvl $val = GUICtrlRead($iInp_PosterizeLvl) If $val = "" Then $val = 8 $val = Number($val) If $val < 0 Then $val = 0 If $val > 255 Then $val = 255 GUICtrlSetData($iInp_PosterizeLvl, $val) Case $iInp_DenoiseLvl $val = GUICtrlRead($iInp_DenoiseLvl) If $val = "" Then $val = 0 $val = Number($val) If $val < 0 Then $val = 0 If $val > 255 Then $val = 255 GUICtrlSetData($iInp_DenoiseLvl, $val) Case $iInp_EdgePoints $val = GUICtrlRead($iInp_EdgePoints) If $val = "" Then $val = 30 $val = Number($val) If $val < 0 Then $val = 0 If $val > 255 Then $val = 255 GUICtrlSetData($iInp_EdgePoints, $val) Case $iInp_CartoonRadius $val = GUICtrlRead($iInp_CartoonRadius) If $val = "" Then $val = 8 $val = Number($val) If $val < 0 Then $val = 0 If $val > 255 Then $val = 255 GUICtrlSetData($iInp_CartoonRadius, $val) Case $iInp_CartoonIntens $val = GUICtrlRead($iInp_CartoonIntens) If $val = "" Then $val = 20 $val = Number($val) If $val < 0 Then $val = 0 If $val > 255 Then $val = 255 GUICtrlSetData($iInp_CartoonIntens, StringFormat("%.2f", $val)) EndSwitch EndIf Return $GUI_RUNDEFMSG EndFunc ;==>_WM_COMMAND Func _WM_DROPFILES($hWnd, $iMsg, $wParam, $lParam) Local $i = 1 Local $aFileList = _WinAPI_DragQueryFileEx($wParam) Do If StringInStr(FileGetAttrib($aFileList[$i]), "D") Then _ArrayDelete($aFileList, $i) Else $i += 1 EndIf Until $i = UBound($aFileList) $aFileList[0] = UBound($aFileList) - 1 $sImgFile = $aFileList[1] _WinAPI_DragFinish($wParam) GUICtrlSendToDummy($iDummy_Load) Return 0 EndFunc ;==>WM_DROPFILES# Func LoadImage($sImgFile) If $hImage Then _GDIPlus_ImageDispose($hImage) $hImage = _GDIPlus_ImageLoadFromFile($sImgFile) If Not $hImage Then MsgBox($MB_ICONERROR, "Error", "Unable to load file to GDI+", 30) Return 0 EndIf $bIsGIF = False If StringRight($sImgFile, 4) = ".gif" Then $bIsGIF = True $iSeed = Int(Random() * 0xFFFFFF) $iCurrentFrame = 0 $iAnimFrameCount = 0 Local $iMax = Int(Max(_GDIPlus_ImageGetWidth($hImage), _GDIPlus_ImageGetHeight($hImage)) / 192) If $iMax > 1 Then GUICtrlSetData($iInp_MinSpace, $iMax) GUICtrlSetData($iInp_MaxSpace, Ceiling($iMax * 4.5)) EndIf If $hImage Then GUICtrlSetState($iBtn_Apply, $GUI_ENABLE) GUICtrlSetState($iBtn_Save, $GUI_ENABLE) EndIf GUICtrlSetData($iInp_BorderSpaceX, Int(_GDIPlus_ImageGetWidth($hImage) / 16)) GUICtrlSetData($iInp_BorderSpaceY, Int(_GDIPlus_ImageGetHeight($hImage) / 16)) EncodeAndDisplay($hImage) EndFunc Func SaveImage() $sFileLowPoly = FileSaveDialog("Save Low-Polygone Image", "", "Images (*.bmp;*.gif;*.png;*.jp?g;*.tif?)", 0, StringRegExpReplace($sImgFile, "^.*\\([^\\]+)(\.[^.]+)$", "\1_Low-Polygon\2"), $hGUI) If @error Or $sFileLowPoly = "" Then Return 0 If FileExists($sFileLowPoly) Then Local $r = MsgBox(BitOR($MB_ICONQUESTION, $MB_YESNO), "Question", "File already exists - overwwrite?", 5) If $r <> $IDYES Then Return MsgBox($MB_ICONINFORMATION, "Information", "Save aborted!", 15, $hGUI) EndIf EndIf If ((UBound($aFrames_LowPoly) > 1 And $bIsGIF) ? _ _GDIPlus_GIFAnimCreateFile2($aFrames_LowPoly, $sFileLowPoly, $aFrameDelays) _ : _ ($hImage_OrginalSize ? _GDIPlus_ImageSaveToFile($hImage_OrginalSize,$sFileLowPoly) _ : _ScreenCapture_SaveImage($sFileLowPoly, $hGDI_LowPoly, False))) Then MsgBox($MB_ICONINFORMATION, "Information", "Low-Poly image saved.", 15, $hGUI) Else MsgBox($MB_ICONERROR, "Error", "Low-Poly image could not be save!", 15, $hGUI) EndIf EndFunc ;==>SaveImage Func _GDIPlus_BitmapCreateVerticalText($sString, $fFontSize = 10, $sFont = "Arial", $iColor_Text = 0xFF000000, $iTxtBorderColor = 0x80808080, $iTxtBorderSize = 1, $iFlip = 3) $iFlip = ($iFlip <> 3 And $iFlip <> 1) ? 3 : $iFlip Local Const $hDC = _WinAPI_GetWindowDC(0) Local Const $hGraphic = _GDIPlus_GraphicsCreateFromHDC($hDC) Local Const $hBrush = _GDIPlus_BrushCreateSolid($iColor_Text), $hPen = _GDIPlus_PenCreate($iTxtBorderColor, $iTxtBorderSize) Local Const $hFormat = _GDIPlus_StringFormatCreate() Local Const $hFamily = _GDIPlus_FontFamilyCreate($sFont) Local Const $hFont = _GDIPlus_FontCreate($hFamily, $fFontSize) Local Const $hPath = _GDIPlus_PathCreate() Local $tLayout = _GDIPlus_RectFCreate() Local $iError = 1 Local Const $aInfo = _GDIPlus_GraphicsMeasureString($hGraphic, $sString, $hFont, $tLayout, $hFormat) If Not @error Then Local Const $iW = Ceiling($aInfo[0].Width), $iH = Ceiling($aInfo[0].Height) Local Const $hBitmap = _GDIPlus_BitmapCreateFromScan0($iW, $iH), $hCanvas = _GDIPlus_ImageGetGraphicsContext($hBitmap) _GDIPlus_GraphicsSetSmoothingMode($hCanvas, $GDIP_SMOOTHINGMODE_HIGHQUALITY) _GDIPlus_GraphicsSetTextRenderingHint($hCanvas, $GDIP_TEXTRENDERINGHINTANTIALIASGRIDFIT) $tLayout.X = 0 $tLayout.Y = 0 $tLayout.Width = $iW $tLayout.Height = $iH _GDIPlus_PathAddString($hPath, $sString, $tLayout, $hFamily, 0, $fFontSize, $hFormat) ;~ _GDIPlus_GraphicsDrawStringEx($hCanvas, $sString, $hFont, $tLayout, $hFormat, $hBrush) _GDIPlus_GraphicsFillPath($hCanvas, $hPath, $hBrush) _GDIPlus_GraphicsDrawPath($hCanvas, $hPath, $hPen) _GDIPlus_ImageRotateFlip($hBitmap, $iFlip) Local Const $hBitmap_GDI = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hBitmap) _GDIPlus_GraphicsDispose($hCanvas) _GDIPlus_BitmapDispose($hBitmap) $iError = 0 EndIf _GDIPlus_PathDispose($hPath) _GDIPlus_FontDispose($hFont) _GDIPlus_FontFamilyDispose($hFamily) _GDIPlus_StringFormatDispose($hFormat) _GDIPlus_BrushDispose($hBrush) _GDIPlus_PenDispose($hPen) _GDIPlus_GraphicsDispose($hGraphic) _WinAPI_ReleaseDC(0, $hDC) If $iError Then Return SetError(1, 0, 0) Local $aResult[3] = [$hBitmap_GDI, $iH, $iW] Return $aResult EndFunc ;==>_GDIPlus_BitmapCreateVerticalText Func CheckVer($sVerInstalled, $sVerRequired) Local $aInst = StringSplit($sVerInstalled, ".") Local $aReq = StringSplit($sVerRequired, ".") Local $iInst, $iReq For $i = 1 To $aReq[0] $iInst = ($i <= $aInst[0]) ? Int($aInst[$i]) : 0 $iReq = Int($aReq[$i]) If $iInst > $iReq Then Return True If $iInst < $iReq Then Return False Next Return True EndFunc ;==>CheckVer #Region GIF ;_GDIPlus_GIFAnim* function taken from _GDIPlus_GIFAnim UDF Func _GDIPlus_GIFAnimGetFrameDimensionsCount($hImage) Local Const $aResult = DllCall($__g_hGDIPDll, "int", "GdipImageGetFrameDimensionsCount", "handle", $hImage, "ulong*", 0) If @error Then Return SetError(@error, @extended, 0) If $aResult[0] Then Return SetError(10, $aResult[0], 0) Return $aResult[2] EndFunc ;==>_GDIPlus_GIFAnimGetFrameDimensionsCount Func _GDIPlus_GIFAnimGetFrameDimensionsList($hImage, $iFramesCount) Local Const $tGUID = DllStructCreate($tagGUID) Local Const $aResult = DllCall($__g_hGDIPDll, "int", "GdipImageGetFrameDimensionsList", "handle", $hImage, "struct*", $tGUID, "uint", $iFramesCount) If @error Then Return SetError(@error, @extended, 0) If $aResult[0] Then Return SetError(10, $aResult[0], 0) Return $tGUID EndFunc ;==>_GDIPlus_GIFAnimGetFrameDimensionsList Func _GDIPlus_GIFAnimGetFrameCount($hImage, $tGUID) Local Const $aResult = DllCall($__g_hGDIPDll, "int", "GdipImageGetFrameCount", "handle", $hImage, "struct*", $tGUID, "ptr*", 0) If @error Then Return SetError(@error, @extended, 0) If $aResult[0] Then Return SetError(10, $aResult[0], 0) Return Int($aResult[3]) EndFunc ;==>_GDIPlus_GIFAnimGetFrameCount Func _GDIPlus_GIFAnimSelectActiveFrame($hImage, $tGUID, $iCurrentFrame) Local Const $aResult = DllCall($__g_hGDIPDll, "int", "GdipImageSelectActiveFrame", "handle", $hImage, "struct*", $tGUID, "uint", $iCurrentFrame) If @error Then Return SetError(@error, @extended, 0) If $aResult[0] Then Return SetError(10, $aResult[0], 0) Return True EndFunc ;==>_GDIPlus_GIFAnimSelectActiveFrame Func _GDIPlus_GIFAnimGetFrameDelays($hImage, $iAnimFrameCount) If $iAnimFrameCount < 2 Then Return SetError(1, 0, 0) Local Const $GDIP_PROPERTYTAGFRAMEDELAY = 0x5100 Local $tPropItem = __GDIPlus_ImageGetPropertyItem($hImage, $GDIP_PROPERTYTAGFRAMEDELAY) If IsDllStruct($tPropItem) And (Not @error) Then Local $iType = $tPropItem.type, $iLength, $tVal If $iType Then $iLength = $tPropItem.length Switch $iType Case 1 $tVal = DllStructCreate("byte delay[" & $iLength & "]", $tPropItem.value) Case 3 $tVal = DllStructCreate("short delay[" & Ceiling($iLength / 2) & "]", $tPropItem.value) Case 4 $tVal = DllStructCreate("long delay[" & Ceiling($iLength / 4) & "]", $tPropItem.value) Case Else Return SetError(3, 0, 0) EndSwitch Local $aFrameDelays[Int($iAnimFrameCount)], $i For $i = 0 To UBound($aFrameDelays) - 1 $aFrameDelays[$i] = $tVal.delay(($i + 1)) * 10 Next EndIf Return $aFrameDelays EndIf Return SetError(2, 0, 0) EndFunc ;==>_GDIPlus_GIFAnimGetFrameDelays Func __GDIPlus_ImageGetPropertyItem($hImage, $iPropID) Local $aResult = DllCall($__g_hGDIPDll, "int", "GdipGetPropertyItemSize", "handle", $hImage, "uint", $iPropID, "ulong*", 0) If @error Then Return SetError(@error, @extended, 0) If $aResult[0] Then Return SetError(10, $aResult[0], 0) Local Static $tBuffer $tBuffer = DllStructCreate("byte[" & $aResult[3] & "]") $aResult = DllCall($__g_hGDIPDll, "int", "GdipGetPropertyItem", "handle", $hImage, "uint", $iPropID, "ulong", $aResult[3], "struct*", $tBuffer) If @error Then Return SetError(@error, @extended, 0) If $aResult[0] Then Return SetError(11, $aResult[0], 0) Local Const $tagGDIPPROPERTYITEM = "uint id;ulong length;word type;ptr value" Local $tPropertyItem = DllStructCreate($tagGDIPPROPERTYITEM, DllStructGetPtr($tBuffer)) If @error Then Return SetError(20, $aResult[0], 0) Return $tPropertyItem EndFunc ;==>__GDIPlus_ImageGetPropertyItem Func _GDIPlus_GIFAnimCreateFile2($aImages, $sFilename, $aDelays = 100, $bReplay = True) Local Const $GDIP_EVTFrameDimensionTime = 21 Local $iMax = $aImages[0] If $iMax < 1 Then Return SetError(1, 0, False) Local Const $sCLSID = _GDIPlus_EncodersGetCLSID("GIF") Local $tMultiFrameParam = DllStructCreate("int type;") $tMultiFrameParam.type = 18 Local $tParams = _GDIPlus_ParamInit(1) _GDIPlus_ParamAdd($tParams, $GDIP_EPGSAVEFLAG, 1, 4, DllStructGetPtr($tMultiFrameParam)) Local Const $hStream = _WinAPI_CreateStreamOnHGlobal() Local $tGUID = _WinAPI_GUIDFromString($sCLSID) _GDIPlus_ImageSaveToStream($aImages[1], $hStream, DllStructGetPtr($tGUID), DllStructGetPtr($tParams)) If $iMax > 1 Then $tMultiFrameParam.type = $GDIP_EVTFrameDimensionTime $tParams = _GDIPlus_ParamInit(1) _GDIPlus_ParamAdd($tParams, $GDIP_EPGSAVEFLAG, 1, 4, DllStructGetPtr($tMultiFrameParam)) For $i = 2 To $iMax _GDIPlus_ImageSaveAddImage($aImages[1], $aImages[$i], $tParams) Next $tMultiFrameParam.type = 19 $tParams = _GDIPlus_ParamInit(1) _GDIPlus_ParamAdd($tParams, $GDIP_EPGSAVEFLAG, 1, 4, DllStructGetPtr($tMultiFrameParam)) _GDIPlus_ImageSaveAdd($aImages[1], $tParams) EndIf $tMultiFrameParam.type = 20 $tParams = _GDIPlus_ParamInit(1) _GDIPlus_ParamAdd($tParams, $GDIP_EPGSAVEFLAG, 1, 4, DllStructGetPtr($tMultiFrameParam)) _GDIPlus_ImageSaveAdd($aImages[1], $tParams) Local Const $hMemory = _WinAPI_GetHGlobalFromStream($hStream) Local Const $iMemSize = _MemGlobalSize($hMemory) Local Const $pMem = _MemGlobalLock($hMemory) Local Const $iNewSize = $bReplay ? ($iMemSize + 19) : $iMemSize Local Const $hNewMem = _MemGlobalAlloc($iNewSize, 0x0002) Local Const $pNewMem = _MemGlobalLock($hNewMem) Local $tNewData = DllStructCreate("byte mem[" & $iNewSize & "]", $pNewMem) Local Const $hDLL_msvcrt = DllOpen("msvcrt.dll") Local $iCopyOffset = 0 If $bReplay Then Local $tNetscape = DllStructCreate("byte mem[19]") $tNetscape.mem = Binary("0x21FF0B4E45545343415045322E300301000000") Local $aResult = DllCall($hDLL_msvcrt, "ptr:cdecl", "memchr", "ptr", $pMem, "int", 0x21, "ulong_ptr", $iMemSize) If @error Or Not IsArray($aResult) Then _MemGlobalUnlock($hMemory) _MemGlobalUnlock($hNewMem) _MemGlobalFree($hNewMem) _WinAPI_ReleaseStream($hStream) DllClose($hDLL_msvcrt) Return SetError(3, 0, False) EndIf Local $pFound = $aResult[0], $tCheck, $iInsertPos While $pFound <> 0 $tCheck = DllStructCreate("byte mem[3]", $pFound) If $tCheck.mem(1) = 0x21 And $tCheck.mem(2) = 0xF9 And $tCheck.mem(3) = 0x04 Then $iInsertPos = $pFound - $pMem DllCall($hDLL_msvcrt, "ptr:cdecl", "memcpy", "ptr", $pNewMem, "ptr", $pMem, "ulong_ptr", $iInsertPos) DllCall($hDLL_msvcrt, "ptr:cdecl", "memcpy", "ptr", $pNewMem + $iInsertPos, "struct*", $tNetscape, "ulong_ptr", 19) DllCall($hDLL_msvcrt, "ptr:cdecl", "memcpy", "ptr", $pNewMem + $iInsertPos + 19, "ptr", $pMem + $iInsertPos, "ulong_ptr", $iMemSize - $iInsertPos) $iCopyOffset = 19 ExitLoop EndIf $aResult = DllCall($hDLL_msvcrt, "ptr:cdecl", "memchr", "ptr", $pFound + 1, "int", 0x21, "ulong_ptr", $iMemSize - ($pFound - $pMem) - 1) $pFound = $aResult[0] WEnd Else DllCall($hDLL_msvcrt, "ptr:cdecl", "memcpy", "ptr", $pNewMem, "ptr", $pMem, "ulong_ptr", $iMemSize) EndIf _MemGlobalUnlock($hMemory) _WinAPI_ReleaseStream($hStream) _MemGlobalFree($hMemory) Local $pSearch = $pNewMem Local $iRemainingByte = $iNewSize Local $iFrameCount = 0, $iDelay, $aResult, $pFound, $tCheck, $isArray = IsArray($aDelays) While $iFrameCount < $iMax And $iRemainingByte > 6 $aResult = DllCall($hDLL_msvcrt, "ptr:cdecl", "memchr", "ptr", $pSearch, "int", 0x21, "ulong_ptr", $iRemainingByte) If $aResult[0] = 0 Then ExitLoop $pFound = $aResult[0] $tCheck = DllStructCreate("byte mem[6]", $pFound) If $tCheck.mem(2) = 0xF9 And $tCheck.mem(3) = 0x04 Then $iDelay = $isArray ? $aDelays[$iFrameCount] : $aDelays $iDelay = Int($iDelay / 10) $tCheck.mem(5) = BitAND($iDelay, 0xFF) $tCheck.mem(6) = BitShift($iDelay, 8) $iFrameCount += 1 $pSearch = $pFound + 8 Else $pSearch = $pFound + 1 EndIf $iRemainingByte = $iNewSize - ($pSearch - $pNewMem) WEnd DllClose($hDLL_msvcrt) Local $hFile = FileOpen($sFilename, BitOR(16, 2)) If $hFile = -1 Then _MemGlobalUnlock($hNewMem) _MemGlobalFree($hNewMem) Return SetError(2, 0, False) EndIf FileWrite($hFile, $tNewData.mem) FileClose($hFile) _MemGlobalUnlock($hNewMem) _MemGlobalFree($hNewMem) Return True EndFunc ;==>_GDIPlus_GIFAnimCreateFile2 Func _GDIPlus_BitmapConvertTo8Bit(ByRef $hBitmap, $iColorCount = 256, $iDitherType = 9, $iPaletteType = 8, $bUseTransparentColor = True) $iColorCount = ($iColorCount > 2 ^ 8) ? 2 ^ 8 : $iColorCount Local $tPalette = _GDIPlus_PaletteInitialize(256, $iPaletteType, $iColorCount, $bUseTransparentColor, $hBitmap) If @error Then Return SetError(1, @error, 0) Local $iRet = _GDIPlus_BitmapConvertFormat($hBitmap, 0x00030803, $iDitherType, $iPaletteType, $tPalette) If @error Then Return SetError(2, @error, 0) Return $iRet EndFunc ;==>_GDIPlus_BitmapConvertTo8Bit #EndRegion GIF Examples: The required DLLs (_GDIPlus_BitmapApplyFilter.dll / _GDIPlus_BitmapApplyFilter_x64.dll) and _GDIPlus_BitmapApplyFilter.au3 can be found on my OneDrive: _GDIPlus_BitmapApplyFilter
-
Added "About" menu entry in Sysmenu (left upper corner in the GUI) and in "Menu One". Check out _WM_MENUCOMMAND function. See first post.
-
Not that I know of.
-
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.
-
Convert Emojis to GDI+ using Direct2D / DWrite. ;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
-
Code updated -> see 1st post.
-
UEZ reacted to a file:
AutoIt DLL Guide
-
Another WMI methode seems to work, too: ;Coded by UEZ build 2025-12-07 Func WMI_GetHDDSerialNumber() Local $oWMI = ObjGet("winmgmts:\\.\root\Microsoft\Windows\Storage") If Not IsObj($oWMI) Then Return "Error: WMI Storage Namespace not found (Win8+ required)" Local $colItems = $oWMI.ExecQuery("SELECT FriendlyName, SerialNumber, AdapterSerialNumber FROM MSFT_PhysicalDisk") Local $aResult[100][3], $c = 0 For $objItem In $colItems With $objItem $aResult[$c][0] = .FriendlyName $aResult[$c][1] = .SerialNumber $aResult[$c][2] = .AdapterSerialNumber ConsoleWrite("-----------------------------------" & @CRLF) ConsoleWrite("Name: " & $aResult[$c][0]& @CRLF) ConsoleWrite("SerialNumber: " & $aResult[$c][1] & @CRLF) ConsoleWrite("AdapterSerial: " & $aResult[$c][2]& @CRLF) EndWith $c += 1 Next ReDim $aResult[$c][3] Return $aResult EndFunc Global $a = WMI_GetHDDSerialNumber()
-
This is the same result as C:\Windows\System32>wmic path win32_physicalmedia get serialnumber SerialNumber 8CE3_8E10_02B1_5166. Yes, CrystalDiskInfo shows 7E5CT5TPZ164 as s/n. Need some more investigation...
-
Or the WinAPI way: ;Coded by UEZ build 2025-12-07 beta ;~ #RequireAdmin #include <WinAPIFiles.au3> #include <WinAPIHObj.au3> Func _WinAPI_GetPhysicalDriveNumber($driveLetter) $driveLetter = StringLeft($driveLetter, 1) Local $hVolume = _WinAPI_CreateFile("\\.\" & $driveLetter & ":", 2, 0, 6) If $hVolume = 0 Then Return SetError(1, 0, -1) Local $tSDN = DllStructCreate("dword DeviceType;dword DeviceNumber;dword PartitionNumber") Local $bResult = _WinAPI_DeviceIoControl($hVolume, $IOCTL_STORAGE_GET_DEVICE_NUMBER, 0, 0, $tSDN, DllStructGetSize($tSDN)) _WinAPI_CloseHandle($hVolume) If Not $bResult Then Return SetError(2, 0, -1) Return $tSDN.DeviceNumber EndFunc Func _WinAPI_GetHDDSerialByPhysicalDrive($driveNumber = 0) Local $hDrive = _WinAPI_CreateFile("\\.\PhysicalDrive" & $driveNumber, 2, 0, 6) If $hDrive = 0 Then Return SetError(1, 0, "") Local $tSPQ = DllStructCreate("int PropertyId;int QueryType;byte AdditionalParameters[1]") With $tSPQ .PropertyId = 0 ; StorageDeviceProperty .QueryType = 0 ; PropertyStandardQuery EndWith Local $tBuffer = DllStructCreate("byte[65536]") Local $bResult = _WinAPI_DeviceIoControl($hDrive, $IOCTL_STORAGE_QUERY_PROPERTY, $tSPQ, DllStructGetSize($tSPQ), $tBuffer, DllStructGetSize($tBuffer)) _WinAPI_CloseHandle($hDrive) If Not $bResult Then Return SetError(2, 0, "") ; Parse STORAGE_DEVICE_DESCRIPTOR header Local $tHeader = DllStructCreate("dword Version;dword Size;byte DeviceType;byte DeviceTypeModifier;" & _ "byte RemovableMedia;byte CommandQueueing;dword VendorIdOffset;dword ProductIdOffset;" & _ "dword ProductRevisionOffset;dword SerialNumberOffset", DllStructGetPtr($tBuffer)) Local $serialOffset = $tHeader.SerialNumberOffset If $serialOffset = 0 Then Return SetError(3, 0, "") ; Read the serial number string Local $basePtr = DllStructGetPtr($tBuffer) Local $serial = "", $i, $tChar, $byte For $i = 0 To 200 $tChar = DllStructCreate("byte b", $basePtr + $serialOffset + $i) $byte = $tChar.b If $byte = 0 Then ExitLoop $serial &= Chr($byte) Next Return StringStripWS($serial, 3) EndFunc Func _WinAPI_GetHDDModelByPhysicalDrive($driveNumber = 0) Local $hDrive = _WinAPI_CreateFile("\\.\PhysicalDrive" & $driveNumber, 2, 0, 6) If $hDrive = 0 Then Return SetError(1, 0, "") Local $tSPQ = DllStructCreate("int PropertyId;int QueryType;byte AdditionalParameters[1]") With $tSPQ .PropertyId = 0 .PropertyId = 0 EndWith Local $tBuffer = DllStructCreate("byte[65536]") Local $bResult = _WinAPI_DeviceIoControl($hDrive, $IOCTL_STORAGE_QUERY_PROPERTY, $tSPQ, DllStructGetSize($tSPQ), $tBuffer, DllStructGetSize($tBuffer)) _WinAPI_CloseHandle($hDrive) If Not $bResult Then Return SetError(2, 0, "") Local $tHeader = DllStructCreate("dword Version;dword Size;byte DeviceType;byte DeviceTypeModifier;" & _ "byte RemovableMedia;byte CommandQueueing;dword VendorIdOffset;dword ProductIdOffset;" & _ "dword ProductRevisionOffset;dword SerialNumberOffset", DllStructGetPtr($tBuffer)) Local $productOffset = $tHeader.ProductIdOffset If $productOffset = 0 Then Return SetError(3, 0, "") Local $basePtr = DllStructGetPtr($tBuffer) Local $product = "", $tChar, $tChar, $i For $i = 0 To 200 $tChar = DllStructCreate("byte b", $basePtr + $productOffset + $i) $byte = $tChar.b If $byte = 0 Then ExitLoop $product &= Chr($byte) Next Return StringStripWS($product, 3) EndFunc Func _WinAPI_GetVolumeSerial($drive = "C:\") Local $aInfo = _WinAPI_GetVolumeInformation($drive) If @error Then Return SetError(@error, 0, "") Return Hex($aInfo[1], 8) EndFunc ConsoleWrite("=== HDD Information ===" & @CRLF & @CRLF) Local $physDrive = _WinAPI_GetPhysicalDriveNumber("C") ConsoleWrite("Physical drive number for C: " & $physDrive & @CRLF) If $physDrive >= 0 Then Local $model = _WinAPI_GetHDDModelByPhysicalDrive($physDrive) ConsoleWrite("Model: " & $model & @CRLF) Local $serial = _WinAPI_GetHDDSerialByPhysicalDrive($physDrive) ConsoleWrite("Serial Number: " & $serial & @CRLF) EndIf Local $volSerial = _WinAPI_GetVolumeSerial() ConsoleWrite("Volume Serial: " & $volSerial & @CRLF & @CRLF) My result: === HDD Information === Physical drive number for C: 0 Model: BG6 KIOXIA 256GB Serial Number: 8CE3_8E10_02B1_5166. Volume Serial: 40D09020
-
I didn't read all the posts in this thread. I found an old WMI script which returns the s/n: Global $oErrorHandler = ObjEvent("AutoIt.Error", "ObjErrorHandler") MsgBox(0, "Test", WMI_GetHDDSN(".")) Func WMI_GetHDDSN($host, $usr = "", $pass = "") ;coded by UEZ 2011 If $host = "." Then $host = "localhost" Local $HDD_SN Local $ping = Ping($host, 1000) If @error Then Return SetError(1, 0, -1) Local $objWMILocator = ObjCreate("WbemScripting.SWbemLocator") Local $objWMIService = $objWMILocator.ConnectServer($host, "\root\cimv2", $usr, $pass, "", "", 128) If @error Then Return SetError(2, 0, -1) Local $colItems = $objWMIService.ExecQuery("SELECT Model, Name, SerialNumber FROM Win32_DiskDrive WHERE MediaType='Fixed hard disk media'", "WQL", 0x30) If IsObj($colItems) Then For $objItem In $colItems $HDD_SN &= "Model: " & $objItem.Model & ", S/N: " & WMI_GetHDDSN2(StringMid($objItem.Name, 5), $host, $usr, $pass) & @LF Next Else Return SetError(3, 0, -1) EndIf Return $HDD_SN EndFunc Func WMI_GetHDDSN2($Tag, $host, $usr = "", $pass = "") ;coded by UEZ 2011 Local $HDD_SN Local $objWMILocator = ObjCreate("WbemScripting.SWbemLocator") Local $objWMIService = $objWMILocator.ConnectServer($host, "\root\cimv2", $usr, $pass, "", "", 128) Local $colItems = $objWMIService.ExecQuery("SELECT SerialNumber,Tag FROM Win32_PhysicalMedia WHERE Tag LIKE '%" & $Tag & "%'", "WQL", 0x30) If IsObj($colItems) Then For $objItem In $colItems ;~ ConsoleWrite($objItem.Tag & @LF) $HDD_SN = $objItem.SerialNumber Next Else Return SetError(3, 0, -1) EndIf Return $HDD_SN EndFunc Func ObjErrorHandler() ConsoleWrite( "A COM Error has occured!" & @CRLF & @CRLF & _ "err.description is: " & @TAB & $oErrorHandler.description & @CRLF & _ "err.windescription:" & @TAB & $oErrorHandler & @CRLF & _ "err.number is: " & @TAB & Hex($oErrorHandler.number, 8) & @CRLF & _ "err.lastdllerror is: " & @TAB & $oErrorHandler.lastdllerror & @CRLF & _ "err.scriptline is: " & @TAB & $oErrorHandler.scriptline & @CRLF & _ "err.source is: " & @TAB & $oErrorHandler.source & @CRLF & _ "err.helpfile is: " & @TAB & $oErrorHandler.helpfile & @CRLF & _ "err.helpcontext is: " & @TAB & $oErrorHandler.helpcontext & @CRLF _ ) EndFunc I don't know if this is what you guys are looking for.
-
I assume you must hook to the external program to change visuals.
-
Converting Transparency Level 0-255 To Percentage
UEZ replied to WildByDesign's topic in AutoIt General Help and Support
A generic map function: ;Coded by UEZ build 2025-10-29 Func Map($val, $source_start, $source_stop, $dest_start, $dest_stop) Return (($val - $source_start) * ($dest_stop - $dest_start) / ($source_stop - $source_start) + $dest_start) EndFunc $iCol = Int(Map(87, 0, 100, 0, 255)) ConsoleWrite($iCol & " - 0x" & Hex($iCol, 2) & @CRLF) ;87% from color value (0 - 255) $iCol = 1 + Int(Map($iCol, 0, 255, 0, 100)) ;and back again ConsoleWrite($iCol & " - 0x" & Hex($iCol, 2) & @CRLF)