Leaderboard
Popular Content
Showing content with the highest reputation since 06/24/2025 in Posts
-
WebP v0.3.5 build 2025-07-01 beta
pixelsearch and 2 others reacted to UEZ for a topic
Updated to: WebP v0.3.5 build 2025-06-27 beta You can now create WebP animated files. Examples8 encodes GDI+ supported image files to an animation. Example9 captures the desktop screen to an WebP anim file.3 points -
You can simply try this code: It uses GDI+ to draw a red circle with centered text, creates a 32-bit ARGB icon, and sets it as a taskbar overlay using ITaskbarList3::SetOverlayIcon. It updates the icon every second. You can easily adjust it to fit your own needs. Let me know if it works for you! #include <GDIPlus.au3> #include <GUIConstantsEx.au3> #include <WinAPIIcons.au3> Global $oError = ObjEvent("AutoIt.Error", "_ErrFunc") Func _ErrFunc() ConsoleWrite("! COM Error ! Number: 0x" & Hex($oError.number, 8) & " Line: " & $oError.scriptline & " - " & $oError.windescription & @CRLF) EndFunc ; Define ITaskbarList3 COM interface Global Const $sCLSID_TaskbarList = "{56FDF344-FD6D-11D0-958A-006097C9A090}" Global Const $sIID_ITaskbarList3 = "{EA1AFB91-9E28-4B86-90E9-9E9F8A5EEFAF}" Global Const $tagITaskbarList3 = _ "HrInit hresult();" & _ "AddTab hresult(hwnd);" & _ "DeleteTab hresult(hwnd);" & _ "ActivateTab hresult(hwnd);" & _ "SetActiveAlt hresult(hwnd);" & _ "MarkFullscreenWindow hresult(hwnd;boolean);" & _ "SetProgressValue hresult(hwnd;uint64;uint64);" & _ "SetProgressState hresult(hwnd;int);" & _ "RegisterTab hresult(hwnd;hwnd);" & _ "UnregisterTab hresult(hwnd);" & _ "SetTabOrder hresult(hwnd;hwnd);" & _ "SetTabActive hresult(hwnd;hwnd;dword);" & _ "ThumbBarAddButtons hresult(hwnd;uint;ptr);" & _ "ThumbBarUpdateButtons hresult(hwnd;uint;ptr);" & _ "ThumbBarSetImageList hresult(hwnd;ptr);" & _ "SetOverlayIcon hresult(hwnd;ptr;wstr);" & _ "SetThumbnailTooltip hresult(hwnd;wstr);" & _ "SetThumbnailClip hresult(hwnd;ptr);" ; Global variables Global $hGraphic, $hTextBrush, $hFormat, $hFamily, $hFont, $hBackgroundBrush, $hPen Global $oList, $hWnd Global $iWidth = 32, $iHeight = 32, $iFontSize = 12 Global $iCounter = 0 Main() Func Main() _GDIPlus_Startup() $hWnd = GUICreate("Taskbar Overlay Icon Test", 400, 300) Local $label = GUICtrlCreateLabel("Starting...", 10, 10, 380, 100) GUISetState() $hGraphic = _GDIPlus_GraphicsCreateFromHWND($hWnd) $hTextBrush = _GDIPlus_BrushCreateSolid(0xFFFFFFFF) $hFormat = _GDIPlus_StringFormatCreate() $hFamily = _GDIPlus_FontFamilyCreate("Arial") $hFont = _GDIPlus_FontCreate($hFamily, $iFontSize) $hBackgroundBrush = _GDIPlus_BrushCreateSolid(0xFFFF0000) $hPen = _GDIPlus_PenCreate(0xFF000000, 2) $oList = ObjCreateInterface($sCLSID_TaskbarList, $sIID_ITaskbarList3, $tagITaskbarList3) If Not IsObj($oList) Then MsgBox(16, "Error", "Failed to initialize ITaskbarList3.") Exit EndIf $oList.HrInit() If @error Then MsgBox(16, "Error", "HrInit failed: " & @error) Exit EndIf GUICtrlSetData($label, "$oList.AddTab") $oList.AddTab($hWnd) If @error Then MsgBox(16, "Error", "Failed to add taskbar tab: " & @error) Exit EndIf _UpdateOverlayIcon($iCounter) GUICtrlSetData($label, "Overlay icon initialized with counter: " & $iCounter) Local $hTimer = TimerInit() While 1 If TimerDiff($hTimer) > 1000 Then $iCounter += 1 If $iCounter > 99 Then $iCounter = 99 _UpdateOverlayIcon($iCounter) GUICtrlSetData($label, "Counter: " & $iCounter) $hTimer = TimerInit() EndIf If GUIGetMsg() = $GUI_EVENT_CLOSE Then ExitLoop Sleep(10) WEnd GUICtrlSetData($label, "Removing overlay icon and tab") _Taskbar_SetOverlayIcon($oList, $hWnd, Null, "") $oList.DeleteTab($hWnd) $oList = 0 _GDIPlus_FontDispose($hFont) _GDIPlus_PenDispose($hPen) _GDIPlus_FontFamilyDispose($hFamily) _GDIPlus_StringFormatDispose($hFormat) _GDIPlus_BrushDispose($hTextBrush) _GDIPlus_BrushDispose($hBackgroundBrush) _GDIPlus_GraphicsDispose($hGraphic) _GDIPlus_Shutdown() EndFunc Func _UpdateOverlayIcon($iCount) Local $hBitmap = _GDIPlus_BitmapCreateFromScan0($iWidth, $iHeight, $GDIP_PXF32ARGB) Local $hGraphicBitmap = _GDIPlus_ImageGetGraphicsContext($hBitmap) _GDIPlus_GraphicsSetSmoothingMode($hGraphicBitmap, 2) _GDIPlus_GraphicsClear($hGraphicBitmap, 0x00000000) _GDIPlus_GraphicsFillEllipse($hGraphicBitmap, 0, 0, $iWidth - 2, $iHeight - 2, $hBackgroundBrush) _GDIPlus_GraphicsDrawEllipse($hGraphicBitmap, 0, 0, $iWidth - 2, $iHeight - 2, $hPen) Local $tLayout = _GDIPlus_RectFCreate(2, 2, $iWidth - 4, $iHeight - 8) DrawStringCentered($hGraphicBitmap, $iCount, $hFont, $tLayout, $hFormat, $hTextBrush) Local $hIcon = _GDIPlus_HICONCreateFromBitmap($hBitmap) If @error Then MsgBox(16, "Error", "Failed to create HICON: " & @error) Exit EndIf _Taskbar_SetOverlayIcon($oList, $hWnd, $hIcon, "Counter: " & $iCount) _WinAPI_DestroyIcon($hIcon) _GDIPlus_BitmapDispose($hBitmap) _GDIPlus_GraphicsDispose($hGraphicBitmap) EndFunc Func DrawStringCentered($hGraphic, $iIndex, $hFont, $tLayout, $hFormat, $hTextBrush) Local $aInfo = _GDIPlus_GraphicsMeasureString($hGraphic, $iIndex, $hFont, $tLayout, $hFormat) Local $tIndex = $aInfo[0] $tIndex.X = $tLayout.X + (($tLayout.Width - $tIndex.Width) / 2) $tIndex.Y = $tLayout.Y + (($tLayout.Height - _GDIPlus_FontGetHeight($hFont, $hGraphic)) / 2) _GDIPlus_GraphicsDrawStringEx($hGraphic, $iIndex, $hFont, $tIndex, $hFormat, $hTextBrush) EndFunc Func _Taskbar_SetOverlayIcon(ByRef $oTB, $hWnd, $hIcon, $sAltText = "") Local $vRet = $oTB.SetOverlayIcon($hWnd, $hIcon, $sAltText) If @error Then Return SetError(@error, @extended, False) If $vRet = 0 Then Return True Return SetError($vRet, 0, False) EndFunc3 points
-
Make active transparent icon on image background
argumentum and 2 others reacted to UEZ for a topic
I have thought again and this is simpler and the better solution. #NoTrayIcon ;#RequireAdmin #include <WinAPISys.au3> #include <GDIPlus.au3> #include <WinAPIShellEx.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <ButtonConstants.au3> #include <StaticConstants.au3> Example() Func Example() Local $hGUI, $hGraphic, $hIcon, $hBitmap, $iX = 768, $iY = 525 $hGUI = GUICreate("GDI+", $iX, $iY) _GDIPlus_Startup() ; Create GUI Global $idPic = GUICtrlCreatePic("", 0, 0, $iX, $iY) Global $sFileName = @ScriptDir& "\MAIN.png" $hImage = _GDIPlus_ImageLoadFromFile($sFileName) $iX = _GDIPlus_ImageGetWidth($hImage) $iY = _GDIPlus_ImageGetHeight($hImage) $hBGImage = _GDIPlus_BitmapCreateFromScan0($iX, $iY) $hGraphic = _GDIPlus_ImageGetGraphicsContext($hBGImage) _GDIPlus_GraphicsDrawImage($hGraphic, $hImage, 0, 0) $btnx = 250 $btny = 150 ;_GDIPlus_GraphicsClear($hGraphic, 0xFFFFFFFF) $hIcon = _WinAPI_ShellExtractIcon(@SystemDir & '\shell32.dll', 221, 48, 48) $hBitmap = _GDIPlus_BitmapCreateFromHICON32($hIcon) _GDIPlus_GraphicsDrawImage($hGraphic, $hBitmap, $btnx, $btny) $shBitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hBGImage) _WinAPI_DeleteObject(GUICtrlSendMsg($idPic, 0x0172, 0, $shBitmap)) ; STM_SETIMAGE = 0x0172, $IMAGE_BITMAP = 0 GUICtrlSetState($idPic, $gui_disable) GUICtrlSetState(-1, $GUI_ONTOP) GUICtrlSetCursor(-1, 0) $hIcon = GUICtrlCreateIcon(@SystemDir & '\shell32.dll', -1, $btnx, $btny, 48, 48, BitOR($SS_NOTIFY, $SS_BLACKRECT)) GUISetState() ; Loop until user exits Do Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop Case $hIcon ConsoleWrite("Icon clicked" & @CRLF) EndSwitch Until False ; Clean up resources _WinAPI_DestroyIcon($hIcon) _WinAPI_DeleteObject($shBitmap) _GDIPlus_BitmapDispose($hImage) _GDIPlus_BitmapDispose($hBGImage) _GDIPlus_BitmapDispose($hBitmap) _GDIPlus_GraphicsDispose($hGraphic) _GDIPlus_Shutdown() EndFunc ;==>Example3 points -
One way to launch other tools while a compiled program is running would be to use a tool like this: Scite Plusbar2 points
-
Understand the request, but this is how the internals work in SciTE to be able to capture the output generated by the Script. These are things I won't be trying to change unless it is changed in the Core version supported by Neil.2 points
-
Yes, I forgot to removed these lines for the other functions but I need to add the code also for the other function with callbacks. Currently only function "WebP_CreateWebPCreateAnimFromScreenCapture" in the dll is implemented (example 9) for callback but it should be easy to add also for the other functions. I think tomorrow I will add it to the other functions, too.2 points
-
How to pin a script to the taskbar or start menu
UEZ and one other reacted to argumentum for a topic
vs. If you would like to pin the script to the taskbar ( or the start menu ), it can be done with a link. This script is an example and demonstration. The way that I go about it, is to have the script and icon with the same name. The easiest way to test this is if the post had it all in a ZIP file so, there: Example AutoIt v3 Script_v2.zip Also, it's easier to find in task manager given that you can see your icon.2 points -
GimageX updates
argumentum and one other reacted to Jon for a topic
I've updated GImageX with the latest version of the ADK. (Dec 2024 version). Don't think the ADK version was the OP's issue. But updated it anyway.2 points -
I dont see $btny used anywhere, $btnx appears to be used for both X and Y positions.2 points
-
Hi Jos, a feature request for SciTE from my side. When I run code in SciTE, all entries under "Tools" except the last 5 are greyed out. Would it be possible to leave those enabled, which do not interfere with the current code execution? Especially for running "AU3Info" I don't know how many times I had to abort the current execution, start AU3Info and then run the code again 🙂, because I forgot to start AU3Info early. Maybe it makes sense to leave some others enabled too, e.g. Open Explorer in Scriptdir, Codewizard and Koda? Best Regards1 point
-
WebP v0.3.5 build 2025-07-01 beta
UEZ reacted to pixelsearch for a topic
Yes it is working. The 10s output file "Captured.webp" displays in the GUI, then loops until we close the GUI. It displays same in IrfanView.1 point -
WebP v0.3.5 build 2025-07-01 beta
UEZ reacted to pixelsearch for a topic
Hello @UEZ Just downloaded all your files (including the Frames subfolder containing 10 png files to create the animation). Somes files were updated 3 hours ago, lucky me to download the brand new release just now Example 8 worked fine and the created animation "TestAnim.webp" displayed without any issue. Well done1 point -
Embedding font in compiled binary and loading per-session
WildByDesign reacted to UEZ for a topic
Here you should find one way how to embed your font (Display Font from Memory):1 point -
DwmColorBlurMica
argumentum reacted to WildByDesign for a topic
Microsoft insists that the false positive is removed from the compiled binary and is no longer detected by Windows Defender. VirusTotal shows it. But apparently Windows Defender itself does not detect it and we're good to go. First post has been updated with version 1.0.3. This version is mostly a bug-fix release with a fix for Windows Terminal losing border color after being minimized. And a regression where border colors, if not set in custom rules, were not properly falling back to the global set value. That was a weird bug that took me forever to understand how/why it was happening but finally fixed it. I also made some changes that made the overall performance even better. Several functions were made to be more efficient. Less loops. I also made a special function Func _ColorBorderOnly($hWnd, $sClassName, $sName) to handle the border coloring in the Foreground Case only. Prior to that, the border stuff was going through the main coloring function and therefore a lot of extra stuff that was not necessary in the Foreground Case. So this also made things much more efficient.1 point -
AutoIt Script for TLS Security Context Initialization (Schannel, Customizable)
argumentum reacted to Numeric1 for a topic
In the context of a complex project with stringent TLS requirements and various technical constraints, I decided to dive into the core of security mechanisms. While many off-the-shelf solutions exist for handling security contexts, I wanted to explore the fundamentals directly. Here, I’m sharing a raw and isolated excerpt of an AutoIt script that initializes a TLS security context using the Schannel API. This code is functional but deliberately minimal, providing a solid foundation for optimization and enhanced robustness. #include-once #include <WinAPI.au3> #include <WinAPIError.au3> #include <AutoItConstants.au3> #include <Date.au3> ; Constantes Schannel Global Const $SEC_E_OK = 0x00000000 Global Const $SEC_I_CONTINUE_NEEDED = 0x00090312 Global Const $SEC_E_INCOMPLETE_MESSAGE = 0x80090318 Global Const $SEC_E_INVALID_TOKEN = 0x80090308 Global Const $SECPKG_CRED_OUTBOUND = 2 Global Const $UNISP_NAME = "Microsoft Unified Security Protocol Provider" Global Const $SCHANNEL_CRED_VERSION = 4 Global Const $SCH_CRED_NO_DEFAULT_CREDS = 0x00000010 Global Const $SCH_CRED_AUTO_CRED_VALIDATION = 0x00000020 ; Flags pour InitializeSecurityContext Global Const $ISC_REQ_SEQUENCE_DETECT = 0x00000008 Global Const $ISC_REQ_REPLAY_DETECT = 0x00000004 Global Const $ISC_REQ_CONFIDENTIALITY = 0x00000010 Global Const $ISC_REQ_ALLOCATE_MEMORY = 0x00000100 Global Const $ISC_REQ_STREAM = 0x00008000 ; Types buffers Global Const $SECBUFFER_TOKEN = 2 Global Const $SECBUFFER_EMPTY = 0 ; Attributes QueryContextAttributes Global Const $SECPKG_ATTR_REMOTE_CERT_CONTEXT = 0x53 Global Const $SECPKG_ATTR_CONNECTION_INFO = 0x5A ; Structures Global Const $tagCRED_HANDLE = "struct;ULONG_PTR dwLower;ULONG_PTR dwUpper;endstruct;" Global Const $tagSCHANNEL_CRED = "struct;" & _ "dword dwVersion;" & _ "dword dwCredFormat;" & _ "dword cCreds;" & _ "ptr paCred;" & _ "ptr hRootStore;" & _ "dword cMappers;" & _ "ptr aphMappers;" & _ "byte reserved[4];" & _ "dword dwSessionLifespan;" & _ "dword dwFlags;" & _ "dword cTlsParameters;" & _ "ptr pTlsParameters;" & _ "endstruct;" Global Const $tagSEC_BUFFER = "struct;dword cbBuffer;dword BufferType;ptr pvBuffer;endstruct;" Global Const $tagSEC_BUFFER_DESC = "struct;dword ulVersion;dword cBuffers;ptr pBuffers;endstruct;" Global Const $tagCERT_CONTEXT = "struct;" & _ "dword dwCertEncodingType;" & _ "ptr pbCertEncoded;" & _ "dword cbCertEncoded;" & _ "ptr pCertInfo;" & _ "ptr hCertStore;" & _ "endstruct;" Global Const $tagCERT_INFO = "struct;" & _ "dword dwVersion;" & _ "dword cbSerialNumber;ptr pbSerialNumber;" & _ "ptr pszObjId;dword cbData;ptr pbData;" & _ "dword cbIssuer;ptr pbIssuer;" & _ "dword NotBeforeLow;dword NotBeforeHigh;" & _ "dword NotAfterLow;dword NotAfterHigh;" & _ "dword cbSubject;ptr pbSubject;" & _ "ptr pSubjectPublicKeyInfo;" & _ "dword cbIssuerUniqueId;ptr pbIssuerUniqueId;" & _ "dword cbSubjectUniqueId;ptr pbSubjectUniqueId;" & _ "dword cExtension;" & _ "ptr rgExtension;" & _ "endstruct;" ; Variables globales Global $iSocket = -1 Global $tCredHandle, $tCtxtHandle Global $sHost = "www.google.com" Global $g_iDetectedTLSVersion = 0 Func InitializeTLS() TCPStartup() Sleep(100) ; Initial delay to stabilize the network Local $sIP = TCPNameToIP($sHost) If @error Then ConsoleWrite("Error: Failed to establish TCP connection to " & $sHost & @CRLF) Cleanup() Return False EndIf $iSocket = TCPConnect($sIP, 443) If $iSocket = -1 Then ConsoleWrite("Error: Failed to establish TCP connection to " & $sHost & @CRLF) Cleanup() Return False EndIf $tCredHandle = _AcquireCredentialsHandle() If @error Then Cleanup() Return False EndIf Local $bResult = EstablishSecurityContext() If Not $bResult Then Cleanup() EndIf Return $bResult EndFunc ;==>InitializeTLS Func _AcquireCredentialsHandle() Local $tCred = DllStructCreate($tagSCHANNEL_CRED) Local $tTimeStamp = DllStructCreate("dword;dword") Local $tHandle = DllStructCreate($tagCRED_HANDLE) DllStructSetData($tCred, "dwVersion", $SCHANNEL_CRED_VERSION) DllStructSetData($tCred, "dwCredFormat", 0) DllStructSetData($tCred, "cCreds", 0) DllStructSetData($tCred, "paCred", 0) DllStructSetData($tCred, "hRootStore", 0) DllStructSetData($tCred, "cMappers", 0) DllStructSetData($tCred, "aphMappers", 0) DllStructSetData($tCred, "dwSessionLifespan", 0) DllStructSetData($tCred, "dwFlags", BitOR($SCH_CRED_NO_DEFAULT_CREDS, $SCH_CRED_AUTO_CRED_VALIDATION)) DllStructSetData($tCred, "cTlsParameters", 0) DllStructSetData($tCred, "pTlsParameters", 0) DllStructSetData($tCred, "grbitEnabledProtocols", BitOR(0x00000800, 0x00002000)) ; TLS 1.2 et 1.3 Local $aRet = DllCall("secur32.dll", "long", "AcquireCredentialsHandleW", _ "wstr", "", _ "wstr", $UNISP_NAME, _ "dword", $SECPKG_CRED_OUTBOUND, _ "ptr", 0, _ "ptr", DllStructGetPtr($tCred), _ "ptr", 0, _ "ptr", 0, _ "ptr", DllStructGetPtr($tHandle), _ "ptr", DllStructGetPtr($tTimeStamp)) If @error Or $aRet[0] <> $SEC_E_OK Then ConsoleWrite("Error AcquireCredentialsHandle: " & Hex($aRet[0]) & @CRLF) Return SetError(1, 0, 0) EndIf ConsoleWrite("Credentials acquired successfully" & @CRLF) Return $tHandle EndFunc ;==>_AcquireCredentialsHandle Func EstablishSecurityContext() Local $tInBufferDesc = DllStructCreate($tagSEC_BUFFER_DESC) Local $tOutBufferDesc = DllStructCreate($tagSEC_BUFFER_DESC) Local $tInBuffer = DllStructCreate($tagSEC_BUFFER) Local $tOutBuffer = DllStructCreate($tagSEC_BUFFER) Local $tCtxtNew = DllStructCreate($tagCRED_HANDLE) Local $tAttributes = DllStructCreate("dword") Local $tTimeStamp = DllStructCreate("dword;dword") DllStructSetData($tInBufferDesc, "ulVersion", 0) DllStructSetData($tInBufferDesc, "cBuffers", 1) DllStructSetData($tInBufferDesc, "pBuffers", DllStructGetPtr($tInBuffer)) DllStructSetData($tInBuffer, "BufferType", $SECBUFFER_EMPTY) DllStructSetData($tInBuffer, "cbBuffer", 0) DllStructSetData($tInBuffer, "pvBuffer", 0) DllStructSetData($tOutBufferDesc, "ulVersion", 0) DllStructSetData($tOutBufferDesc, "cBuffers", 1) DllStructSetData($tOutBufferDesc, "pBuffers", DllStructGetPtr($tOutBuffer)) DllStructSetData($tOutBuffer, "BufferType", $SECBUFFER_TOKEN) DllStructSetData($tOutBuffer, "cbBuffer", 0) DllStructSetData($tOutBuffer, "pvBuffer", 0) Local $dwFlags = BitOR($ISC_REQ_SEQUENCE_DETECT, $ISC_REQ_REPLAY_DETECT, _ $ISC_REQ_CONFIDENTIALITY, $ISC_REQ_ALLOCATE_MEMORY, $ISC_REQ_STREAM) Local $scRet = $SEC_I_CONTINUE_NEEDED Local $bFirstCall = True While $scRet = $SEC_I_CONTINUE_NEEDED Or $scRet = $SEC_E_INCOMPLETE_MESSAGE ConsoleWrite("Calling InitializeSecurityContext (" & ($bFirstCall ? "first" : "subsequent") & ")" & @CRLF) Local $aRet = DllCall("secur32.dll", "long", "InitializeSecurityContextW", _ "ptr", DllStructGetPtr($tCredHandle), _ "ptr", ($bFirstCall ? 0 : DllStructGetPtr($tCtxtNew)), _ "wstr", $sHost, _ "dword", $dwFlags, _ "dword", 0, _ "dword", 0, _ "ptr", ($bFirstCall ? 0 : DllStructGetPtr($tInBufferDesc)), _ "dword", 0, _ "ptr", DllStructGetPtr($tCtxtNew), _ "ptr", DllStructGetPtr($tOutBufferDesc), _ "ptr", DllStructGetPtr($tAttributes), _ "ptr", DllStructGetPtr($tTimeStamp)) If @error Then ConsoleWrite("DLL Call ERROR: " & @CRLF) Return False EndIf $scRet = $aRet[0] ConsoleWrite("hResult: " & Hex($scRet) & @CRLF) If $scRet = $SEC_E_OK Then ConsoleWrite("TLS connection successfully established!" & @CRLF) $tCtxtHandle = $tCtxtNew Return True ElseIf $scRet = $SEC_I_CONTINUE_NEEDED Or $scRet = $SEC_E_INCOMPLETE_MESSAGE Then If Not SendOutBuffer($tOutBuffer) Then Return False EndIf If Not ReceiveInputBuffer($tInBufferDesc, $tInBuffer) Then Return False EndIf If $bFirstCall Then $bFirstCall = False Else ConsoleWrite("Error InitializeSecurityContext: " & Hex($scRet) & @CRLF) Return False EndIf WEnd Return False EndFunc ;==>EstablishSecurityContext Func SendOutBuffer(ByRef $tBuffer) Local $cbBuffer = DllStructGetData($tBuffer, "cbBuffer") If $cbBuffer <= 0 Then Return True Local $pvBuffer = DllStructGetData($tBuffer, "pvBuffer") Local $tData = DllStructCreate("byte[" & $cbBuffer & "]", $pvBuffer) Local $bData = DllStructGetData($tData, 1) ConsoleWrite("Send " & $cbBuffer & " octets (hex): " & StringLeft($bData, 100) & "..." & @CRLF) ConsoleWrite("Send (text) : " & StringLeft(BinaryToString($bData), 50) & "..." & @CRLF) TCPSend($iSocket, $bData) If @error Then ConsoleWrite("Errorr TCPSend: " & @error & @CRLF) Return False EndIf DllCall("secur32.dll", "long", "FreeContextBuffer", "ptr", $pvBuffer) DllStructSetData($tBuffer, "pvBuffer", 0) DllStructSetData($tBuffer, "cbBuffer", 0) Return True EndFunc ;==>SendOutBuffer Func ReceiveInputBuffer(ByRef $tBufferDesc, ByRef $tBuffer) Local $bData = "" Local $iTimeout = TimerInit() While BinaryLen($bData) < 5 And TimerDiff($iTimeout) < 5000 $bData = TCPRecv($iSocket, 8192, 1) If @error Then ConsoleWrite("Error TCPRecv: " & @error & @CRLF) Return False EndIf If BinaryLen($bData) > 0 Then ExitLoop Sleep(10) WEnd Local $iLen = BinaryLen($bData) If $iLen = 0 Then ConsoleWrite("Error: No data received after timeout" & @CRLF) Return False EndIf ConsoleWrite("Received " & $iLen & " bytes (hex): " & StringLeft($bData, 50) & "..." & @CRLF) ConsoleWrite("Received (text): " & StringLeft(BinaryToString($bData), 50) & "..." & @CRLF) If BinaryMid($bData, 1, 1) = 0x15 And $iLen >= 7 Then Local $iVersion = Number(BinaryMid($bData, 2, 2)) Local $iLengthHi = Number(BinaryMid($bData, 4, 1)) Local $iLengthLo = Number(BinaryMid($bData, 5, 1)) Local $iLength = $iLengthHi * 256 + $iLengthLo Local $iLevel = Number(BinaryMid($bData, 6, 1)) Local $iDesc = Number(BinaryMid($bData, 7, 1)) ConsoleWrite("Alerte TLS détected: " & _ "Version=0x" & Hex($iVersion, 4) & ", " & _ "Length=" & $iLength & ", " & _ "Level=" & ($iLevel = 2 ? "Fatal" : "Warning") & ", " & _ "Description=" & $iDesc & " (" & GetAlertDescription($iDesc) & ")" & @CRLF) EndIf Local $tData = DllStructCreate("byte[" & $iLen & "]") DllStructSetData($tData, 1, $bData) DllStructSetData($tBuffer, "BufferType", $SECBUFFER_TOKEN) DllStructSetData($tBuffer, "cbBuffer", $iLen) DllStructSetData($tBuffer, "pvBuffer", DllStructGetPtr($tData)) Return True EndFunc ;==>ReceiveInputBuffer Func GetAlertDescription($iDesc) Switch $iDesc Case 0 Return "Close Notify" Case 10 Return "Unexpected Message" Case 40 Return "Handshake Failure" Case 70 Return "Protocol Version" Case 112 Return "Unrecognized Name" Case Else Return "Unknown Alert" EndSwitch EndFunc ;==>GetAlertDescription Func DisplayCertInfo() Local $tCertContextPtr = DllStructCreate("ptr") Local $aRet = DllCall("secur32.dll", "long", "QueryContextAttributesW", _ "ptr", DllStructGetPtr($tCtxtHandle), _ "dword", $SECPKG_ATTR_REMOTE_CERT_CONTEXT, _ "ptr", DllStructGetPtr($tCertContextPtr)) If @error Or $aRet[0] <> $SEC_E_OK Then ConsoleWrite("Error QueryContextAttributesW (cert): " & Hex($aRet[0]) & @CRLF) Return EndIf Local $pCertContext = DllStructGetData($tCertContextPtr, 1) If $pCertContext = 0 Then ConsoleWrite("Error: No certificate retrieved" & @CRLF) Return EndIf Local $tCertContext = DllStructCreate($tagCERT_CONTEXT, $pCertContext) Local $pCertInfo = DllStructGetData($tCertContext, "pCertInfo") Local $tCertInfo = DllStructCreate($tagCERT_INFO, $pCertInfo) Local $tConnInfo = DllStructCreate("struct;dword dwProtocol;dword aiCipher;dword dwCipherStrength;dword aiHash;dword dwHashStrength;dword aiExch;dword dwExchStrength;endstruct;") $aRet = DllCall("secur32.dll", "long", "QueryContextAttributesW", _ "ptr", DllStructGetPtr($tCtxtHandle), _ "dword", $SECPKG_ATTR_CONNECTION_INFO, _ "ptr", DllStructGetPtr($tConnInfo)) If @error Or $aRet[0] <> $SEC_E_OK Then ConsoleWrite("Error QueryContextAttributesW (conn): " & Hex($aRet[0]) & @CRLF) EndIf ConsoleWrite("🔒 SSL CERTIFICATE INFO" & @CRLF) ConsoleWrite("======================================" & @CRLF) ConsoleWrite("🏷️ Subject: " & GetCertNameString($pCertContext, False) & @CRLF) ConsoleWrite("🏛️ Issued by: " & GetCertNameString($pCertContext, True) & @CRLF) Local $tNotAfter = DllStructCreate($tagFILETIME) DllStructSetData($tNotAfter, "Lo", DllStructGetData($tCertInfo, "NotAfterLow")) DllStructSetData($tNotAfter, "Hi", DllStructGetData($tCertInfo, "NotAfterHigh")) Local $sExpiration = FileTimeToString($tNotAfter) ConsoleWrite("📅 Expiration: " & $sExpiration & @CRLF) Local $tNotBefore = DllStructCreate($tagFILETIME) DllStructSetData($tNotBefore, "Lo", DllStructGetData($tCertInfo, "NotBeforeLow")) DllStructSetData($tNotBefore, "Hi", DllStructGetData($tCertInfo, "NotBeforeHigh")) Local $sValidFrom = FileTimeToString($tNotBefore) ConsoleWrite("📅 Valid from: " & $sValidFrom & @CRLF) ConsoleWrite("ConnInfo: " & _ "Protocol=0x" & Hex(DllStructGetData($tConnInfo, "dwProtocol"), 4) & ", " & _ "Cipher=0x" & Hex(DllStructGetData($tConnInfo, "aiCipher"), 4) & ", " & _ "Strength=" & DllStructGetData($tConnInfo, "dwCipherStrength") & ", " & _ "Hash=0x" & Hex(DllStructGetData($tConnInfo, "aiHash"), 4) & ", " & _ "HashStrength=" & DllStructGetData($tConnInfo, "dwHashStrength") & ", " & _ "Exch=0x" & Hex(DllStructGetData($tConnInfo, "aiExch"), 4) & ", " & _ "ExchStrength=" & DllStructGetData($tConnInfo, "dwExchStrength") & @CRLF) Local $dwProtocol = DllStructGetData($tConnInfo, "dwProtocol") Local $sProtocol = GetProtocolName($dwProtocol) ConsoleWrite("🔒 SSL Protocol: " & $sProtocol & " (raw value: 0x" & Hex($dwProtocol, 4) & ")" & @CRLF) ConsoleWrite("CERT_INFO Data: Version=" & DllStructGetData($tCertInfo, "dwVersion") & ", pszObjId=" & DllStructGetData($tCertInfo, "pszObjId") & @CRLF) ConsoleWrite("🖊️ Signature Algorithm: " & GetSignatureAlgorithm($pCertInfo) & @CRLF) Local $sCipher = GetCipherName(DllStructGetData($tConnInfo, "aiCipher")) ConsoleWrite("🔑 Encryption Algorithm: " & $sCipher & @CRLF) Local $iCipherStrength = DllStructGetData($tConnInfo, "dwCipherStrength") ConsoleWrite("🛠️ Key Size: " & $iCipherStrength & " bits" & @CRLF) DllCall("crypt32.dll", "bool", "CertFreeCertificateContext", "ptr", $pCertContext) EndFunc ;==>DisplayCertInfo Func GetCertNameString($pCertContext, $bIssuer = False) Local Const $CERT_NAME_SIMPLE_DISPLAY_TYPE = 4 Local Const $CERT_NAME_ISSUER_FLAG = 0x1 Local $dwFlags = ($bIssuer ? $CERT_NAME_ISSUER_FLAG : 0) Local $aRet = DllCall("crypt32.dll", "dword", "CertGetNameStringW", _ "ptr", $pCertContext, _ "dword", $CERT_NAME_SIMPLE_DISPLAY_TYPE, _ "dword", $dwFlags, _ "ptr", 0, _ "wstr", 0, _ "dword", 0) If @error Then Return "Error DLL: " & @error EndIf Local $iLength = $aRet[0] If $iLength <= 1 Then Return "" EndIf Local $tBuffer = DllStructCreate("wchar[" & $iLength & "]") $aRet = DllCall("crypt32.dll", "dword", "CertGetNameStringW", _ "ptr", $pCertContext, _ "dword", $CERT_NAME_SIMPLE_DISPLAY_TYPE, _ "dword", $dwFlags, _ "ptr", 0, _ "ptr", DllStructGetPtr($tBuffer), _ "dword", $iLength) If @error Or $aRet[0] <= 1 Then Return "" EndIf Return DllStructGetData($tBuffer, 1) EndFunc ;==>GetCertNameString Func GetProtocolName($dwProtocol) Switch $dwProtocol Case 0x0080 Return "SSL 2.0" Case 0x0300 Return "SSL 3.0" Case 0x0301 Return "TLS 1.0" Case 0x0302 Return "TLS 1.1" Case 0x0800 Return "TLS 1.2" Case 0x1000 Return "TLS 1.3" Case Else Return "Inconnu (0x" & Hex($dwProtocol, 4) & ")" EndSwitch EndFunc ;==>GetProtocolName Func GetSignatureAlgorithm($pCertInfo) Local $tCertInfo = DllStructCreate($tagCERT_INFO, $pCertInfo) Local $pszObjId = DllStructGetData($tCertInfo, "pszObjId") ConsoleWrite("OID brut : " & $pszObjId & @CRLF) Switch $pszObjId Case "1.2.840.113549.1.1.11" Return "SHA256withRSA" Case "1.2.840.113549.1.1.12" Return "SHA384withRSA" Case "1.2.840.10045.4.3.2" Return "ECDSAwithSHA256" Case "1.2.840.10045.4.3.3" Return "ECDSAwithSHA384" Case Else Return "Inconnu (OID: " & $pszObjId & ")" EndSwitch EndFunc ;==>GetSignatureAlgorithm Func GetCipherName($aiCipher) Switch $aiCipher Case 0x0000660E Return "AES-128" Case 0x0000660F Return "AES-256" Case 0x00000002 Return "RC4" Case 0x00000005 Return "3DES" Case Else Return "Inconnu (0x" & Hex($aiCipher, 4) & ")" EndSwitch EndFunc ;==>GetCipherName Func Cleanup() If IsDllStruct($tCtxtHandle) Then DllCall("secur32.dll", "long", "DeleteSecurityContext", "ptr", DllStructGetPtr($tCtxtHandle)) $tCtxtHandle = 0 EndIf If IsDllStruct($tCredHandle) Then DllCall("secur32.dll", "long", "FreeCredentialsHandle", "ptr", DllStructGetPtr($tCredHandle)) $tCredHandle = 0 EndIf If $iSocket <> -1 Then TCPCloseSocket($iSocket) $iSocket = -1 EndIf TCPShutdown() EndFunc ;==>Cleanup Func FileTimeToString($tFileTime) Local $tSystemTime = DllStructCreate("word wYear;word wMonth;word wDayOfWeek;word wDay;word wHour;word wMinute;word wSecond;word wMilliseconds") Local $aRet = DllCall("kernel32.dll", "none", "FileTimeToSystemTime", _ "ptr", DllStructGetPtr($tFileTime), _ "ptr", DllStructGetPtr($tSystemTime)) If @error Or $aRet[0] <> 0 Then ConsoleWrite("Erreur FileTimeToSystemTime: " & @error & @CRLF) Return "Erreur" EndIf Return StringFormat("%04d/%02d/%02d %02d:%02d:%02d UTC", _ DllStructGetData($tSystemTime, "wYear"), _ DllStructGetData($tSystemTime, "wMonth"), _ DllStructGetData($tSystemTime, "wDay"), _ DllStructGetData($tSystemTime, "wHour"), _ DllStructGetData($tSystemTime, "wMinute"), _ DllStructGetData($tSystemTime, "wSecond")) EndFunc ;==>FileTimeToString ; Execution If InitializeTLS() Then ConsoleWrite("TLS connection successful!" & @CRLF) Sleep(300) DisplayCertInfo() Else ConsoleWrite("TLS connection failed" & @CRLF) EndIf Cleanup()1 point -
AutoIt Script for TLS Security Context Initialization (Schannel, Customizable)
Numeric1 reacted to argumentum for a topic
Oh, am just running this once. And doubt that it needs constant reties. But I'd like to replicate the from your post1 point -
I haven't touched AutoIt in over a year, so I'm a bit rusty. Here is an attempt to incorporate the Get/Set property into @trancexx ObjectFromTag code, similar to the AutoItObject UDF. Example 1: #include "ObjFromTag_v1a UDF.au3" Global $oError = ObjEvent("AutoIt.Error", "_ErrFunc") __Example1() Func __Example1() ConsoleWrite("> __Example4() " & @CRLF) Local $t_TestObj Local $o_TestObj = __ObjectFromTag("__MyInterface_", '', $t_TestObj, 'int Ln;char Msg[30];') __SetProperty($o_TestObj, "Ln", 555) __SetProperty($o_TestObj, "Msg", 'Is it working.') ConsoleWrite("+>>> Ln : " & __GetProperty($o_TestObj, "Ln") & @CRLF) ConsoleWrite("+>>> Msg : " & __GetProperty($o_TestObj, "Msg") & @CRLF) If IsObj($o_TestObj) Then $o_TestObj = 0 __DeleteObjectFromTag($t_TestObj) ConsoleWrite("----The End----" & @CRLF) EndFunc Func __MyInterface_QueryInterface($pSelf, $pRIID, $pObj) Return __QueryInterface($pSelf, $pRIID, $pObj) EndFunc Func __MyInterface_AddRef($pSelf) Return __AddRef($pSelf) EndFunc Func __MyInterface_Release($pSelf) Return __Release($pSelf) EndFunc Func _ErrFunc() ConsoleWrite("! COM Error ! Number: 0x" & Hex($oError.number, 8) & " ScriptLine: " & $oError.scriptline & " - " & $oError.windescription & @CRLF) Return EndFunc ;==>_ErrFunc Example 2: #include "ObjFromTag_v1a UDF.au3" Global $oError = ObjEvent("AutoIt.Error", "_ErrFunc") __Example2() Func __Example2() ConsoleWrite("> __Example2() " & @CRLF) Local $t_TestObj Local $o_TestObj = __ObjectFromTag("__MyInterface_", 'Open hresult();Close hresult();', $t_TestObj, 'handle WinHnd;', False) If Not IsObj($o_TestObj) Then Return $o_TestObj.Open() MsgBox(0, '', 'Clicked to closed Notepad....') $o_TestObj.Close() If IsObj($o_TestObj) Then $o_TestObj = 0 __DeleteObjectFromTag($t_TestObj) EndFunc Func __MyInterface_Open($pSelf) Run("notepad.exe") WinWait("[CLASS:Notepad]", "", 10) Local $hWnd = WinGetHandle("[CLASS:Notepad]") __SetProperty($pSelf, "WinHnd", $hWnd) Return 0 EndFunc Func __MyInterface_Close($pSelf) WinClose(__GetProperty($pSelf, "WinHnd")) Return 0 EndFunc Func _ErrFunc() ConsoleWrite("! COM Error ! Number: 0x" & Hex($oError.number, 8) & " ScriptLine: " & $oError.scriptline & " - " & $oError.windescription & @CRLF) Return EndFunc ;==>_ErrFunc Example 3: #include "ObjFromTag_v1a UDF.au3" Global $oError = ObjEvent("AutoIt.Error", "_ErrFunc") __Example3() Func __Example3() ConsoleWrite("> __Example3() " & @CRLF) Local $t_TestObj Local $o_TestObj = __ObjectFromTag("__MyInterface_", 'MsgBox hresult();', $t_TestObj, 'char Title[10];char Text[30];int Flag;', False) If Not IsObj($o_TestObj) Then Return __SetProperty($o_TestObj, "Title", "Something") __SetProperty($o_TestObj, "Text", 'Is it working.') __SetProperty($o_TestObj, "Flag", 64 + 262144) $o_TestObj.MsgBox() If IsObj($o_TestObj) Then $o_TestObj = 0 __DeleteObjectFromTag($t_TestObj) ConsoleWrite("----The End----" & @CRLF) EndFunc Func __MyInterface_MsgBox($pSelf) MsgBox(__GetProperty($pSelf, "Flag"), __GetProperty($pSelf, "Title"), __GetProperty($pSelf, "Text")) EndFunc Func _ErrFunc() ConsoleWrite("! COM Error ! Number: 0x" & Hex($oError.number, 8) & " ScriptLine: " & $oError.scriptline & " - " & $oError.windescription & @CRLF) Return EndFunc ;==>_ErrFunc Example 4: #include "ObjFromTag_v1a UDF.au3" Global $oError = ObjEvent("AutoIt.Error", "_ErrFunc") __Example3() Func __Example3() ConsoleWrite("> __Example3() " & @CRLF) Local $t_TestObj Local $o_TestObj = __ObjectFromTag("", 'DisplayBook str();', $t_TestObj, 'char book[50];char author[15];int year;', False) If Not IsObj($o_TestObj) Then Return __SetProperty($o_TestObj, "book", "Harry Potter and the Sorcerer's Stone") __SetProperty($o_TestObj, "author", 'J. K. Rowling') __SetProperty($o_TestObj, "year", 1997) MsgBox(0, 'Book', $o_TestObj.DisplayBook) If IsObj($o_TestObj) Then $o_TestObj = 0 __DeleteObjectFromTag($t_TestObj) ConsoleWrite("----The End----" & @CRLF) EndFunc Func DisplayBook($pSelf) Local $sString = 'The novel ' & __GetProperty($pSelf, "book") & ' ,' & _ ' written by author ' & __GetProperty($pSelf, "author") & _ ' and published in ' & __GetProperty($pSelf, "year") & '.' Local Static $tString = DllStructCreate(StringFormat("char str[%d]", StringLen($sString) + 1)) ;+1 to null terminate! $tString.str = $sString Return DllStructGetPtr($tString) EndFunc Func _ErrFunc() ConsoleWrite("! COM Error ! Number: 0x" & Hex($oError.number, 8) & " ScriptLine: " & $oError.scriptline & " - " & $oError.windescription & @CRLF) Return EndFunc ;==>_ErrFunc Example 5: #include "ObjFromTag_v1a UDF.au3" Global $oError = ObjEvent("AutoIt.Error", "_ErrFunc") __Example3() Func __Example3() ConsoleWrite("> __Example3() " & @CRLF) Local $t_BookObj, $t_AuthorObj Local $o_BookObj = __ObjectFromTag("", 'BookList hresult(bstr;bstr);', $t_BookObj, 'char book[50];int year;', False) Local $o_AuthorObj = __ObjectFromTag("", 'DisplayBook str(bstr);', $t_AuthorObj, 'char author[15];ptr oBook;', False) __SetProperty($o_AuthorObj, "oBook", $o_BookObj()) $o_BookObj.BookList("Harry Potter and the Sorcerer's Stone", 1997) MsgBox(0, 'Book', $o_AuthorObj.DisplayBook('J. K. Rowling')) If IsObj($o_AuthorObj) Then $o_AuthorObj = 0 If IsObj($o_BookObj) Then $o_BookObj = 0 __DeleteObjectFromTag($t_AuthorObj) __DeleteObjectFromTag($t_BookObj) ConsoleWrite("----The End----" & @CRLF) EndFunc Func BookList($pSelf, $pStrA, $pStrB) __SetProperty($pSelf, "book", __Bstr_ToString($pStrA)) __SetProperty($pSelf, "year", __Bstr_ToString($pStrB)) EndFunc Func DisplayBook($pSelf, $pStrA) __SetProperty($pSelf, "author", __Bstr_ToString($pStrA)) Local $pBookList = __GetProperty($pSelf, "oBook") Local $sString = 'The novel ' & __GetProperty($pBookList, "book") & ' ,' & _ ' written by author ' & __GetProperty($pSelf, "author") & _ ' and published in ' & __GetProperty($pBookList, "year") & '.' Local Static $tString = DllStructCreate(StringFormat("char str[%d]", StringLen($sString) + 1)) ;+1 to null terminate! $tString.str = $sString Return DllStructGetPtr($tString) EndFunc Func __Bstr_ToString($pString) Local $o_Data = DllStructGetData(DllStructCreate("wchar[" & _ DllStructGetData(DllStructCreate("dword", $pString - 4), 1) / 2 & "]", $pString), 1) Return $o_Data EndFunc Func _ErrFunc() ConsoleWrite("! COM Error ! Number: 0x" & Hex($oError.number, 8) & " ScriptLine: " & $oError.scriptline & " - " & $oError.windescription & @CRLF) Return EndFunc ;==>_ErrFunc for more about objectfromtag you can follow this thread created by @LarsJ https://www.autoitscript.com/forum/topic/205154-using-objcreateinterface-and-objectfromtag-functions/ and do check out code posted by @trancexx @ProgAndy @monoceres @wolf9228 @LarsJ @Danyfirex and @Bilgus. on this topic. Note: You can also register this object, created using __ObjectFromTag, within the Running Object Table (ROT). ObjFromTag_v1c.au31 point
-
Credit goes to @Numeric1 for his Ping Pong game using AutoItObject. @Gianni also converted the Ping Pong game using AutoItObject_Internal, coded by @genius257 Here’s my attempt using __ObjectFromTag. #include-once #AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <GDIPlus.au3> #include <Misc.au3> #include "ObjFromTag_v1c.au3" Global $g__flag = False Global $oErrorHandler = ObjEvent("AutoIt.Error", "_ErrFunc") _GDIPlus_Startup() Const $COLOR_RED = 0xFFFF0000 Const $COLOR_GREEN = 0xFF00FF00 GamePanel() Func GamePanel() Local $hGUI = GUICreate("Ping Pong", 400, 300, -1, -1, $WS_SIZEBOX + $WS_SYSMENU) GUISetBkColor(0x000000) GUISetState() Local $aClient = WinGetClientSize($hGUI) If @error Then Return SetError(1, 0, 0) Local $iWidth = $aClient[0] Local $iHeight = $aClient[1] Local $t_GamePanel Local $GamePanel_Property = 'int iWidth;int iHeight;ptr ball;ptr paddle;ptr map[5];int speedLevel;' Local $GamePanel_Method = 'move hresult();drawStage hresult();cleanUpResources hresult();runGameLoop hresult();' Local $c_GamePanel = __ObjectFromTag('_', $GamePanel_Method, $t_GamePanel, $GamePanel_Property, False) If Not IsObj($c_GamePanel) Then Return Local $t_Ball Local $Ball_Property = 'int dx;int dy;int size;int X;int Y;' Local $Ball_Method = 'move hresult();' Local $c_Ball = __ObjectFromTag('_', $Ball_Method, $t_Ball, $Ball_Property, False) If Not IsObj($c_Ball) Then Return Local $t_Paddle Local $Paddle_Property = 'int X;int size;int dx;' Local $Paddle_Method = 'moveLeft hresult();moveRight hresult(int);' Local $c_Paddle = __ObjectFromTag('_', $Paddle_Method, $t_Paddle, $Paddle_Property, False) If Not IsObj($c_Paddle) Then Return Local $aGDIMap[5] $aGDIMap[0] = _GDIPlus_GraphicsCreateFromHWND($hGUI) $aGDIMap[1] = _GDIPlus_BitmapCreateFromGraphics($iWidth, $iHeight, $aGDIMap[0]) $aGDIMap[2] = _GDIPlus_ImageGetGraphicsContext($aGDIMap[1]) $aGDIMap[3] = _GDIPlus_BrushCreateSolid($COLOR_RED) $aGDIMap[4] = _GDIPlus_HatchBrushCreate(4, $COLOR_GREEN) Ball($c_Ball, 40, 40) Paddle($c_Paddle, 150, 100) __SetProperty($c_GamePanel, 'iWidth', $iWidth) __SetProperty($c_GamePanel, 'iHeight', $iHeight) __SetProperty($c_GamePanel, 'ball', $c_Ball()) __SetProperty($c_GamePanel, 'paddle', $c_Paddle()) __SetProperty($c_GamePanel, 'speedLevel', 100) __SetProperty($c_GamePanel, "map", $aGDIMap[0], 1) __SetProperty($c_GamePanel, "map", $aGDIMap[1], 2) __SetProperty($c_GamePanel, "map", $aGDIMap[2], 3) __SetProperty($c_GamePanel, "map", $aGDIMap[3], 4) __SetProperty($c_GamePanel, "map", $aGDIMap[4], 5) $c_GamePanel.runGameLoop() $c_GamePanel.cleanUpResources() $c_Paddle = 0 $c_Ball = 0 $c_GamePanel = 0 __DeleteObjectFromTag($t_Paddle) __DeleteObjectFromTag($t_Ball) __DeleteObjectFromTag($t_GamePanel) ConsoleWrite("< The End >" & @CRLF) EndFunc Func Ball(Byref $oSelf, $x = 0, $y = 0, $size = 5) __SetProperty($oSelf, 'dx', 10) __SetProperty($oSelf, 'dy', -10) __SetProperty($oSelf, 'size', $size) __SetProperty($oSelf, 'X', $y) __SetProperty($oSelf, 'Y', $x) EndFunc Func Paddle(Byref $oSelf, $x = 0, $size = 5) __SetProperty($oSelf, 'X', $x) __SetProperty($oSelf, 'size', $size) __SetProperty($oSelf, 'dx', 20) EndFunc Func _moveLeft($this) Local $paddleX = __GetProperty($this, "X") Local $paddledx = __GetProperty($this, "dx") $paddleX -= $paddledx If $paddleX < 0 Then __SetProperty($this, 'X', 0) Else __SetProperty($this, 'X', $paddleX) Endif EndFunc ;==>_moveLeft Func _moveRight($this, $maxX) Local $paddleWidth = __GetProperty($this, "size") Local $paddleX = __GetProperty($this, "X") Local $paddledx = __GetProperty($this, "dx") If $paddleX + $paddledx + $paddleWidth <= $maxX Then $paddleX += $paddledx Else $paddleX = $maxX - $paddledx EndIf __SetProperty($this, 'X', $paddleX) EndFunc ;==>_moveRight Func _move($this) Local $pBall = __GetProperty($this, "ball") Local $pPaddle = __GetProperty($this, "paddle") Local $x = __GetProperty($pBall, "X") Local $y = __GetProperty($pBall, "Y") Local $dx = __GetProperty($pBall, "dx") Local $dy = __GetProperty($pBall, "dy") Local $BallSize = __GetProperty($pBall, "size") Local $Width = __GetProperty($this, "iWidth") Local $Height = __GetProperty($this, "iHeight") If $y + $dy >= ($Height - 40) And $x + $BallSize >= __GetProperty($pPaddle, "X") And $x <= __GetProperty($pPaddle, "X") + __GetProperty($pPaddle, "size") Then $dy *= -1 EndIf If $y + $dy <= 0 Then $dy = Abs($dy) EndIf If $y + $dy >= $Height - $BallSize Then MsgBox(0, "Game Over", "You missed the ball! Game Over!") $g__flag = True Return EndIf If $x + $dx <= 0 Then $dx = Abs($dx) EndIf If $x + $dx >= $Width - $BallSize Then $dx = -Abs($dx) EndIf $x += $dx $y += $dy __SetProperty($pBall, 'dx', $dx) __SetProperty($pBall, 'dy', $dy) __SetProperty($pBall, 'X', $x) __SetProperty($pBall, 'Y', $y) Local $GamePanel_Method = 'move hresult();drawStage hresult();cleanUpResources hresult();runGameLoop hresult();' Local $c__GamePanel = __RestoreObjectFromPtr($this, $GamePanel_Method, False, Default) $c__GamePanel.drawStage() EndFunc ;==>_move Func _drawStage($this) Local $hGraphics = __GetProperty($this, "map", 1) Local $hBitmap = __GetProperty($this, "map", 2) Local $hGraphicsCtxt = __GetProperty($this, "map", 3) Local $hBrush = __GetProperty($this, "map", 4) Local $hHatchBrush = __GetProperty($this, "map", 5) Local $pBall = __GetProperty($this, "ball") Local $pPaddle = __GetProperty($this, "paddle") Local $iX = __GetProperty($pBall, "X") Local $iY = __GetProperty($pBall, "Y") Local $iRadius = __GetProperty($pBall, "size") Local $padX = __GetProperty($pPaddle, "X") Local $padH = __GetProperty($this, "iHeight") - 40 _GDIPlus_GraphicsClear($hGraphicsCtxt, 0xFF000000) _GDIPlus_GraphicsFillEllipse($hGraphicsCtxt, $iX - $iRadius, $iY - $iRadius, $iRadius * 2, $iRadius * 2, $hBrush) _GDIPlus_GraphicsFillRect($hGraphicsCtxt, $padX, $padH, __GetProperty($pPaddle, "size"), 10, $hHatchBrush) _GDIPlus_GraphicsDrawImageRect($hGraphics, $hBitmap, 0, 0, __GetProperty($this, "iWidth"), __GetProperty($this, "iHeight")) EndFunc ;==>_drawStage Func _cleanUpResources($this) ConsoleWrite("clean up ressources...." & @CRLF) _GDIPlus_GraphicsDispose(__GetProperty($this, "map", 1)) _GDIPlus_BitmapDispose(__GetProperty($this, "map", 2)) _GDIPlus_GraphicsDispose(__GetProperty($this, "map", 3)) _GDIPlus_BrushDispose(__GetProperty($this, "map", 4)) _GDIPlus_Shutdown() EndFunc ;==>_cleanUpResources Func _runGameLoop($this) Local $speedUpTime = 5000 Local $lastMoveTime = TimerInit() Local $maxX = __GetProperty($this, "iWidth") Local $GamePanel_Method = 'move hresult();drawStage hresult();cleanUpResources hresult();runGameLoop hresult();' Local $c__GamePanel = __RestoreObjectFromPtr($this, $GamePanel_Method, False, Default) Local $pPaddle = __GetProperty($this, "paddle") Local $Paddle_Method = 'moveLeft hresult();moveRight hresult(int);' Local $c__Paddle = __RestoreObjectFromPtr($pPaddle, $Paddle_Method, False, Default) While 1 If GUIGetMsg() = $GUI_EVENT_CLOSE Then ExitLoop If _IsPressed(25) Then $c__Paddle.moveLeft() If _IsPressed(27) Then $c__Paddle.moveRight($maxX) If _IsPressed(53) Then While 1 If _IsPressed(25) Or _IsPressed(27) Then ExitLoop Sleep(100) WEnd EndIf If TimerDiff($lastMoveTime) >= $speedUpTime Then __SetProperty($this, 'speedLevel', __GetProperty($this, "speedLevel") - 5) If __GetProperty($this, "speedLevel") < 0 Then __SetProperty($this, 'speedLevel', 0) $lastMoveTime = TimerInit() EndIf $c__GamePanel.move() If $g__flag Then ExitLoop Sleep(__GetProperty($this, "speedLevel")) WEnd EndFunc ;==>_runGameLoop I also updated the __ObjectFromTag UDF (ver: 1c)1 point
-
DwmColorBlurMica
argumentum reacted to WildByDesign for a topic
I just updated the first post with version 1.0.2. I made some changes to the hooking logic so that it hooks earlier during process initialization. This made the overall hooking significantly faster and the occasional flicker with some apps is gone or at least greatly reduced. That may also depend on CPU speed, system load, etc. but overall a really nice improvement. I also made some changes to the border coloring function to make it more efficient and therefore benefit the performance of other areas of the program.1 point -
Make active transparent icon on image background
Davidyese reacted to argumentum for a topic
..this is quite something. For GUIs without combo or listviews, the whole GUI could be used like this 💯1 point -
1 point
-
_WinAPI_DwmEnableBlurBehindWindow in Windows 10
Parsix reacted to scintilla4evr for a topic
Hello! As some of you probably know, _WinAPI_DwmEnableBlurBehindWindow does not work as you'd like it to work in Windows 10. It doesn't add Aero-like blur, as seen in the new Start menu or Notification Center. I looked for a solution and found "the most elegant" one: The blur only affects the inside of the window and it is not colored. It can be enabled via an undocumented SetWindowCompositionAttribute function in user32.dll. _WinAPI_DwmEnableBlurBehindWindow for Windows 10 - this archive contains both the UDF and the example.1 point -
DwmColorBlurMica
argumentum reacted to WildByDesign for a topic
I've updated the first post with version 1.0.1. It might be the smallest update with the least amount of changes. However, it is by far the most significant to me. I was finally able to get the compiled x64 binary to avoid the False Positive from Windows Defender. I actually tried about a dozen different changes and none of them got rid of the false positive. The one single change that did get rid of the false positive: #AutoIt3Wrapper_Compression=0 That's it. That is all. I was so disappointed with the false positive on every single prior version, but now I am ecstatic. Now I have to get rid of the false positives on my 5 or 6 other AutoIt programs. I'm wondering if they should change the default compression level because of this.1 point -
You have to exclude the area of the icon off the bitmap (graphic). One example:1 point
-
1 point
-
DwmColorBlurMica
argumentum reacted to WildByDesign for a topic
Version 1.0.0 has been updated on the first post. After failing to figure out color tinted blur for weeks now, I have finally figured it out. Now you can have blur tinted with any color. There are global options for this and per-app / per-class options. So you can have as many apps as you want all with varying colors of tinted blur with varying intensities. And some with all of the other stuff too. I've been so busy building this thing that I haven't actually had much time to play with it. But I am imagining the crazy amount of possibilities right now.1 point -
WinRT Object Libraries
WildByDesign reacted to MattyD for a topic
Apologies for the late reply, I have been awol for a bit. Generally speaking, if the object name starts with windows.* then it'll be built into the OS. So we should have a decent chance of making these ones work. The Microsoft.* objects however are usually external. For these we'll probably need dependencies or a runtime in order to use them. So "Microsoft.UI.Content.DesktopChildSiteBridge" looks to be part of the Windows App SDK (And maybe WinUI3??). There will be associated *.winmd files in the SDK somewhere that contain object definitions. From these we should be able to wrap any object that we'll need in order to change colours etc.. But the tricky bit is how to implement the external objects/controls in the first place. Hope that makes sense. I will eventually get around to attacking this WinUI stuff - It'll just be whenever I have the time and energy to throw at it1 point -
I got it working (I think). Tested, both x86 and x64, it gives same results. I haven't put any error handling, as I wanted to see if it would work solely in AutoIt. #Region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_UseX64=y #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** #include <StructureConstants.au3> #include <WinAPIProc.au3> #include <Array.au3> #include <WinAPIFiles.au3> #include <APIErrorsConstants.au3> Global Const $SECURITY_DESCRIPTOR_REVISION = 1 Global $hEventBufferReady, $hEventDataReady, $hBuffer, $pDebugInfo, $bEnd HotKeySet("{ESC}", Terminate) Example() Func Example() Local $iPID, $sOutput StartDebugCapture() Do $sOutput = GetDebugOutput() If $sOutput Then $iPID = @extended ConsoleWrite($iPID & @CRLF & $sOutput & @CRLF) EndIf Sleep(100) Until $bEnd StopDebugCapture() EndFunc ;==>Example Func StartDebugCapture() Local $tSecurityDescriptor = DllStructCreate("byte;byte;word;ptr[4]") Local $tSecurityAttributes = DllStructCreate($tagSECURITY_ATTRIBUTES) $tSecurityAttributes.Length = DllStructGetSize($tSecurityAttributes) $tSecurityAttributes.Descriptor = DllStructGetPtr($tSecurityDescriptor) $tSecurityAttributes.InheritHandle = True Local $aCall = DllCall("advapi32.dll", "bool", "InitializeSecurityDescriptor", "struct*", $tSecurityDescriptor, "dword", $SECURITY_DESCRIPTOR_REVISION) $aCall = DllCall("advapi32.dll", "bool", "SetSecurityDescriptorDacl", "struct*", $tSecurityDescriptor, "bool", True, "ptr", 0, "bool", False) $hEventBufferReady = _WinAPI_CreateEvent($tSecurityAttributes, False, False, "DBWIN_BUFFER_READY") ;ConsoleWrite($hEventBufferReady & @CRLF) $hEventDataReady = _WinAPI_CreateEvent($tSecurityAttributes, False, False, "DBWIN_DATA_READY") ;ConsoleWrite($hEventDataReady & @CRLF) $hBuffer = _WinAPI_CreateFileMapping(-1, 4096, "DBWIN_BUFFER", $PAGE_READWRITE, $tSecurityAttributes) ;ConsoleWrite($hBuffer & @CRLF) $pDebugInfo = _WinAPI_MapViewOfFile($hBuffer, 0, 4096, $FILE_MAP_READ) ;ConsoleWrite($pDebugInfo & @CRLF) _WinAPI_SetEvent($hEventBufferReady) EndFunc ;==>StartDebugCapture Func StopDebugCapture() _WinAPI_CloseHandle($hEventBufferReady) _WinAPI_CloseHandle($hEventDataReady) _WinAPI_UnmapViewOfFile($pDebugInfo) _WinAPI_CloseHandle($hBuffer) EndFunc ;==>StopDebugCapture Func GetDebugOutput() If _WinAPI_WaitForSingleObject($hEventDataReady, 0) = $WAIT_TIMEOUT Then Return Local $tEvent = DllStructCreate("dword PID;char string[4092]", $pDebugInfo) _WinAPI_SetEvent($hEventBufferReady) Return SetExtended($tEvent.PID, $tEvent.string) EndFunc ;==>GetDebugOutput Func Terminate() $bEnd = True EndFunc ;==>Terminate1 point
-
@argumentum I hope you don't mind me doing something similar in parallel. I would like to test the code on different OS, need your support. It would make sense to have 2+ monitors, if possible with > 96 DPI. I don't know from which os it is possible to set different DPIs per monitor (WIn10+?). I tested it on Win11 22H2 and worked properly on 3 monitors with 3 different DPIs (left 100%, middle 125 % (main), right 150%). Just run the code and move the GUI over all your monitors. Theoretically the GUI should be adjusted accordingly. _WinAPI_DPI.au3: ;Coded by UEZ build 2023-08-15 beta #include-once #include <GDIPlus.au3> #include <Misc.au3> #include <WinAPISysWin.au3> #include <WinAPIsysinfoConstants.au3> #Region DPI Constants ;https://learn.microsoft.com/en-us/windows/win32/api/windef/ne-windef-dpi_awareness Global Enum $DPI_AWARENESS_INVALID = -1, $DPI_AWARENESS_UNAWARE = 0, $DPI_AWARENESS_SYSTEM_AWARE = 1, $DPI_AWARENESS_PER_MONITOR_AWARE = 2 ;https://learn.microsoft.com/en-us/windows/win32/hidpi/dpi-awareness-context Global Const $DPI_AWARENESS_CONTEXT_UNAWARE = $DPI_AWARENESS_UNAWARE - 1 Global Const $DPI_AWARENESS_CONTEXT_SYSTEM_AWARE = $DPI_AWARENESS_UNAWARE - 2 Global Const $DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE = $DPI_AWARENESS_UNAWARE - 3 Global Const $DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2 = $DPI_AWARENESS_UNAWARE - 4 Global Const $DPI_AWARENESS_CONTEXT_UNAWARE_GDISCALED = $DPI_AWARENESS_UNAWARE - 5 ; enum _MONITOR_DPI_TYPE Global Enum $MDT_EFFECTIVE_DPI = 0, $MDT_ANGULAR_DPI, $MDT_RAW_DPI Global Const $MDT_DEFAULT = $MDT_EFFECTIVE_DPI ;Windows Message Codes Global Const $WM_DPICHANGED = 0x02E0, $WM_DPICHANGED_BEFOREPARENT = 0x02E2, $WM_DPICHANGED_AFTERPARENT = 0x02E3, $WM_GETDPISCALEDSIZE = 0x02E4 #EndRegion DPI Constants #Region WinAPI DPI ;https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-adjustwindowrectexfordpi Func _WinAPI_AdjustWindowRectExForDpi($dpi, $dwStyle, $dwExStyle, $bMenu = False) Local $tRECT = DllStructCreate($tagRECT) Local $aResult = DllCall("user32.dll", "bool", "AdjustWindowRectExForDpi", "struct*", $tRECT, "dword", $dwStyle, "bool", $bMenu, "dword", $dwExStyle, "int", $dpi) ;requires Win10 v1607+ / no server support If Not IsArray($aResult) Or @error Then Return SetError(1, @extended, 0) If $aResult[0] Then Return SetError(2, @extended, 0) Return $tRECT EndFunc ;==>_WinAPI_AdjustWindowRectExForDpi ;https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-systemparametersinfofordpi Func _WinAPI_SystemParametersInfoForDpi($uiAction, $uiParam, $pvParam, $fWinIni, $dpi) Local $aResult = DllCall("user32.dll", "bool", "SystemParametersInfoForDpi", "uint", $uiAction, "uint", $uiParam, "struct*", $pvParam, "uint", $fWinIni, "uint", $dpi) ;requires Win10 v1607+ / no server support If Not IsArray($aResult) Or @error Then Return SetError(1, @extended, 0) If Not $aResult[0] Then Return SetError(2, @extended, 0) Return $aResult[0] EndFunc ;==>_WinAPI_SystemParametersInfoForDpi ;https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-inheritwindowmonitor Func _WinAPI_InheritWindowMonitor($hWnd, $hWndInherit) Local $aResult = DllCall("user32.dll", "bool", "InheritWindowMonitor", "hwnd", $hWnd, "hwnd", $hWndInherit) ;requires Win10 v1803+ / Windows Server 2016+ If Not IsArray($aResult) Or @error Then Return SetError(1, @extended, 0) If Not $aResult[0] Then Return SetError(2, @extended, 0) Return $aResult[0] EndFunc ;==>_WinAPI_InheritWindowMonitor ;https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-isvaliddpiawarenesscontext Func _WinAPI_IsValidDpiAwarenessContext($DPI_AWARENESS_CONTEXT_value) Local $aResult = DllCall("user32.dll", "bool", "IsValidDpiAwarenessContext", @AutoItX64 ? "int64" : "int", $DPI_AWARENESS_CONTEXT_value) ;requires Win10 v1607+ / no server support If Not IsArray($aResult) Or @error Then Return SetError(1, @extended, 0) If Not $aResult[0] Then Return SetError(2, @extended, 0) Return $aResult[0] EndFunc ;==>_WinAPI_IsValidDpiAwarenessContext ;https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-logicaltophysicalpointforpermonitordpi Func _WinAPI_LogicalToPhysicalPointForPerMonitorDPI($hWnd) Local $tPOINT = DllStructCreate($tagPOINT) Local $aResult = DllCall("user32.dll", "bool", "LogicalToPhysicalPointForPerMonitorDPI", "hwnd", $hWnd, "struct*", $tPOINT) ;requires Win 8.1+ / no server support If Not IsArray($aResult) Or @error Then Return SetError(1, @extended, 0) If Not $aResult[0] Then Return SetError(2, @extended, 0) Return $tPOINT EndFunc ;==>_WinAPI_LogicalToPhysicalPointForPerMonitorDPI ;https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-physicaltologicalpointforpermonitordpi Func _WinAPI_PhysicalToLogicalPointForPerMonitorDPI($hWnd) Local $tPOINT = DllStructCreate($tagPOINT) Local $aResult = DllCall("user32.dll", "bool", "PhysicalToLogicalPointForPerMonitorDPI", "hwnd", $hWnd, "struct*", $tPOINT) ;requires Win 8.1+ / no server support If Not IsArray($aResult) Or @error Then Return SetError(1, @extended, 0) If Not $aResult[0] Then Return SetError(2, @extended, 0) Return $tPOINT EndFunc ;==>_WinAPI_PhysicalToLogicalPointForPerMonitorDPI Func _GDIPlus_GetDPI($hGUI = 0) _GDIPlus_Startup() Local $hGfx = _GDIPlus_GraphicsCreateFromHWND($hGUI) If @error Then Return SetError(1, @extended, 0) Local $aResult = DllCall($__g_hGDIPDll, "int", "GdipGetDpiX", "handle", $hGfx, "float*", 0) If @error Then Return SetError(2, @extended, 0) _GDIPlus_GraphicsDispose($hGfx) _GDIPlus_Shutdown() Return $aResult[2] EndFunc ;==>_GDIPlus_GetDPI Func _WinAPI_GetDPI($hWnd = 0) $hWnd = Not $hWnd ? _WinAPI_GetDesktopWindow() : $hWnd Local Const $hDC = _WinAPI_GetDC($hWnd) If @error Then Return SetError(1, 0, 0) Local Const $iDPI = _WinAPI_GetDeviceCaps($hDC, $LOGPIXELSX) If @error Or Not $iDPI Then _WinAPI_ReleaseDC($hWnd, $hDC) Return SetError(2, 0, 0) EndIf _WinAPI_ReleaseDC($hWnd, $hDC) Return $iDPI EndFunc ;==>_WinAPI_GetDPI ;https://learn.microsoft.com/en-us/windows/win32/api/shellscalingapi/nf-shellscalingapi-getdpiformonitor Func _WinAPI_GetDpiForPrimaryMonitor($hMOnitor = 0, $dpiType = $MDT_DEFAULT) If $hMOnitor = 0 Then Local $aMonitors = _WinAPI_EnumDisplayMonitors() If @error Or Not IsArray($aMonitors) Then Return SetError(1, 0, 0) Local $i For $i = 1 To $aMonitors[0][0] If _WinAPI_GetMonitorInfo($aMonitors[$i][0])[2] = 1 Then $hMOnitor = $aMonitors[$i][0] ExitLoop EndIf Next EndIf Local $tx = DllStructCreate("int dpiX"), $tY = DllStructCreate("int dpiY") Local $aResult = DllCall("Shcore.dll", "long", "GetDpiForMonitor", "handle", $hMOnitor, "long", $dpiType, "struct*", $tx, "struct*", $tY) If @error Or Not IsArray($aResult) Then Return SetError(2, 0, 0) Return $tx.dpiX EndFunc ;==>_WinAPI_GetDpiForPrimaryMonitor ;https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-getdpiforwindow Func _WinAPI_GetDpiForWindow($hWnd) Local $aResult = DllCall("user32.dll", "uint", "GetDpiForWindow", "hwnd", $hWnd) ;requires Win10 v1607+ / no server support If Not IsArray($aResult) Or @error Then Return SetError(1, @extended, 0) If Not $aResult[0] Then Return SetError(2, @extended, 0) Return $aResult[0] EndFunc ;==>_WinAPI_GetDpiForWindow ;https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-getdpiforsystem Func _WinAPI_GetDpiForSystem() Local $aResult = DllCall("user32.dll", "uint", "GetDpiForSystem") ;requires Win10 v1607+ / no server support If Not IsArray($aResult) Or @error Then Return SetError(1, @extended, 0) If Not $aResult[0] Then Return SetError(2, @extended, 0) Return $aResult[0] EndFunc ;==>_WinAPI_GetDpiForSystem ;https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-getthreaddpiawarenesscontext Func _WinAPI_GetThreadDpiAwarenessContext() Local $aResult = DllCall("user32.dll", "uint", "GetThreadDpiAwarenessContext") ;requires Win10 v1607+ / no server support If Not IsArray($aResult) Or @error Then Return SetError(1, @extended, 0) If Not $aResult[0] Then Return SetError(2, @extended, 0) Return $aResult[0] EndFunc ;==>_WinAPI_GetThreadDpiAwarenessContext ;https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-getdpifromdpiawarenesscontext Func _WinAPI_GetDpiFromDpiAwarenessContext($DPI_AWARENESS_CONTEXT_value) Local $aResult = DllCall("user32.dll", "uint", "GetDpiFromDpiAwarenessContext", @AutoItX64 ? "int64" : "int", $DPI_AWARENESS_CONTEXT_value) ;requires Win10 v1803+ / Windows Server 2016+ If Not IsArray($aResult) Or @error Then Return SetError(1, @extended, 0) If Not $aResult[0] Then Return SetError(2, @extended, 0) Return $aResult[0] EndFunc ;==>_WinAPI_GetDpiFromDpiAwarenessContext ;https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-getawarenessfromdpiawarenesscontext Func _WinAPI_GetAwarenessFromDpiAwarenessContext($DPI_AWARENESS_CONTEXT_value) Local $aResult = DllCall("user32.dll", "uint", "GetAwarenessFromDpiAwarenessContext", @AutoItX64 ? "int64" : "int", $DPI_AWARENESS_CONTEXT_value) ;requires Win10 v1607+ / no server support If Not IsArray($aResult) Or @error Then Return SetError(1, @extended, 0) If Not $aResult[0] Then Return SetError(2, @extended, 0) Return $aResult[0] EndFunc ;==>_WinAPI_GetAwarenessFromDpiAwarenessContext ;https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-getdpiawarenesscontextforprocess Func _WinAPI_GetDpiAwarenessContextForProcess($hProcess) Local $aResult = DllCall("user32.dll", "uint", "GetDpiAwarenessContextForProcess", "handle", $hProcess) ;requires Win10 v1803+ / Windows Server 2016+ If Not IsArray($aResult) Or @error Then Return SetError(1, @extended, 0) If Not $aResult[0] Then Return SetError(2, @extended, 0) Return $aResult[0] EndFunc ;==>_WinAPI_GetDpiAwarenessContextForProcess ;https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-getsystemdpiforprocess Func _WinAPI_GetSystemDpiForProcess($hProcess) Local $aResult = DllCall("user32.dll", "uint", "GetSystemDpiForProcess", "handle", $hProcess) ;requires Win10 v1803+ / Windows Server 2016+ If Not IsArray($aResult) Or @error Then Return SetError(1, @extended, 0) If Not $aResult[0] Then Return SetError(2, @extended, 0) Return $aResult[0] EndFunc ;==>_WinAPI_GetSystemDpiForProcess ;https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-getwindowdpiawarenesscontext Func _WinAPI_GetWindowDpiAwarenessContext($hWnd) Local $aResult = DllCall("user32.dll", "uint", "GetWindowDpiAwarenessContext", "hwnd", $hWnd) ;requires Win10 v1607+ / no server support If Not IsArray($aResult) Or @error Then Return SetError(1, @extended, 0) If Not $aResult[0] Then Return SetError(2, @extended, 0) Return $aResult[0] EndFunc ;==>_WinAPI_GetWindowDpiAwarenessContext ;https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-setprocessdpiawarenesscontext Func _WinAPI_SetProcessDpiAwarenessContext($DPI_AWARENESS_CONTEXT_value) Local $aResult = DllCall("user32.dll", "bool", "SetProcessDpiAwarenessContext", @AutoItX64 ? "int64" : "int", $DPI_AWARENESS_CONTEXT_value) ;requires Win10 v1703+ / Windows Server 2016+ If Not IsArray($aResult) Or @error Then Return SetError(1, @extended, 0) If Not $aResult[0] Then Return SetError(2, @extended, 0) Return $aResult[0] EndFunc ;==>_WinAPI_SetProcessDpiAwarenessContext ;https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-setthreaddpiawarenesscontext Func _WinAPI_SetThreadDpiAwarenessContext($DPI_AWARENESS_CONTEXT_value) Local $aResult = DllCall("user32.dll", "uint", "SetThreadDpiAwarenessContext", @AutoItX64 ? "int64" : "int", $DPI_AWARENESS_CONTEXT_value) ;requires Win10 v1703+ / Windows Server 2016+ If Not IsArray($aResult) Or @error Then Return SetError(1, @extended, 0) If Not $aResult[0] Then Return SetError(2, @extended, 0) Return $aResult[0] EndFunc ;==>_WinAPI_SetThreadDpiAwarenessContext ;https://learn.microsoft.com/en-us/windows/win32/api/shellscalingapi/nf-shellscalingapi-setprocessdpiawareness Func _WinAPI_SetProcessDpiAwareness($PROCESS_DPI_AWARENESS = $DPI_AWARENESS_PER_MONITOR_AWARE) Local $aResult = DllCall("Shcore.dll", "long", "SetProcessDpiAwareness", "int", $PROCESS_DPI_AWARENESS) ;requires Win 8.1+ / Server 2012 R2+ If Not IsArray($aResult) Or @error Then Return SetError(1, @extended, 0) If $aResult[0] Then Return SetError(2, $aResult[0], 0) Return $aResult[0] ;0 is S_OK EndFunc ;==>_WinAPI_SetProcessDpiAwareness Func _WinAPI_SetDPIAwareness($DPIAwareContext = $DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE, $iMode = 1) Switch @OSBuild Case 6000 To 9199 Local $aResult = DllCall("user32.dll", "bool", "SetProcessDPIAware") ;requires Vista+ / Server 2008+ If Not $aResult[0] Then Return SetError(1, 0, 0) Case 9200 To 13999 $DPIAwareContext = ($DPIAwareContext < 0) ? 0 : ($DPIAwareContext > 2) ? 2 : $DPIAwareContext _WinAPI_SetProcessDpiAwareness($DPIAwareContext) If @error Then Return SetError(2, @error, 0) Case @OSBuild > 13999 $DPIAwareContext = ($DPIAwareContext < -5) ? -5 : ($DPIAwareContext > -1) ? -1 : $DPIAwareContext $iMode = ($iMode < 1) ? 1 : ($iMode > 2) ? 2 : $iMode Local $iResult Switch $iMode Case 1 $iResult = _WinAPI_SetProcessDpiAwarenessContext($DPIAwareContext) If Not $iResult Or @error Then Return SetError(3, 0, 0) Case 2 #cs Return DPI_AWARENESS_CONTEXT values $DPI_AWARENESS_CONTEXT_UNAWARE = 0x6010 / 24592 $DPI_AWARENESS_CONTEXT_SYSTEM_AWARE = 0x9011 / 36881 $DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE = 0x12 / 18 $DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2 = 0x22 / 34 $DPI_AWARENESS_CONTEXT_UNAWARE_GDISCALED = 0x40006010 / 1073766416 #ce $iResult = _WinAPI_SetThreadDpiAwarenessContext($DPIAwareContext) If Not $iResult Or @error Then Return SetError(4, 0, 0) EndSwitch EndSwitch Local $iDPI If @OSBuild < 9200 Then $iDPI = _WinAPI_GetDPI() If @error Or Not $iDPI Then Return SetError(5, 0, 0) Else $iDPI = _WinAPI_GetDpiForPrimaryMonitor() If @error Or Not $iDPI Then Return SetError(6, 0, 0) EndIf Return $iDPI EndFunc ;==>_WinAPI_SetDPIAwareness #EndRegion WinAPI DPI Example.au3: ; AutoIt GUI Example ; Created: 17/01/2005 - CyberSlug ; Modifed: 05/12/2011 - guinness ; Modifed: 09/06/2014 - mLipok ; Modifed: 15/10/2018 - mLipok ; Modifed: 14/08/2023 - UEZ #AutoIt3Wrapper_Change2CUI=n #AutoIt3Wrapper_Run_Au3Stripper=y #Au3Stripper_Parameters=/so #AutoIt3Wrapper_Res_HiDpi=n ;must be n otherwise _WinAPI_SetDPIAwareness() function will fail! #AutoIt3Wrapper_UseX64=n #Region INCLUDE #include <AVIConstants.au3> #include <GuiConstantsEx.au3> #include <TreeViewConstants.au3> #include <Array.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WinAPIGdiDC.au3> #include <WindowsConstants.au3> #include "_WinAPI_DPI.au3" #EndRegion INCLUDE #Region INITIALIZATION and EXIT Global $aCtrl[43][6], $ahWnd[2][10], $g_iDPI_ratio1, $g_iDPI_ratio2, $iw = 400, $ih = 200 _Example() ; Finished! #EndRegion INITIALIZATION and EXIT Func _Example() Local $AWARENESS Switch @OSBuild Case 9200 To 13999 $AWARENESS = $DPI_AWARENESS_PER_MONITOR_AWARE Case @OSBuild > 13999 $AWARENESS = $DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2 EndSwitch Local $iDPI = _WinAPI_SetDPIAwareness($AWARENESS, 2), $iDPI_def = 96 If $iDPI = 0 Then Exit MsgBox($MB_ICONERROR, "ERROR", "Unable to set DPI awareness!!!", 10) $g_iDPI_ratio1 = $iDPI / $iDPI_def $g_iDPI_ratio2 = $iDPI_def / $iDPI #Region GUI Local $sPath = RegRead("HKLM\SOFTWARE\" & (@AutoItX64 ? "WOW6432Node\" : "") & "AutoIt v3\AutoIt", "InstallDir") $sPath = ($sPath = "" ? @ProgramFilesDir & "\AutoIt3\" : $sPath & "\") ;assume default path $ahWnd[0][1] = 8.5 * $g_iDPI_ratio1 $ahWnd[0][0] = GUICreate("DPI Sample GUI", 400 * $g_iDPI_ratio1, 400 * $g_iDPI_ratio1) GUISetIcon(@SystemDir & "\mspaint.exe", 0) GUISetFont($ahWnd[0][1], 400, 0, "Arial", $ahWnd[0][0], $CLEARTYPE_QUALITY) #EndRegion GUI #Region MENU $aCtrl[1][0] = GUICtrlCreateMenu("Menu &One") $aCtrl[2][0] = GUICtrlCreateMenu("Menu &Two") $aCtrl[3][0] = GUICtrlCreateMenu("Menu Th&ree") $aCtrl[4][0] = GUICtrlCreateMenu("Menu &Four") GUICtrlCreateMenuItem('SubMenu One &A', $aCtrl[1][0]) GUICtrlCreateMenuItem('SubMenu One &B', $aCtrl[1][0]) #EndRegion MENU #Region CONTEXT MENU $aCtrl[5][0] = GUICtrlCreateContextMenu() GUICtrlCreateMenuItem("Context Menu", $aCtrl[5][0]) GUICtrlCreateMenuItem("", $aCtrl[5][0]) ; Separator GUICtrlCreateMenuItem("&Properties", $aCtrl[5][0]) #EndRegion CONTEXT MENU #Region PIC $aCtrl[6][2] = 0 ;x $aCtrl[6][3] = 0 ;y $aCtrl[6][4] = 169 ;w $aCtrl[6][5] = 68 ;h $aCtrl[6][0] = GUICtrlCreatePic($sPath & "Examples\GUI\logo4.gif", $aCtrl[6][2] * $g_iDPI_ratio1, $aCtrl[6][3] * $g_iDPI_ratio1, $aCtrl[6][4] * $g_iDPI_ratio1, $aCtrl[6][5] * $g_iDPI_ratio1) GUICtrlSetTip(-1, '#Region PIC') $aCtrl[7][2] = 75 $aCtrl[7][3] = 1 $aCtrl[7][4] = 80 $aCtrl[7][5] = 16 $aCtrl[7][1] = 8.5 * $g_iDPI_ratio2 $aCtrl[7][0] = GUICtrlCreateLabel("Sample Pic", $aCtrl[7][2] * $g_iDPI_ratio1, $aCtrl[7][3] * $g_iDPI_ratio1, $aCtrl[7][4] * $g_iDPI_ratio1, $aCtrl[7][5] * $g_iDPI_ratio1) GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT) GUICtrlSetColor(-1, 0xFFFFFF) GUICtrlSetFont(-1, $aCtrl[7][1] * $g_iDPI_ratio1) #EndRegion PIC #Region AVI $aCtrl[8][2] = 180 $aCtrl[8][3] = 10 $aCtrl[8][4] = 32 $aCtrl[8][5] = 32 $aCtrl[8][0] = GUICtrlCreateAvi($sPath & "Examples\GUI\SampleAVI.avi", 0, $aCtrl[8][2] * $g_iDPI_ratio1, $aCtrl[8][3] * $g_iDPI_ratio1, $aCtrl[8][4] * $g_iDPI_ratio1, $aCtrl[8][5] * $g_iDPI_ratio1, $ACS_AUTOPLAY) GUICtrlSetTip(-1, '#Region AVI') ; TODO $aCtrl[9][2] = 175 $aCtrl[9][3] = 50 $aCtrl[9][4] = 50 $aCtrl[9][5] = 12 $aCtrl[9][1] = 8.5 * $g_iDPI_ratio2 $aCtrl[9][0] = GUICtrlCreateLabel("Sample avi", $aCtrl[9][2] * $g_iDPI_ratio1, $aCtrl[9][3] * $g_iDPI_ratio1, $aCtrl[9][4] * $g_iDPI_ratio1, $aCtrl[9][5] * $g_iDPI_ratio1) GUICtrlSetTip(-1, '#Region AVI - Label') GUICtrlSetFont(-1, $aCtrl[9][1] * $g_iDPI_ratio1) #EndRegion AVI #Region TAB $aCtrl[10][2] = 240 $aCtrl[10][3] = 0 $aCtrl[10][4] = 150 $aCtrl[10][5] = 70 $aCtrl[10][1] = 8.5 * $g_iDPI_ratio2 $aCtrl[10][0] = GUICtrlCreateTab($aCtrl[10][2] * $g_iDPI_ratio1, $aCtrl[10][3] * $g_iDPI_ratio1, $aCtrl[10][4] * $g_iDPI_ratio1, $aCtrl[10][5] * $g_iDPI_ratio1) GUICtrlSetFont(-1, $aCtrl[10][1] * $g_iDPI_ratio1) $aCtrl[11][0] = GUICtrlCreateTabItem("One") GUICtrlSetTip(-1, '#Region TAB1') $aCtrl[12][2] = 244 $aCtrl[12][3] = 35 $aCtrl[12][4] = 140 $aCtrl[12][5] = 24 $aCtrl[12][1] = 8.5 * $g_iDPI_ratio2 $aCtrl[12][0] = GUICtrlCreateLabel("Sample Tab with TabItems", $aCtrl[12][2] * $g_iDPI_ratio1, $aCtrl[12][3] * $g_iDPI_ratio1, $aCtrl[12][4] * $g_iDPI_ratio1, $aCtrl[12][5] * $g_iDPI_ratio1) GUICtrlSetFont(-1, $aCtrl[12][1] * $g_iDPI_ratio1) $aCtrl[13][0] = GUICtrlCreateTabItem("Two") GUICtrlSetTip(-1, '#Region TAB2') $aCtrl[14][0] = GUICtrlCreateTabItem("Three") GUICtrlSetTip(-1, '#Region TAB3') GUICtrlCreateTabItem("") #EndRegion TAB #Region COMBO $aCtrl[15][2] = 250 $aCtrl[15][3] = 80 $aCtrl[15][4] = 120 $aCtrl[15][5] = 100 $aCtrl[15][1] = 8.5 * $g_iDPI_ratio2 $aCtrl[15][0] = GUICtrlCreateCombo("Sample Combo", $aCtrl[15][2] * $g_iDPI_ratio1, $aCtrl[15][3] * $g_iDPI_ratio1, $aCtrl[15][4] * $g_iDPI_ratio1, $aCtrl[15][5] * $g_iDPI_ratio1) GUICtrlSetTip(-1, '#Region COMBO') GUICtrlSetFont(-1, $aCtrl[15][1] * $g_iDPI_ratio1) #EndRegion COMBO #Region PROGRESS $aCtrl[16][2] = 60 $aCtrl[16][3] = 80 $aCtrl[16][4] = 150 $aCtrl[16][5] = 20 $aCtrl[16][0] = GUICtrlCreateProgress($aCtrl[16][2] * $g_iDPI_ratio1, $aCtrl[16][3] * $g_iDPI_ratio1, $aCtrl[16][4] * $g_iDPI_ratio1, $aCtrl[16][5] * $g_iDPI_ratio1) GUICtrlSetTip(-1, '#Region PROGRES') GUICtrlSetData(-1, 60) $aCtrl[17][2] = 5 $aCtrl[17][3] = 82 $aCtrl[17][4] = 50 $aCtrl[17][5] = 18 $aCtrl[17][1] = 8.5 * $g_iDPI_ratio2 $aCtrl[17][0] = GUICtrlCreateLabel("Progress:", $aCtrl[17][2] * $g_iDPI_ratio1, $aCtrl[17][3] * $g_iDPI_ratio1, $aCtrl[17][4] * $g_iDPI_ratio1, $aCtrl[17][5] * $g_iDPI_ratio1) GUICtrlSetTip(-1, '#Region PROGRES - Label') GUICtrlSetFont(-1, $aCtrl[17][1] * $g_iDPI_ratio1) #EndRegion PROGRESS #Region EDIT $aCtrl[18][2] = 10 $aCtrl[18][3] = 110 $aCtrl[18][4] = 150 $aCtrl[18][5] = 70 $aCtrl[18][1] = 8.5 * $g_iDPI_ratio2 $aCtrl[18][0] = GUICtrlCreateEdit(@CRLF & " Sample Edit Control", $aCtrl[18][2] * $g_iDPI_ratio1, $aCtrl[18][3] * $g_iDPI_ratio1, $aCtrl[18][4] * $g_iDPI_ratio1, $aCtrl[18][5] * $g_iDPI_ratio1) GUICtrlSetTip(-1, '#Region EDIT') GUICtrlSetFont(-1, $aCtrl[18][1] * $g_iDPI_ratio1) #EndRegion EDIT #Region LIST $aCtrl[19][2] = 5 $aCtrl[19][3] = 190 $aCtrl[19][4] = 100 $aCtrl[19][5] = 90 $aCtrl[19][1] = 8.5 * $g_iDPI_ratio2 $aCtrl[19][0] = GUICtrlCreateList("", $aCtrl[19][2] * $g_iDPI_ratio1, $aCtrl[19][3] * $g_iDPI_ratio1, $aCtrl[19][4] * $g_iDPI_ratio1, $aCtrl[19][5] * $g_iDPI_ratio1) GUICtrlSetFont(-1, $aCtrl[19][1] * $g_iDPI_ratio1) GUICtrlSetTip(-1, '#Region LIST') GUICtrlSetData(-1, "A.Sample|B.List|C.Control|D.Here", "B.List") #EndRegion LIST #Region ICON $aCtrl[20][2] = 175 $aCtrl[20][3] = 120 $aCtrl[20][4] = 32 $aCtrl[20][5] = 32 $aCtrl[20][0] = GUICtrlCreateIcon("explorer.exe", 0, $aCtrl[20][2] * $g_iDPI_ratio1, $aCtrl[20][3] * $g_iDPI_ratio1, $aCtrl[20][4] * $g_iDPI_ratio1, $aCtrl[20][5] * $g_iDPI_ratio1) GUICtrlSetTip(-1, '#Region ICON') $aCtrl[21][2] = 180 $aCtrl[21][3] = 160 $aCtrl[21][4] = 50 $aCtrl[21][5] = 20 $aCtrl[21][1] = 8.5 * $g_iDPI_ratio2 $aCtrl[21][0] = GUICtrlCreateLabel("Icon", $aCtrl[21][2] * $g_iDPI_ratio1, $aCtrl[21][3] * $g_iDPI_ratio1, $aCtrl[21][4] * $g_iDPI_ratio1, $aCtrl[21][5] * $g_iDPI_ratio1) GUICtrlSetTip(-1, '#Region ICON - Label') GUICtrlSetFont(-1, $aCtrl[21][1] * $g_iDPI_ratio1) #EndRegion ICON #Region LIST VIEW $aCtrl[22][2] = 110 $aCtrl[22][3] = 190 $aCtrl[22][4] = 110 $aCtrl[22][5] = 80 $aCtrl[22][1] = 8.5 * $g_iDPI_ratio2 $aCtrl[22][0] = GUICtrlCreateListView("Sample|ListView|", $aCtrl[22][2] * $g_iDPI_ratio1, $aCtrl[22][3] * $g_iDPI_ratio1, $aCtrl[22][4] * $g_iDPI_ratio1, $aCtrl[22][5] * $g_iDPI_ratio1) GUICtrlSetTip(-1, '#Region LIST VIEW') GUICtrlSetFont(-1, $aCtrl[22][1] * $g_iDPI_ratio1) GUICtrlCreateListViewItem("A|One", $aCtrl[22][0]) GUICtrlCreateListViewItem("B|Two", $aCtrl[22][0]) GUICtrlCreateListViewItem("C|Three", $aCtrl[22][0]) #EndRegion LIST VIEW #Region GROUP WITH RADIO BUTTONS $aCtrl[23][2] = 230 $aCtrl[23][3] = 120 $aCtrl[23][4] = 110 $aCtrl[23][5] = 80 $aCtrl[23][1] = 8.5 * $g_iDPI_ratio2 $aCtrl[23][0] = GUICtrlCreateGroup("Sample Group", $aCtrl[23][2] * $g_iDPI_ratio1, $aCtrl[23][3] * $g_iDPI_ratio1, $aCtrl[23][4] * $g_iDPI_ratio1, $aCtrl[23][5] * $g_iDPI_ratio1) GUICtrlSetFont(-1, $aCtrl[22][1] * $g_iDPI_ratio1) $aCtrl[24][2] = 250 $aCtrl[24][3] = 140 $aCtrl[24][4] = 80 $aCtrl[24][5] = 32 $aCtrl[24][1] = 8.5 * $g_iDPI_ratio2 $aCtrl[24][0] = GUICtrlCreateRadio("Radio One", $aCtrl[24][2] * $g_iDPI_ratio1, $aCtrl[24][3] * $g_iDPI_ratio1, $aCtrl[24][4] * $g_iDPI_ratio1, $aCtrl[24][5] * $g_iDPI_ratio1) GUICtrlSetTip(-1, '#Region GROUP WITH RADIO BUTTONS- RADIO1') GUICtrlSetFont(-1, $aCtrl[24][1] * $g_iDPI_ratio1) GUICtrlSetState(-1, $GUI_CHECKED) $aCtrl[25][2] = 250 $aCtrl[25][3] = 165 $aCtrl[25][4] = 80 $aCtrl[25][5] = 32 $aCtrl[25][1] = 8.5 * $g_iDPI_ratio2 $aCtrl[25][0] = GUICtrlCreateRadio("Radio Two", $aCtrl[25][2] * $g_iDPI_ratio1, $aCtrl[25][3] * $g_iDPI_ratio1, $aCtrl[25][4] * $g_iDPI_ratio1, $aCtrl[25][5] * $g_iDPI_ratio1) GUICtrlSetTip(-1, '#Region GROUP WITH RADIO BUTTONS- RADIO2') GUICtrlSetFont(-1, $aCtrl[25][1] * $g_iDPI_ratio1) GUICtrlCreateGroup("", -99, -99, 1, 1) ;close group #EndRegion GROUP WITH RADIO BUTTONS #Region UPDOWN $aCtrl[26][2] = 350 $aCtrl[26][3] = 113 $aCtrl[26][4] = 40 $aCtrl[26][5] = 12 $aCtrl[26][1] = 8 * $g_iDPI_ratio2 $aCtrl[26][0] = GUICtrlCreateLabel("UpDown", $aCtrl[26][2] * $g_iDPI_ratio1, $aCtrl[26][3] * $g_iDPI_ratio1, $aCtrl[26][4] * $g_iDPI_ratio1, $aCtrl[26][5] * $g_iDPI_ratio1) GUICtrlSetTip(-1, '#Region UPDOWN - Label') GUICtrlSetFont(-1, $aCtrl[26][1] * $g_iDPI_ratio1) $aCtrl[27][2] = 350 $aCtrl[27][3] = 130 $aCtrl[27][4] = 40 $aCtrl[27][5] = 20 $aCtrl[27][1] = 8.5 * $g_iDPI_ratio2 $aCtrl[27][0] = GUICtrlCreateInput("42", $aCtrl[27][2] * $g_iDPI_ratio1, $aCtrl[27][3] * $g_iDPI_ratio1, $aCtrl[27][4] * $g_iDPI_ratio1, $aCtrl[27][5] * $g_iDPI_ratio1) GUICtrlSetTip(-1, '#Region UPDOWN - Input') GUICtrlSetFont(-1, $aCtrl[27][1] * $g_iDPI_ratio1) $aCtrl[28][0] = GUICtrlCreateUpdown(-1) GUICtrlSetTip(-1, '#Region UPDOWN - Updown') #EndRegion UPDOWN #Region LABEL $aCtrl[29][2] = 350 $aCtrl[29][3] = 165 $aCtrl[29][4] = 40 $aCtrl[29][5] = 40 $aCtrl[29][1] = 8.5 * $g_iDPI_ratio2 $aCtrl[29][0] = GUICtrlCreateLabel("Green" & @CRLF & "Label", $aCtrl[29][2] * $g_iDPI_ratio1, $aCtrl[29][3] * $g_iDPI_ratio1, $aCtrl[29][4] * $g_iDPI_ratio1, $aCtrl[29][5] * $g_iDPI_ratio1) GUICtrlSetTip(-1, '#Region LABEL') GUICtrlSetBkColor(-1, 0x00FF00) GUICtrlSetFont(-1, $aCtrl[29][1] * $g_iDPI_ratio1) #EndRegion LABEL #Region SLIDER $aCtrl[30][2] = 235 $aCtrl[30][3] = 215 $aCtrl[30][4] = 40 $aCtrl[30][5] = 16 $aCtrl[30][1] = 8.5 * $g_iDPI_ratio2 $aCtrl[30][0] = GUICtrlCreateLabel("Slider:", $aCtrl[30][2] * $g_iDPI_ratio1, $aCtrl[30][3] * $g_iDPI_ratio1, $aCtrl[30][4] * $g_iDPI_ratio1, $aCtrl[30][5] * $g_iDPI_ratio1) GUICtrlSetTip(-1, '#Region SLIDER - Label') GUICtrlSetFont(-1, $aCtrl[30][1] * $g_iDPI_ratio1) $aCtrl[31][2] = 270 $aCtrl[31][3] = 210 $aCtrl[31][4] = 120 $aCtrl[31][5] = 30 $aCtrl[31][0] = GUICtrlCreateSlider($aCtrl[31][2] * $g_iDPI_ratio1, $aCtrl[31][3] * $g_iDPI_ratio1, $aCtrl[31][4] * $g_iDPI_ratio1, $aCtrl[31][5] * $g_iDPI_ratio1) GUICtrlSetTip(-1, '#Region SLIDER') GUICtrlSetData(-1, 30) #EndRegion SLIDER #Region INPUT $aCtrl[32][2] = 235 $aCtrl[32][3] = 255 $aCtrl[32][4] = 130 $aCtrl[32][5] = 20 $aCtrl[32][1] = 8.5 * $g_iDPI_ratio2 $aCtrl[32][0] = GUICtrlCreateInput("Sample Input Box", $aCtrl[32][2] * $g_iDPI_ratio1, $aCtrl[32][3] * $g_iDPI_ratio1, $aCtrl[32][4] * $g_iDPI_ratio1, $aCtrl[32][5] * $g_iDPI_ratio1) GUICtrlSetTip(-1, '#Region INPUT') GUICtrlSetFont(-1, $aCtrl[32][1] * $g_iDPI_ratio1) #EndRegion INPUT #Region DATE $aCtrl[33][2] = 5 $aCtrl[33][3] = 280 $aCtrl[33][4] = 200 $aCtrl[33][5] = 20 $aCtrl[33][1] = 8.5 * $g_iDPI_ratio2 $aCtrl[33][0] = GUICtrlCreateDate("", $aCtrl[33][2] * $g_iDPI_ratio1, $aCtrl[33][3] * $g_iDPI_ratio1, $aCtrl[33][4] * $g_iDPI_ratio1, $aCtrl[33][5] * $g_iDPI_ratio1) GUICtrlSetTip(-1, '#Region DATE') GUICtrlSetFont(-1, $aCtrl[33][1] * $g_iDPI_ratio1) $aCtrl[34][1] = 8.5 * $g_iDPI_ratio2 $aCtrl[34][2] = 10 $aCtrl[34][3] = 305 $aCtrl[34][4] = 200 $aCtrl[34][5] = 20 $aCtrl[34][0] = GUICtrlCreateLabel("(Date control expands into a calendar)", $aCtrl[34][2] * $g_iDPI_ratio1, $aCtrl[34][3] * $g_iDPI_ratio1, $aCtrl[34][4] * $g_iDPI_ratio1, $aCtrl[34][5] * $g_iDPI_ratio1) GUICtrlSetTip(-1, '#Region DATE - Label') GUICtrlSetFont(-1, $aCtrl[34][1] * $g_iDPI_ratio1) #EndRegion DATE #Region BUTTON $aCtrl[35][2] = 10 $aCtrl[35][3] = 330 $aCtrl[35][4] = 100 $aCtrl[35][5] = 30 $aCtrl[35][1] = 8.5 * $g_iDPI_ratio2 $aCtrl[35][0] = GUICtrlCreateButton("Click me :-)", $aCtrl[35][2] * $g_iDPI_ratio1, $aCtrl[35][3] * $g_iDPI_ratio1, $aCtrl[35][4] * $g_iDPI_ratio1, $aCtrl[35][5] * $g_iDPI_ratio1) GUICtrlSetTip(-1, '#Region BUTTON') GUICtrlSetFont(-1, $aCtrl[35][1] * $g_iDPI_ratio1) #EndRegion BUTTON #Region CHECKBOX $aCtrl[36][2] = 130 $aCtrl[36][3] = 335 $aCtrl[36][4] = 80 $aCtrl[36][5] = 20 $aCtrl[36][1] = 8.5 * $g_iDPI_ratio2 $aCtrl[36][0] = GUICtrlCreateCheckbox("Checkbox", $aCtrl[36][2] * $g_iDPI_ratio1, $aCtrl[36][3] * $g_iDPI_ratio1, $aCtrl[36][4] * $g_iDPI_ratio1, $aCtrl[36][5] * $g_iDPI_ratio1) GUICtrlSetTip(-1, '#Region CHECKBOX') GUICtrlSetState(-1, $GUI_CHECKED) GUICtrlSetFont(-1, $aCtrl[36][1] * $g_iDPI_ratio1) #EndRegion CHECKBOX #Region TREEVIEW ONE $aCtrl[37][2] = 210 $aCtrl[37][3] = 290 $aCtrl[37][4] = 80 $aCtrl[37][5] = 80 $aCtrl[37][1] = 8.5 * $g_iDPI_ratio2 $aCtrl[37][0] = GUICtrlCreateTreeView($aCtrl[37][2] * $g_iDPI_ratio1, $aCtrl[37][3] * $g_iDPI_ratio1, $aCtrl[37][4] * $g_iDPI_ratio1, $aCtrl[37][5] * $g_iDPI_ratio1) GUICtrlSetTip(-1, '#Region TREEVIEW ONE') GUICtrlSetFont(-1, $aCtrl[37][1] * $g_iDPI_ratio1) $aCtrl[38][0] = GUICtrlCreateTreeViewItem("TreeView", $aCtrl[37][0]) GUICtrlCreateTreeViewItem("Item1", $aCtrl[38][0]) GUICtrlCreateTreeViewItem("Item2", $aCtrl[38][0]) GUICtrlCreateTreeViewItem("Foo", -1) GUICtrlSetState($aCtrl[38][0], $GUI_EXPAND) #EndRegion TREEVIEW ONE #Region TREEVIEW TWO $aCtrl[39][2] = 295 $aCtrl[39][3] = 290 $aCtrl[39][4] = 103 $aCtrl[39][5] = 80 $aCtrl[39][1] = 8.5 * $g_iDPI_ratio2 $aCtrl[39][0] = GUICtrlCreateTreeView($aCtrl[39][2] * $g_iDPI_ratio1, $aCtrl[39][3] * $g_iDPI_ratio1, $aCtrl[39][4] * $g_iDPI_ratio1, $aCtrl[39][5] * $g_iDPI_ratio1, $TVS_CHECKBOXES) GUICtrlSetTip(-1, '#Region TREEVIEW TWO') GUICtrlSetFont(-1, $aCtrl[39][1] * $g_iDPI_ratio1) GUICtrlCreateTreeViewItem("TreeView", $aCtrl[39][0]) GUICtrlCreateTreeViewItem("With", $aCtrl[39][0]) GUICtrlCreateTreeViewItem("$TVS_CHECKBOXES", $aCtrl[39][0]) GUICtrlSetState(-1, $GUI_CHECKED) GUICtrlCreateTreeViewItem("Style", $aCtrl[39][0]) #EndRegion TREEVIEW TWO #Region GUI MESSAGE LOOP GUISetState(@SW_SHOW) If @OSBuild > 9599 Then GUIRegisterMsg($WM_DPICHANGED, "WM_DPICHANGED") ;requires Win 8.1+ / Server 2012 R2+ GUIRegisterMsg($WM_GETMINMAXINFO, "WM_GETMINMAXINFO") GUIRegisterMsg($WM_SIZE, "WM_SIZE") Local $hGUI_child, $hImage, $hGDIBitmap, $hGfx, $hPath, $hFamily, $hFormat, $tLayout, $hPen, $hBrush, $hB, $aGUIGetMsg _GDIPlus_Startup() While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE _GDIPlus_PathDispose($hPath) _GDIPlus_PenDispose($hPen) _GDIPlus_BrushDispose($hBrush) _GDIPlus_FontFamilyDispose($hFamily) _GDIPlus_StringFormatDispose($hFormat) _GDIPlus_ImageDispose ($hImage) _GDIPlus_GraphicsDispose($hGfx) _GDIPlus_Shutdown() GUIRegisterMsg($WM_DPICHANGED, "") GUIRegisterMsg(WM_GETMINMAXINFO, "") GUIRegisterMsg(WM_SIZE, "") GUIDelete() Exit Case $aCtrl[35][0] If $hImage Then $hImage = _GDIPlus_ImageDispose($hImage) $hImage = _GDIPlus_BitmapCreateFromScan0($iw * $g_iDPI_ratio1, $ih * $g_iDPI_ratio1) If $hGfx Then _GDIPlus_GraphicsDispose($hGfx) $hGfx = _GDIPlus_ImageGetGraphicsContext($hImage) _GDIPlus_GraphicsSetTextRenderingHint($hGfx, $GDIP_TEXTRENDERINGHINTANTIALIAS) _GDIPlus_GraphicsSetSmoothingMode($hGfx, $GDIP_SMOOTHINGMODE_HIGHQUALITY) _GDIPlus_GraphicsClear($hGfx, 0xFFF0F0F0) If $hPath Then _GDIPlus_PathDispose($hPath) $hPath = _GDIPlus_PathCreate() If $hFamily Then _GDIPlus_FontFamilyDispose($hFamily) $hFamily = _GDIPlus_FontFamilyCreate("Arial") If $hFormat Then _GDIPlus_StringFormatDispose($hFormat) $hFormat = _GDIPlus_StringFormatCreate() _GDIPlus_StringFormatSetAlign($hFormat, 1) _GDIPlus_StringFormatSetLineAlign($hFormat, 1) $tLayout = _GDIPlus_RectFCreate(0, 0, $iw * $g_iDPI_ratio1, $ih * $g_iDPI_ratio1) _GDIPlus_PathAddString($hPath, "Hello World!", $tLayout, $hFamily, 0, 50 * $g_iDPI_ratio1, $hFormat) If $hPen Then _GDIPlus_PenDispose($hPen) $hPen = _GDIPlus_PenCreate(0xFF000000, 8) _GDIPlus_PenSetLineJoin($hPen, 2) _GDIPlus_GraphicsDrawPath($hGfx, $hPath, $hPen) If $hBrush Then _GDIPlus_BrushDispose($hBrush) $hBrush = _GDIPlus_BrushCreateSolid(0xFF00FF00) _GDIPlus_GraphicsFillPath($hGfx, $hPath, $hBrush) If $hGDIBitmap Then _WinAPI_DeleteObject($hGDIBitmap) $hGDIBitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hImage) Local $aGUI_Pos = WinGetPos($ahWnd[0][0]) $ahWnd[1][0] = GUICreate("GDI+ Child Window", $iw * $g_iDPI_ratio1, $ih * $g_iDPI_ratio1, $aGUI_Pos[0] - ($aGUI_Pos[2] - $iw * $g_iDPI_ratio1) / 2, $aGUI_Pos[1] + $ih * $g_iDPI_ratio1 / 2, $WS_SIZEBOX, -1, $ahWnd[0][0]) $aCtrl[40][2] = 0 $aCtrl[40][3] = 0 $aCtrl[40][4] = $iw $aCtrl[40][5] = $ih $aCtrl[40][0] = GUICtrlCreatePic("", $aCtrl[40][2], $aCtrl[40][3], $aCtrl[40][4] * $g_iDPI_ratio1, $aCtrl[40][5] * $g_iDPI_ratio1) _WinAPI_DeleteObject(GUICtrlSendMsg($aCtrl[40][0], $STM_SETIMAGE, $IMAGE_BITMAP, $hGDIBitmap)) GUISetState(@SW_SHOW, $ahWnd[1][0]) While 1 $aGUIGetMsg = GUIGetMsg(1) Switch $aGUIGetMsg[1] Case $ahWnd[1][0] Switch $aGUIGetMsg[0] Case $GUI_EVENT_CLOSE GUIDelete($ahWnd[1][0]) ExitLoop EndSwitch EndSwitch WEnd EndSwitch WEnd #EndRegion GUI MESSAGE LOOP EndFunc ;==>_Example Func WM_SIZE($hWnd, $iMsg, $wParam, $lParam) #forceref $iMsg, $wParam, $lParam Switch $hWnd Case $ahWnd[1][0] Local $aSize = ControlGetPos($ahWnd[1][0], "", $aCtrl[40][0]) $aCtrl[40][2] = $aSize[0] $aCtrl[40][3] = $aSize[1] $aCtrl[40][4] = _WinAPI_LoWord($lParam) $aCtrl[40][5] = _WinAPI_HiWord($lParam) GUICtrlSetPos($aCtrl[40][0], $aCtrl[40][2], $aCtrl[40][3], $aCtrl[40][4], $aCtrl[40][5]) EndSwitch Return $GUI_RUNDEFMSG EndFunc ;==>WM_SIZE Func WM_GETMINMAXINFO($hWnd, $Msg, $wParam, $lParam) If $hWnd = $ahWnd[1][0] Then Local $minmaxinfo = DllStructCreate("long ptReservedX;long ptReservedY;long ptMaxSizeX; long ptMaxSizeY;long ptMaxPositionX;long ptMaxPositionY;long ptMinTrackSizeX;long ptMinTrackSizeY;long ptMaxTrackSizeX;long ptMaxTrackSizeY ", $lParam) $minmaxinfo.ptMinTrackSizeX = $iw / 2 $minmaxinfo.ptMinTrackSizeY = $ih / 2 $minmaxinfo.ptMaxTrackSizeX = $iw * 3 $minmaxinfo.ptMaxTrackSizeY = $ih * 3 EndIf Return "GUI_RUNDEFMSG" EndFunc ;==>WM_GETMINMAXINFO Func WM_DPICHANGED($hWnd, $iMsg, $wParam, $lParam) #forceref $iMsg Local $iDPI = _WinAPI_LoWord($wParam) ConsoleWrite("DPI change triggered! DPI: " & $iDPI & @CRLF) $g_iDPI_ratio1 = $iDPI / 96 $g_iDPI_ratio2 = $g_iDPI_ratio1 ^ -1 Local $tRECT = DllStructCreate($tagRECT, $lParam) Local $iX = $tRECT.left, $iY = $tRECT.top, $iW = $tRECT.right - $iX, $iH = $tRECT.bottom - $iY, $i Switch $hWnd Case $ahWnd[0][0] _WinAPI_SetWindowPos($ahWnd[0][0], 0, $iX, $iY, $iW, $iH, BitOR($SWP_NOZORDER, $SWP_NOACTIVATE)) For $i = 0 To 39 If $aCtrl[$i][1] Then GUICtrlSetFont($aCtrl[$i][0], $aCtrl[$i][1] * $g_iDPI_ratio1) If $aCtrl[$i][4] Then GUICtrlSetPos($aCtrl[$i][0], $aCtrl[$i][2] * $g_iDPI_ratio1, $aCtrl[$i][3] * $g_iDPI_ratio1, $aCtrl[$i][4] * $g_iDPI_ratio1, $aCtrl[$i][5] * $g_iDPI_ratio1) Next _WinAPI_UpdateWindow($ahWnd[0][0]) Case $ahWnd[1][0] $i = 40 _WinAPI_SetWindowPos($ahWnd[1][0], 0, $iX, $iY, $iW, $iH, BitOR($SWP_NOZORDER, $SWP_NOACTIVATE)) GUICtrlSetPos($aCtrl[$i][0], $aCtrl[$i][2], $aCtrl[$i][3], $aCtrl[$i][4], $aCtrl[$i][5]) _WinAPI_UpdateWindow($ahWnd[1][0]) EndSwitch Return 1 EndFunc ;==>WM_DPICHANGED THX.1 point
-
I very offen wonders which values gives particular macro. For example: do I should use @AppDataDir or @LocalAppDataDir or @UserProfileDir Here is my Show_Macro_Values.au3script: ConsoleWrite('@AppDataCommonDir : ' & @AppDataCommonDir & @CRLF) ConsoleWrite('@AppDataDir : ' & @AppDataDir & @CRLF) ConsoleWrite('@AutoItExe : ' & @AutoItExe & @CRLF) ConsoleWrite('@AutoItPID : ' & @AutoItPID & @CRLF) ConsoleWrite('@AutoItVersion : ' & @AutoItVersion & @CRLF) ConsoleWrite('@AutoItX64 : ' & @AutoItX64 & @CRLF) ConsoleWrite('@CommonFilesDir : ' & @CommonFilesDir & @CRLF) ConsoleWrite('@Compiled : ' & @Compiled & @CRLF) ConsoleWrite('@ComputerName : ' & @ComputerName & @CRLF) ConsoleWrite('@ComSpec : ' & @ComSpec & @CRLF) ConsoleWrite('@CPUArch : ' & @CPUArch & @CRLF) ConsoleWrite('@DesktopCommonDir : ' & @DesktopCommonDir & @CRLF) ConsoleWrite('@DesktopDepth : ' & @DesktopDepth & @CRLF) ConsoleWrite('@DesktopDir : ' & @DesktopDir & @CRLF) ConsoleWrite('@DesktopHeight : ' & @DesktopHeight & @CRLF) ConsoleWrite('@DesktopRefresh : ' & @DesktopRefresh & @CRLF) ConsoleWrite('@DesktopWidth : ' & @DesktopWidth & @CRLF) ConsoleWrite('@DocumentsCommonDir : ' & @DocumentsCommonDir & @CRLF) ConsoleWrite('@FavoritesCommonDir : ' & @FavoritesCommonDir & @CRLF) ConsoleWrite('@FavoritesDir : ' & @FavoritesDir & @CRLF) ConsoleWrite('@HomeDrive : ' & @HomeDrive & @CRLF) ConsoleWrite('@HomePath : ' & @HomePath & @CRLF) ConsoleWrite('@HomeDrive : ' & @HomeDrive & @CRLF) ConsoleWrite('@HomeShare : ' & @HomeShare & @CRLF) ConsoleWrite('@LocalAppDataDir : ' & @LocalAppDataDir & @CRLF) ConsoleWrite('@LogonDNSDomain : ' & @LogonDNSDomain & @CRLF) ConsoleWrite('@LogonDomain : ' & @LogonDomain & @CRLF) ConsoleWrite('@LogonServer : ' & @LogonServer & @CRLF) ConsoleWrite('@MyDocumentsDir : ' & @MyDocumentsDir & @CRLF) ConsoleWrite('@OSArch : ' & @OSArch & @CRLF) ConsoleWrite('@OSBuild : ' & @OSBuild & @CRLF) ConsoleWrite('@OSLang : ' & @OSLang & @CRLF) ConsoleWrite('@OSServicePack : ' & @OSServicePack & @CRLF) ConsoleWrite('@OSType : ' & @OSType & @CRLF) ConsoleWrite('@OSVersion : ' & @OSVersion & @CRLF) ConsoleWrite('@ProgramFilesDir : ' & @ProgramFilesDir & @CRLF) ConsoleWrite('@ProgramsCommonDir : ' & @ProgramsCommonDir & @CRLF) ConsoleWrite('@ProgramsDir : ' & @ProgramsDir & @CRLF) ConsoleWrite('@ScriptFullPath : ' & @ScriptFullPath & @CRLF) ConsoleWrite('@ScriptDir : ' & @ScriptDir & @CRLF) ConsoleWrite('@ScriptName : ' & @ScriptName & @CRLF) ConsoleWrite('@ScriptLineNumber : ' & @ScriptLineNumber & @CRLF) ConsoleWrite('@StartMenuCommonDir : ' & @StartMenuCommonDir & @CRLF) ConsoleWrite('@StartMenuDir : ' & @StartMenuDir & @CRLF) ConsoleWrite('@StartupCommonDir : ' & @StartupCommonDir & @CRLF) ConsoleWrite('@StartupDir : ' & @StartupDir & @CRLF) ConsoleWrite('@SystemDir : ' & @SystemDir & @CRLF) ConsoleWrite('@TempDir : ' & @TempDir & @CRLF) ConsoleWrite('@UserName : ' & @UserName & @CRLF) ConsoleWrite('@UserProfileDir : ' & @UserProfileDir & @CRLF) ConsoleWrite('@WindowsDir : ' & @WindowsDir & @CRLF)1 point
-
Sers, while working on another project I was in need of desktop notifications. I wanted an own implementation and from time to time the code grew and I thought about sharing it with the world. I know that there is a similar UDF out there but when my project got bigger an UDF was the best choice for me. As you can see the UDF's differ in usage and style of notifications. So, what do we have? The UDF offers the usage of permanent desktop notifications for your own script in a very easy way. Notifications are starting in the bottom right corner of your main screen and will be shown on top until there is no more space. Further notifications will be shown if previous ones are closed. The notifications have a nice minimalistic design in two colors. By default they match the look of the dark taskbar in Windows 10, but colors and other things can be set differently if wished (see example scripts). The UDF works for GUIOnEventMode activated and deactivated and detects it automatically. Show me! Each notification has its GUI, a title, the message, a seperating line, date label, time label and a closing button (and if activated, a border around the notification). The color of the title, message, seperating line, date, time and closing button (+ border if activated) have all the text color. Right now notifications have a fixed size. I thought about variable sizes but did not add it because I didn't need it so far. Some people may notice the shorter seperating line when border is activated, thats just because of better looks Notifications will be colored as the following: Windows 10: they match the design of the taskbar Windows 8/8.1: On most designs: they match the border color of active windows, else they are black with transparency (see screenshot) Windows 7 and earlier: black with transparency (sry aero) How do I use notifications in my script? include UDF call _Notifications_Startup() (after you determined if you want to use GUIOnEventMode or not) If GUIOneventMode deactivated: call _Notifications_CheckGUIMsg($__GUIMsg) in your main loop create a notification using _Notifications_Create($__title, $__message) Between step 2 and 3 you can set various options: _Notifications_SetAnimationTime _Notifications_SetBorder _Notifications_SetButtonText _Notifications_SetBkColor _Notifications_SetColor _Notifications_SetDateFormat _Notifications_SetSound _Notifications_SetTextAlign _Notifications_SetTimeFormat _Notifications_SetTransparency You can also set own functions to be called when notifications are clicked (see advanced example). And now? You can find more information in the UDF. There also are two example scripts to show the usage for GUIOnEventMode activated and deactivated. Another advanced example shows the usage of the Set-Functions. Thats it? Yup, have fun. Changelog Notifications.au3 ( v1.2) Notifications GUIMsg Example.au3 Notifications OnEvent Example.au3 Notifications Advanced Example.au31 point
-
3D Pie Chart
pat4005 reacted to WideBoyDixon for a topic
I've revamped this so that it doesn't "cheat" any more but instead creates a fills paths properly. This should be a bit quicker to draw and the result looks a bit nicer I think. In addition, I've added the capability to display the pie as a 2D donut with a configurable hole size in the middle. The sliders at the bottom can be used to rotate the pie chart and also to change the aspect (but not for a donut). The third slider changes the hole size. #include <GDIPlus.au3> #include <WinAPI.au3> #include <GUISlider.au3> #include <GUIConstants.au3> #include <WindowsConstants.au3> #include <Date.au3> ; Let's be strict here Opt("MustDeclareVars", 1) ; Controls the size of the pie and also the depth Global Const $PIE_DIAMETER = 400 Global Const $PIE_MARGIN = $PIE_DIAMETER * 0.025 Global Const $PIE_DEPTH = $PIE_DIAMETER * 0.2 Global Const $PIE_AREA = $PIE_DIAMETER + 2 * $PIE_MARGIN ; Random data for values and colours Global Const $NUM_VALUES = 8 Global $aChartValue[$NUM_VALUES] Global $aChartColour[$NUM_VALUES] For $i = 0 To $NUM_VALUES - 1 $aChartValue[$i] = Random(5, 25, 1) $aChartColour[$i] = (Random(0, 255, 1) * 0x10000) + (Random(0, 255, 1) * 0x100) + Random(0, 255, 1) Next ; The value of PI Global Const $PI = ATan(1) * 4 ; Start GDI+ _GDIPlus_Startup() ; Create the brushes and pens Global $ahBrush[$NUM_VALUES][2], $ahPen[$NUM_VALUES] For $i = 0 To $NUM_VALUES - 1 $ahBrush[$i][0] = _GDIPlus_BrushCreateSolid(BitOR(0xff000000, $aChartColour[$i])) $ahBrush[$i][1] = _GDIPlus_BrushCreateSolid(BitOR(0xff000000, _GetDarkerColour($aChartColour[$i]))) $ahPen[$i] = _GDIPlus_PenCreate(BitOR(0xff000000, _GetDarkerColour(_GetDarkerColour($aChartColour[$i])))) Next ; Create the GUI with sliders to control the aspect, rotation, style and hole size (for donuts) Global $hWnd = GUICreate("Pie Chart", $PIE_AREA, $PIE_AREA + 100, Default, Default) Global $hSlideAspect = _GUICtrlSlider_Create($hWnd, $PIE_MARGIN, $PIE_AREA + 10, $PIE_DIAMETER, 20) _GUICtrlSlider_SetRange($hSlideAspect, 10, 100) _GUICtrlSlider_SetPos($hSlideAspect, 50) Global $hSlideRotation = _GUICtrlSlider_Create($hWnd, $PIE_MARGIN, $PIE_AREA + 40, $PIE_DIAMETER, 20) _GUICtrlSlider_SetRange($hSlideRotation, 0, 360) Global $cStyle = GUICtrlCreateCheckbox("Donut", $PIE_MARGIN, $PIE_AREA + 70, $PIE_DIAMETER / 2 - $PIE_MARGIN, 20) Global $hStyle = GUICtrlGetHandle($cStyle) Global $hHoleSize = _GUICtrlSlider_Create($hWnd, $PIE_MARGIN + $PIE_DIAMETER / 2, $PIE_AREA + 70, $PIE_DIAMETER / 2, 20) _GUICtrlSlider_SetRange($hHoleSize, 2, $PIE_DIAMETER - 4 * $PIE_MARGIN) _GUICtrlSlider_SetPos($hHoleSize, $PIE_DIAMETER / 2) GUISetState() ; Set up GDI+ Global $hDC = _WinAPI_GetDC($hWnd) Global $hGraphics = _GDIPlus_GraphicsCreateFromHDC($hDC) Global $hBitmap = _GDIPlus_BitmapCreateFromGraphics($PIE_AREA, $PIE_AREA, $hGraphics) Global $hBuffer = _GDIPlus_ImageGetGraphicsContext($hBitmap) _GDIPlus_GraphicsSetSmoothingMode($hBuffer, 2) ; Draw the initial pie chart _DrawPie($aChartValue, _GUICtrlSlider_GetPos($hSlideAspect) / 100, _ _GUICtrlSlider_GetPos($hSlideRotation), _ (GUICtrlRead($cStyle) = $GUI_CHECKED), _ _GUICtrlSlider_GetPos($hHoleSize)) ; The sliders will send WM_NOTIFY messages GUIRegisterMsg($WM_NOTIFY, "_OnNotify") ; Wait until the user quits While GUIGetMsg() <> $GUI_EVENT_CLOSE Sleep(10) WEnd ; Release the resources For $i = 0 To UBound($aChartColour) - 1 _GDIPlus_PenDispose($ahPen[$i]) _GDIPlus_BrushDispose($ahBrush[$i][0]) _GDIPlus_BrushDispose($ahBrush[$i][1]) Next _GDIPlus_GraphicsDispose($hBuffer) _GDIPlus_BitmapDispose($hBitmap) _GDIPlus_GraphicsDispose($hGraphics) _WinAPI_ReleaseDC($hWnd, $hDC) ; Shut down GDI+ _GDIPlus_Shutdown() ; Done Exit ; Get a darker version of a colour by extracting the RGB components Func _GetDarkerColour($Colour) Local $Red, $Green, $Blue $Red = (BitAND($Colour, 0xff0000) / 0x10000) - 40 $Green = (BitAND($Colour, 0x00ff00) / 0x100) - 40 $Blue = (BitAND($Colour, 0x0000ff)) - 40 If $Red < 0 Then $Red = 0 If $Green < 0 Then $Green = 0 If $Blue < 0 Then $Blue = 0 Return ($Red * 0x10000) + ($Green * 0x100) + $Blue EndFunc ;==>_GetDarkerColour ; Draw the pie chart Func _DrawPie($Percentage, $Aspect, $rotation, $style = 0, $holesize = 100) If $style <> 0 Then $Aspect = 1 Local $nCount, $nTotal = 0, $angleStart, $angleSweep, $X, $Y Local $pieLeft = $PIE_MARGIN, $pieTop = $PIE_AREA / 2 - ($PIE_DIAMETER / 2) * $Aspect Local $pieWidth = $PIE_DIAMETER, $pieHeight = $PIE_DIAMETER * $Aspect, $hPath ; Total up the values For $nCount = 0 To UBound($Percentage) - 1 $nTotal += $Percentage[$nCount] Next ; Set the fractional values For $nCount = 0 To UBound($Percentage) - 1 $Percentage[$nCount] /= $nTotal Next ; Make sure we don't over-rotate $rotation = Mod($rotation, 360) ; Clear the graphics buffer _GDIPlus_GraphicsClear($hBuffer, 0xffc0c0c0) ; Set the initial angles based on the fractional values Local $Angles[UBound($Percentage) + 1] For $nCount = 0 To UBound($Percentage) If $nCount = 0 Then $Angles[$nCount] = $rotation Else $Angles[$nCount] = $Angles[$nCount - 1] + ($Percentage[$nCount - 1] * 360) EndIf Next Switch $style Case 0 ; Adjust the angles based on the aspect For $nCount = 0 To UBound($Percentage) $X = $PIE_DIAMETER * Cos($Angles[$nCount] * $PI / 180) $Y = $PIE_DIAMETER * Sin($Angles[$nCount] * $PI / 180) $Y -= ($PIE_DIAMETER - $pieHeight) * Sin($Angles[$nCount] * $PI / 180) If $X = 0 Then $Angles[$nCount] = 90 + ($Y < 0) * 180 Else $Angles[$nCount] = ATan($Y / $X) * 180 / $PI EndIf If $X < 0 Then $Angles[$nCount] += 180 If $X >= 0 And $Y < 0 Then $Angles[$nCount] += 360 $X = $PIE_DIAMETER * Cos($Angles[$nCount] * $PI / 180) $Y = $pieHeight * Sin($Angles[$nCount] * $PI / 180) Next ; Decide which pieces to draw first and last Local $nStart = -1, $nEnd = -1 For $nCount = 0 To UBound($Percentage) - 1 $angleStart = Mod($Angles[$nCount], 360) $angleSweep = Mod($Angles[$nCount + 1] - $Angles[$nCount] + 360, 360) If $angleStart <= 270 And ($angleStart + $angleSweep) >= 270 Then $nStart = $nCount EndIf If ($angleStart <= 90 And ($angleStart + $angleSweep) >= 90) _ Or ($angleStart <= 450 And ($angleStart + $angleSweep) >= 450) Then $nEnd = $nCount EndIf If $nEnd >= 0 And $nStart >= 0 Then ExitLoop Next ; Draw the first piece _DrawPiePiece($hBuffer, $pieLeft, $pieTop, $pieWidth, $pieHeight, $PIE_DEPTH * (1 - $Aspect), $nStart, $Angles) ; Draw pieces "to the right" $nCount = Mod($nStart + 1, UBound($Percentage)) While $nCount <> $nEnd _DrawPiePiece($hBuffer, $pieLeft, $pieTop, $pieWidth, $pieHeight, $PIE_DEPTH * (1 - $Aspect), $nCount, $Angles) $nCount = Mod($nCount + 1, UBound($Percentage)) WEnd ; Draw pieces "to the left" $nCount = Mod($nStart + UBound($Percentage) - 1, UBound($Percentage)) While $nCount <> $nEnd _DrawPiePiece($hBuffer, $pieLeft, $pieTop, $pieWidth, $pieHeight, $PIE_DEPTH * (1 - $Aspect), $nCount, $Angles) $nCount = Mod($nCount + UBound($Percentage) - 1, UBound($Percentage)) WEnd ; Draw the last piece _DrawPiePiece($hBuffer, $pieLeft, $pieTop, $pieWidth, $pieHeight, $PIE_DEPTH * (1 - $Aspect), $nEnd, $Angles) Case 1 ; Draw the donut pieces For $nCount = 0 To UBound($Percentage) - 1 $angleStart = Mod($Angles[$nCount], 360) $angleSweep = Mod($Angles[$nCount + 1] - $Angles[$nCount] + 360, 360) ; Draw the outer arc in a darker colour $hPath = _GDIPlus_GraphicsPathCreate() _GDIPlus_GraphicsPathAddArc($hPath, $pieLeft, $pieTop, $pieWidth, $pieHeight, $angleStart, $angleSweep) _GDIPlus_GraphicsPathAddArc($hPath, $pieLeft + $PIE_MARGIN, $pieTop + $PIE_MARGIN, $pieWidth - $PIE_MARGIN * 2, _ $pieHeight - $PIE_MARGIN * 2, $angleStart + $angleSweep, -$angleSweep) _GDIPlus_GraphicsPathCloseFigure($hPath) _GDIPlus_GraphicsFillPath($hBuffer, $ahBrush[$nCount][1], $hPath) _GDIPlus_GraphicsDrawPath($hBuffer, $ahPen[$nCount], $hPath) _GDIPlus_GraphicsPathDispose($hPath) ; Draw the inner piece in a lighter colour - leave room for the hole $hPath = _GDIPlus_GraphicsPathCreate() _GDIPlus_GraphicsPathAddArc($hPath, $pieLeft + $PIE_MARGIN, $pieTop + $PIE_MARGIN, $pieWidth - $PIE_MARGIN * 2, _ $pieHeight - $PIE_MARGIN * 2, $angleStart, $angleSweep) _GDIPlus_GraphicsPathAddArc($hPath, $pieLeft + ($PIE_DIAMETER - $holesize) / 2, $pieTop + ($PIE_DIAMETER - $holesize) / 2, _ $holesize, $holesize, $angleStart + $angleSweep, -$angleSweep) _GDIPlus_GraphicsPathCloseFigure($hPath) _GDIPlus_GraphicsFillPath($hBuffer, $ahBrush[$nCount][0], $hPath) _GDIPlus_GraphicsDrawPath($hBuffer, $ahPen[$nCount], $hPath) _GDIPlus_GraphicsPathDispose($hPath) Next EndSwitch ; Now draw the bitmap on to the device context of the window _GDIPlus_GraphicsDrawImage($hGraphics, $hBitmap, 0, 0) EndFunc ;==>_DrawPie Func _OnNotify($hWnd, $iMsg, $wParam, $lParam) Local $tNMHDR = DllStructCreate($tagNMHDR, $lParam) Local $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom")) Switch $hWndFrom Case $hSlideAspect, $hSlideRotation, $hStyle, $hHoleSize ; Update the pie chart _DrawPie($aChartValue, _GUICtrlSlider_GetPos($hSlideAspect) / 100, _ _GUICtrlSlider_GetPos($hSlideRotation), _ (GUICtrlRead($cStyle) = $GUI_CHECKED), _ _GUICtrlSlider_GetPos($hHoleSize)) EndSwitch EndFunc ;==>_OnNotify Func _DrawPiePiece($hGraphics, $iX, $iY, $iWidth, $iHeight, $iDepth, $nCount, $Angles) Local $hPath, $cX = $iX + ($iWidth / 2), $cY = $iY + ($iHeight / 2), $fDrawn = False Local $iStart = Mod($Angles[$nCount], 360), $iSweep = Mod($Angles[$nCount + 1] - $Angles[$nCount] + 360, 360) ; Draw side ConsoleWrite(_Now() & @CRLF) $hPath = _GDIPlus_GraphicsPathCreate() If $iStart < 180 And ($iStart + $iSweep > 180) Then _GDIPlus_GraphicsPathAddArc($hPath, $iX, $iY, $iWidth, $iHeight, $iStart, 180 - $iStart) _GDIPlus_GraphicsPathAddArc($hPath, $iX, $iY + $iDepth, $iWidth, $iHeight, 180, $iStart - 180) _GDIPlus_GraphicsPathCloseFigure($hPath) _GDIPlus_GraphicsFillPath($hGraphics, $ahBrush[$nCount][1], $hPath) _GDIPlus_GraphicsDrawPath($hGraphics, $ahPen[$nCount], $hPath) $fDrawn = True EndIf If $iStart + $iSweep > 360 Then _GDIPlus_GraphicsPathAddArc($hPath, $iX, $iY, $iWidth, $iHeight, 0, $iStart + $iSweep - 360) _GDIPlus_GraphicsPathAddArc($hPath, $iX, $iY + $iDepth, $iWidth, $iHeight, $iStart + $iSweep - 360, 360 - $iStart - $iSweep) _GDIPlus_GraphicsPathCloseFigure($hPath) _GDIPlus_GraphicsFillPath($hGraphics, $ahBrush[$nCount][1], $hPath) _GDIPlus_GraphicsDrawPath($hGraphics, $ahPen[$nCount], $hPath) $fDrawn = True EndIf If $iStart < 180 And (Not $fDrawn) Then _GDIPlus_GraphicsPathAddArc($hPath, $iX, $iY, $iWidth, $iHeight, $iStart, $iSweep) _GDIPlus_GraphicsPathAddArc($hPath, $iX, $iY + $iDepth, $iWidth, $iHeight, $iStart + $iSweep, -$iSweep) _GDIPlus_GraphicsPathCloseFigure($hPath) _GDIPlus_GraphicsFillPath($hGraphics, $ahBrush[$nCount][1], $hPath) _GDIPlus_GraphicsDrawPath($hGraphics, $ahPen[$nCount], $hPath) EndIf _GDIPlus_GraphicsPathDispose($hPath) ; Draw top _GDIPlus_GraphicsFillPie($hGraphics, $iX, $iY, $iWidth, $iHeight, $iStart, $iSweep, $ahBrush[$nCount][0]) _GDIPlus_GraphicsDrawPie($hGraphics, $iX, $iY, $iWidth, $iHeight, $iStart, $iSweep, $ahPen[$nCount]) EndFunc ;==>_DrawPiePiece Func _GDIPlus_GraphicsPathCreate($iFillMode = 0) Local $aResult = DllCall($ghGDIPDll, "int", "GdipCreatePath", "int", $iFillMode, "int*", 0); If @error Then Return SetError(@error, @extended, 0) Return SetError($aResult[0], 0, $aResult[2]) EndFunc ;==>_GDIPlus_GraphicsPathCreate Func _GDIPlus_GraphicsPathAddLine($hGraphicsPath, $iX1, $iY1, $iX2, $iY2) Local $aResult = DllCall($ghGDIPDll, "int", "GdipAddPathLine", "hwnd", $hGraphicsPath, "float", $iX1, "float", $iY1, _ "float", $iX2, "float", $iY2) If @error Then Return SetError(@error, @extended, 0) Return SetError($aResult[0], 0, 0) EndFunc ;==>_GDIPlus_GraphicsPathAddLine Func _GDIPlus_GraphicsPathAddArc($hGraphicsPath, $iX, $iY, $iWidth, $iHeight, $iStartAngle, $iSweepAngle) Local $aResult = DllCall($ghGDIPDll, "int", "GdipAddPathArc", "hwnd", $hGraphicsPath, "float", $iX, "float", $iY, _ "float", $iWidth, "float", $iHeight, "float", $iStartAngle, "float", $iSweepAngle) If @error Then Return SetError(@error, @extended, 0) Return SetError($aResult[0], 0, 0) EndFunc ;==>_GDIPlus_GraphicsPathAddArc Func _GDIPlus_GraphicsPathAddPie($hGraphicsPath, $iX, $iY, $iWidth, $iHeight, $iStartAngle, $iSweepAngle) Local $aResult = DllCall($ghGDIPDll, "int", "GdipAddPathPie", "hwnd", $hGraphicsPath, "float", $iX, "float", $iY, _ "float", $iWidth, "float", $iHeight, "float", $iStartAngle, "float", $iSweepAngle) If @error Then Return SetError(@error, @extended, 0) Return SetError($aResult[0], 0, 0) EndFunc ;==>_GDIPlus_GraphicsPathAddPie Func _GDIPlus_GraphicsPathCloseFigure($hGraphicsPath) Local $aResult = DllCall($ghGDIPDll, "int", "GdipClosePathFigure", "hwnd", $hGraphicsPath) If @error Then Return SetError(@error, @extended, 0) Return SetError($aResult[0], 0, 0) EndFunc ;==>_GDIPlus_GraphicsPathCloseFigure Func _GDIPlus_GraphicsPathDispose($hGraphicsPath) Local $aResult = DllCall($ghGDIPDll, "int", "GdipDeletePath", "hwnd", $hGraphicsPath) If @error Then Return SetError(@error, @extended, 0) Return SetError($aResult[0], 0, 0) EndFunc ;==>_GDIPlus_GraphicsPathDispose Func _GDIPlus_GraphicsDrawPath($hGraphics, $hPen, $hGraphicsPath) Local $aResult = DllCall($ghGDIPDll, "int", "GdipDrawPath", "hwnd", $hGraphics, "hwnd", $hPen, "hwnd", $hGraphicsPath) If @error Then Return SetError(@error, @extended, 0) Return SetError($aResult[0], 0, 0) EndFunc ;==>_GDIPlus_GraphicsDrawPath Func _GDIPlus_GraphicsFillPath($hGraphics, $hBrush, $hGraphicsPath) Local $aResult = DllCall($ghGDIPDll, "int", "GdipFillPath", "hwnd", $hGraphics, "hwnd", $hBrush, "hwnd", $hGraphicsPath) If @error Then Return SetError(@error, @extended, 0) Return SetError($aResult[0], 0, 0) EndFunc ;==>_GDIPlus_GraphicsFillPath1 point -
Creates a shortcut file to a URL $oShell = ObjCreate("WScript.Shell") $oShort = $oShell.CreateShortcut(@ScriptDir & "\AutoIt Forums.url") $oShort.TargetPath = "http://www.autoitscript.com/forum/" $oShort.Save1 point