mpower Posted August 7, 2015 Share Posted August 7, 2015 (edited) Hey all (especially @water - the creator of AD UDF),I'm having a problem with using some GDI+ animations alongside AD queries - when an AD query happens, the animation halts/slows down a lot. Is there any reason for this? And possibly a workaround that doesn't cause the animation choppiness?Here's the reproducer:expandcollapse popup#include <Array.au3> #include <AD.au3> #include <GDIPlus.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> _GDIPlus_Startup() Global $iW = 300, $iH = 150, $userfirstname Global Const $hGUI = GUICreate("", $iW, $iH, -1, -1, $WS_POPUP + $WS_BORDER) GUISetBkColor(0xFFFFFF) Global Const $iPic = GUICtrlCreatePic("", 0, 0, $iW, $iH - 20) GUICtrlSetState(-1, $GUI_DISABLE) $statuslbl = GUICtrlCreateLabel("Loading please wait...", 0, $iH - 15, $iW, 15, $SS_CENTER) GUICtrlSetBkColor(-1, 0xFFFFFF) GUISetState() Global $hHBmp_BG, $hB AdlibRegister("PlayAnim", 10) NameCheck() Do Switch GUIGetMsg() Case $GUI_EVENT_CLOSE AdlibUnRegister("PlayAnim") _WinAPI_DeleteObject($hHBmp_BG) _GDIPlus_Shutdown() GUIDelete() Exit EndSwitch Until False Func NameCheck() If _AD_Open() Then $aResult = _AD_GetObjectAttribute(@UserName, "DisplayName") $aResultSplit = StringSplit($aResult, ',') $userfirstname = StringStripWS($aResultSplit[Ubound($aResultSplit)-1],$STR_STRIPLEADING) _AD_Close() Else $userfirstname = 'Anonymous' EndIf GUICtrlSetData($statuslbl, 'Hi, ' & $userfirstname) EndFunc ;==>CheckName Func PlayAnim() $hHBmp_BG = _GDIPlus_Carousel($iW, $iH - 20) $hB = GUICtrlSendMsg($iPic, $STM_SETIMAGE, $IMAGE_BITMAP, $hHBmp_BG) If $hB Then _WinAPI_DeleteObject($hB) _WinAPI_DeleteObject($hHBmp_BG) EndFunc ;==>PlayAnim Func _GDIPlus_Carousel($iW, $iH, $bHBitmap = True) Local Const $hBitmap = _GDIPlus_BitmapCreateFromScan0($iW, $iH) Local Const $hGfx = _GDIPlus_ImageGetGraphicsContext($hBitmap) _GDIPlus_GraphicsSetSmoothingMode($hGfx, 4 + (@OSBuild > 5999)) _GDIPlus_GraphicsSetPixelOffsetMode($hGfx, 4) _GDIPlus_GraphicsClear($hGfx, 0xFFFFFFFF) Local Const $iUB = 4 Local $aColors[$iUB][4] = [[0xD8F4B401, 0xE8CF9902], [0xD8E3746C, 0xE8C1645C], [0xD83A7BF9, 0xE8326AD4], [0xD8109D59, 0xE80E864C]] Local Const $fRadius = 50, $fMid = ($iW - $fRadius) / 2 Local Const $hBrush = _GDIPlus_BrushCreateSolid(), $hPen = _GDIPlus_PenCreate(0x80000000) Local Const $hPath1 = _GDIPlus_PathCreate(), $hPath2 = _GDIPlus_PathCreate() Local $hRegion1, $hRegion2, $fPenSize, $i Local Static $fSpeed For $i = 0 To $iUB - 1 $aColors[$i][2] = -Sin($fSpeed + $i * 1.570796) * 15 ;z coordinate, 1.570796 = Pi/2 = 90° = 360° / 4 $aColors[$i][3] = $fMid + Cos($fSpeed + $i * 1.570796) * 80 ;x coordinate Next _ArraySort($aColors, 0, 0, 0, 2) ;sort z-axis For $i = 0 To $iUB - 1 $fPenSize = $aColors[$i][2] / 20 + 1.1 _GDIPlus_PenSetWidth($hPen, $fPenSize) _GDIPlus_BrushSetSolidColor($hBrush, 0x80E0E0E0) ;shadow color _GDIPlus_GraphicsFillEllipse($hGfx, $aColors[$i][3], ($iH - $fRadius) / 2 + 10 + $fRadius + $aColors[$i][2], $fRadius + $aColors[$i][2], ($fRadius + $aColors[$i][2]) / 4, $hBrush) _GDIPlus_PathAddEllipse($hPath1, $aColors[$i][3], ($iH - $fRadius) / 2, $fRadius + $aColors[$i][2], $fRadius + $aColors[$i][2]) _GDIPlus_PathAddEllipse($hPath2, $aColors[$i][3] + $fPenSize - 5 - $aColors[$i][2] / 10, ($iH - $fRadius) / 2 - $fPenSize - 5 - $aColors[$i][2] / 10, $fRadius + $aColors[$i][2], $fRadius + $aColors[$i][2]) $hRegion1 = _GDIPlus_RegionCreateFromPath($hPath1) $hRegion2 = _GDIPlus_RegionCreateFromPath($hPath2) _GDIPlus_RegionCombineRegion($hRegion1, $hRegion2, 1) ;combine lighter circle with darker circle _GDIPlus_BrushSetSolidColor($hBrush, $aColors[$i][1]) ;lighter ball color _GDIPlus_GraphicsFillPath($hGfx, $hPath1, $hBrush) _GDIPlus_BrushSetSolidColor($hBrush, $aColors[$i][0]) ;darker ball color _GDIPlus_GraphicsFillRegion($hGfx, $hRegion1, $hBrush) _GDIPlus_GraphicsDrawPath($hGfx, $hPath1, $hPen) ;draw circle frame _GDIPlus_RegionDispose($hRegion1) _GDIPlus_RegionDispose($hRegion2) _GDIPlus_PathReset($hPath1) _GDIPlus_PathReset($hPath2) Next $fSpeed += 0.0361799 If $bHBitmap Then Local $hHBITMAP = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hBitmap) _GDIPlus_BitmapDispose($hBitmap) Return $hHBITMAP EndIf Return $hBitmap EndFuncCheers,mpower Edited August 7, 2015 by mpower Link to comment Share on other sites More sharing options...
UEZ Posted August 7, 2015 Share Posted August 7, 2015 AutoIt is not able to work "real" threaded. That means when you use AdlibRegister or the Timer function the script will still partly interrupted as it is done in this AD scenario.I don't know whether it is possible to let run the animation function "real" threaded. Please don't send me any personal message and ask for support! I will not reply! Selection of finest graphical examples at Codepen.io The own fart smells best! ✌Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!¯\_(ツ)_/¯ ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ Link to comment Share on other sites More sharing options...
water Posted August 7, 2015 Share Posted August 7, 2015 I'm not sure AdlibRegister can interrupt a running AD query. Wouldn't a progress bar or something else be enough to tell the user that the script is working ...? My UDFs and Tutorials: Spoiler UDFs:Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsOutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiPowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - WikiTask Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs:Excel - Example Scripts - WikiWord - Wiki Tutorials:ADO - WikiWebDriver - Wiki Link to comment Share on other sites More sharing options...
UEZ Posted August 7, 2015 Share Posted August 7, 2015 water, same problem when using the timer function. A progress bar is too boring. Please don't send me any personal message and ask for support! I will not reply! Selection of finest graphical examples at Codepen.io The own fart smells best! ✌Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!¯\_(ツ)_/¯ ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ Link to comment Share on other sites More sharing options...
water Posted August 7, 2015 Share Posted August 7, 2015 I see. In this case I would try to enhance performance of the AD queries. If you can deliver sub-second response time then there is no need for a progress bar or something else. My UDFs and Tutorials: Spoiler UDFs:Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsOutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiPowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - WikiTask Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs:Excel - Example Scripts - WikiWord - Wiki Tutorials:ADO - WikiWebDriver - Wiki Link to comment Share on other sites More sharing options...
mpower Posted August 7, 2015 Author Share Posted August 7, 2015 I see. In this case I would try to enhance performance of the AD queries. If you can deliver sub-second response time then there is no need for a progress bar or something else.there is actually a other things happening before the AD query, this is part of a splash screen, it's the reproducer that I've created to only show the "slow-down" part of the animation. when other things happen the animation is smooth, only the AD query seems to cause the slow down. Link to comment Share on other sites More sharing options...
water Posted August 7, 2015 Share Posted August 7, 2015 Never did I play with performance of the AD UDF and GDI+.But if the animation is so essential you could run the animation in another script and use IPC (Inter Process Communication) to move data to the animation script or end it. My UDFs and Tutorials: Spoiler UDFs:Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsOutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiPowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - WikiTask Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs:Excel - Example Scripts - WikiWord - Wiki Tutorials:ADO - WikiWebDriver - Wiki Link to comment Share on other sites More sharing options...
mpower Posted August 7, 2015 Author Share Posted August 7, 2015 Never did I play with performance of the AD UDF and GDI+.But if the animation is so essential you could run the animation in another script and use IPC (Inter Process Communication) to move data to the animation script or end it.Oh it's definitely not important or essential, I just thought it might be due to some bug or inefficiency in the UDF or autoit, but if it's just down to the non-threaded autoit process then that's that. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now