CoffeeJoe Posted October 4, 2021 Posted October 4, 2021 I have a project that I believe needs some additional animation - I have looked at various posts and considered several options. Problem I have is that I'm trying to animate some GDI+ graphics / not insert a gif. I put together an example of what I have and what I'm looking for. Any assistance would be appreciated. Thanks expandcollapse popup#include <GUIConstants.au3> #include <GDIPlus.au3> #NoTrayIcon Global $GUIw = 247, $GUIh = 395 Global $bkcolor24 = 0x303030, $bkcolor32 = 0xFF303030 Global $flash = 0 , $pulse = 0 ;Define the Primary GUI ================================================================================== $main = GUICreate("", $GUIw, $GUIh, Default, Default, $WS_POPUP, $WS_EX_TOPMOST) GUISetBkColor($bkcolor24, $main) GUICtrlCreateLabel("", 0, 0, ($GUIw-30), 30, Default, $GUI_WS_EX_PARENTDRAG) FormatCtrl(-1, 1, 16, 0xFFFFFF, 0xFF6000) $exitb = GUICtrlCreateButton("Ò", ($GUIw-30), 0, 30, 30) FormatCtrl(-1, 2, 18, 0xFFFFFF, 0xFF0000) ;==================================================== ; This is what I have - its quick and lightweight - a little choppy but servicable ; Not my optimal choice - it studders and flickers sometimes and it's too abrupt ;******************************************************************* $ring = GUICtrlCreatePic("", 15, 150, 40, 40) DrawParts(-1, 1, 40, 40) GUICtrlSetState(-1, $GUI_DISABLE) $flash1 = GUICtrlCreatePic("", 15, 150, 40, 40) DrawParts(-1, 2, 40, 40) GUICtrlSetCursor(-1, 0) $flash2 = GUICtrlCreatePic("", 15, 150, 40, 40) DrawParts(-1, 3, 40, 40) GUICtrlSetCursor(-1, 0) GUICtrlSetState(-1, BitOR($GUI_DISABLE, $GUI_HIDE)) $flash3 = GUICtrlCreatePic("", 15, 150, 40, 40) DrawParts(-1, 4, 40, 40) GUICtrlSetCursor(-1, 0) GUICtrlSetState(-1, BitOR($GUI_DISABLE, $GUI_HIDE)) ;******************** AdlibRegister("Flash", 750) ; Adlib ;******************** ;===================================================== ; This is what I want - the slow pulse in and out - but it can't hog the processing ; cycle this long or use GDI+ to run - other processes already have GDI+ working at 100% ;****************************************************************** $ring2 = GUICtrlCreatePic("", 75, 150, 40, 40) DrawParts(-1, 1, 40, 40) GUICtrlSetState(-1, $GUI_DISABLE) $pulse1 = GUICtrlCreatePic("", 75, 150, 40, 40) DrawParts(-1, 5, 40, 40, 0xFF9F7800) ;******************** AdlibRegister("Pulse", 2000) ; Adlib ;******************** GUISetState(@SW_SHOW, $main) ;==================================================== ; What I'm looking for is a way to put these frames in a "gif" or "avi" and use one of ; several low cost options to run it. Trancexx's solution seems perfect. ; I can't save anything to the disk and once drawn can't require GDI+ to run it. ; Clarification: I don't want to save anything to the disk and can't have _GDIPlus_Startup() ; It causes my program to crash if it does _GDIPlus_Shutdown() when other process is running ; Additionally: If I leave GDI+ running and don't shut it down between tasks the process ; grows in memory to the tune of about 4MB per cycle and never releases it. ;******************************************************************* ;Main Process Loop ====================================================================================== While 1 $msg = GUIGetMsg() If $msg = $GUI_EVENT_CLOSE Then ExitLoop If $msg = $exitb Then ExitLoop WEnd ;====================== ; Exit Cleanup AdlibUnRegister("Flash") AdlibUnRegister("Pulse") GUIDelete($main) ; Functions =========================================================================================== ;***************************************************************************************** ;======================================== Func FormatCtrl($ctrl, $opt, $fsize, $fg=Default, $bg=Default) Switch $opt Case 1 GUICtrlSetFont($ctrl, $fsize, 500, -1, "Consolas", 4) GUICtrlSetBkColor($ctrl, $bg) GUICtrlSetColor($ctrl, $fg) Case 2 GUICtrlSetFont($ctrl, $fsize, 500, -1, "Wingdings 2", 4) GUICtrlSetBkColor($ctrl, $bg) GUICtrlSetColor($ctrl, $fg) EndSwitch EndFunc ;======================================== Func DrawParts($ctrl, $opt, $pw, $ph, $color = 0) _GDIPlus_Startup() Local $ghandle = _GDIPlus_GraphicsCreateFromHWND($main) Local $hImage = _GDIPlus_BitmapCreateFromGraphics($pw, $ph, $ghandle) Local $hGraphic = _GDIPlus_ImageGetGraphicsContext($hImage) _GDIPlus_GraphicsSetSmoothingMode($hGraphic, 2) Switch $opt Case 1 ;Ring Local $hBrush =_GDIPlus_LineBrushCreate(($pw*0.5), ($ph*0.0), ($pw*0.5), ($ph*0.5), 0xFF707070, 0xFFE0E0E0, 3) _GDIPlus_GraphicsFillEllipse($hGraphic, 0, 0, $pw, $ph, $hBrush) _GDIPlus_BrushDispose($hBrush) $hBrush = _GDIPlus_BrushCreateSolid(0xFF000000) _GDIPlus_GraphicsFillEllipse($hGraphic, ($pw*0.2), ($ph*0.2), ($pw*0.6), ($ph*0.6), $hBrush) _GDIPlus_BrushDispose($hBrush) $hPen = _GDIPlus_PenCreate(0xFF707070, 4) _GDIPlus_GraphicsDrawEllipse($hGraphic, ($pw*0.2), ($ph*0.2), ($pw*0.6), ($ph*0.6), $hPen) _GDIPlus_PenDispose($hPen) Case 2 ; off $hBrush = _GDIPlus_BrushCreateSolid(0xFF9F7800) _GDIPlus_GraphicsFillEllipse($hGraphic, ($pw*0.2), ($ph*0.2), ($pw*0.6), ($ph*0.6), $hBrush) _GDIPlus_BrushDispose($hBrush) Case 3 ; mid $hBrush = _GDIPlus_BrushCreateSolid(0xFFCF9800) _GDIPlus_GraphicsFillEllipse($hGraphic, ($pw*0.2), ($ph*0.2), ($pw*0.6), ($ph*0.6), $hBrush) _GDIPlus_BrushDispose($hBrush) Case 4 ; on $hBrush = _GDIPlus_BrushCreateSolid(0xFFFFC800) _GDIPlus_GraphicsFillEllipse($hGraphic, ($pw*0.2), ($ph*0.2), ($pw*0.6), ($ph*0.6), $hBrush) _GDIPlus_BrushDispose($hBrush) Case 5 $hBrush = _GDIPlus_BrushCreateSolid($color) _GDIPlus_GraphicsFillEllipse($hGraphic, ($pw*0.2), ($ph*0.2), ($pw*0.6), ($ph*0.6), $hBrush) _GDIPlus_BrushDispose($hBrush) EndSwitch Local $hBitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hImage) _WinAPI_DeleteObject(GUICtrlSendMsg($ctrl, $STM_SETIMAGE, $IMAGE_BITMAP, $hBitmap)) _WinAPI_DeleteObject($hBitmap) _GDIPlus_GraphicsDispose($hGraphic) _GDIPlus_GraphicsDispose($ghandle) _GDIPlus_ImageDispose($hImage) _GDIPlus_Shutdown() EndFunc ;======================================== Func Flash() Switch $flash Case 0 GUICtrlSetState($flash3, BitOR($GUI_DISABLE, $GUI_HIDE)) GUICtrlSetState($flash2, BitOR($GUI_ENABLE, $GUI_SHOW)) GUICtrlSetState($flash2, BitOR($GUI_DISABLE, $GUI_HIDE)) GUICtrlSetState($flash1, BitOR($GUI_ENABLE, $GUI_SHOW)) $flash = 1 Case 1 GUICtrlSetState($flash1, BitOR($GUI_DISABLE, $GUI_HIDE)) GUICtrlSetState($flash2, BitOR($GUI_ENABLE, $GUI_SHOW)) GUICtrlSetState($flash2, BitOR($GUI_DISABLE, $GUI_HIDE)) GUICtrlSetState($flash3, BitOR($GUI_ENABLE, $GUI_SHOW)) $flash = 0 EndSwitch EndFunc Func Pulse() Local $aColors[7] $aColors[0] = 0xFF9F7800 $aColors[1] = 0xFFAF8800 $aColors[2] = 0xFFBF9800 $aColors[3] = 0xFFCFA800 $aColors[4] = 0xFFDFB800 $aColors[5] = 0xFFEFC800 $aColors[6] = 0xFFFFC800 Switch $pulse Case 0 For $i = 0 To 6 DrawParts($pulse1, 5, 40, 40, $aColors[$i]) Sleep(100) Next $pulse = 1 Case 1 For $i = 6 To 0 Step -1 DrawParts($pulse1, 5, 40, 40, $aColors[$i]) Sleep(100) Next $pulse = 0 EndSwitch EndFunc
CoffeeJoe Posted October 8, 2021 Author Posted October 8, 2021 So I just discovered that an Image List isn't only available in a ListView control. (have always seen to 2 together) I'm pretty sure I can put my graphic images in an ImageList and draw them into another control using _Imagelist_Draw This is a revelation for me and I think it will change the way I solve this problem. I'll post what I come up with
Solution CoffeeJoe Posted October 8, 2021 Author Solution Posted October 8, 2021 This is what I ended up with I'll do some tweaking to make it a little smoother flowing but this is essentially what I need. expandcollapse popup#include <GUIConstants.au3> #include <GuiImageList.au3> #include <GuiListView.au3> #include <GDIPlus.au3> #NoTrayIcon Global $GUIw = 247, $GUIh = 395 Global $bkcolor24 = 0x303030, $bkcolor32 = 0xFF303030 Global $hImageList Global $pulse = 0 ;Define the Primary GUI ================================================================================== $main = GUICreate("", $GUIw, $GUIh, Default, Default, $WS_POPUP, $WS_EX_TOPMOST) GUISetBkColor($bkcolor24, $main) GUICtrlCreateLabel("", 0, 0, ($GUIw-30), 30, Default, $GUI_WS_EX_PARENTDRAG) FormatCtrl(-1, 1, 16, 0xFFFFFF, 0xFF6000) $exitb = GUICtrlCreateButton("Ò", ($GUIw-30), 0, 30, 30) FormatCtrl(-1, 2, 18, 0xFFFFFF, 0xFF0000) GUISetState(@SW_SHOW, $main) CreateImageList() ;******************** AdlibRegister("Pulse") ; Adlib ;******************** ;Main Process Loop ====================================================================================== While 1 $msg = GUIGetMsg() If $msg = $GUI_EVENT_CLOSE Then ExitLoop If $msg = $exitb Then ExitLoop WEnd ;====================== ; Exit Cleanup AdlibUnRegister("Pulse") GUIDelete($main) ; Functions =========================================================================================== ;***************************************************************************************** Func CreateImageList() Local $aColors[4] $aColors[0] = 0xFF9F7800 ;$aColors[1] = 0xFFAF8800 $aColors[1] = 0xFFBF9800 ;$aColors[3] = 0xFFCFA800 $aColors[2] = 0xFFDFB800 ;$aColors[5] = 0xFFEFC800 $aColors[3] = 0xFFFFC800 $hImageList = _GUiImageList_Create ( 40, 40, 5, 4 ) ; 40x40, 32bit color, strip of images DrawParts(1, 40, 40) ;0 For $i = 0 To 3 ;1-4 DrawParts(2, 40, 40, $aColors[$i]) Next For $i = 3 To 0 Step -1 ; 5-8 DrawParts(2, 40, 40, $aColors[$i]) Next EndFunc ;======================================== Func DrawParts($opt, $pw, $ph, $color = 0) _GDIPlus_Startup() Local $hGui = _GDIPlus_GraphicsCreateFromHWND($main) Local $hBmp = _GDIPlus_BitmapCreateFromGraphics($pw, $ph, $hGui) Local $hGC = _GDIPlus_ImageGetGraphicsContext($hBmp) _GDIPlus_GraphicsSetSmoothingMode($hGC, 2) Switch $opt Case 1 ;Ring Local $hBrush =_GDIPlus_LineBrushCreate(($pw*0.5), ($ph*0.0), ($pw*0.5), ($ph*0.5), 0xFF707070, 0xFFE0E0E0, 3) _GDIPlus_GraphicsFillEllipse($hGC, 0, 0, $pw, $ph, $hBrush) _GDIPlus_BrushDispose($hBrush) $hBrush = _GDIPlus_BrushCreateSolid(0xFF000000) _GDIPlus_GraphicsFillEllipse($hGC, ($pw*0.2), ($ph*0.2), ($pw*0.6), ($ph*0.6), $hBrush) _GDIPlus_BrushDispose($hBrush) $hPen = _GDIPlus_PenCreate(0xFF707070, 4) _GDIPlus_GraphicsDrawEllipse($hGC, ($pw*0.2), ($ph*0.2), ($pw*0.6), ($ph*0.6), $hPen) _GDIPlus_PenDispose($hPen) Case 2 ;Light $hBrush = _GDIPlus_BrushCreateSolid($color) _GDIPlus_GraphicsFillEllipse($hGC, ($pw*0.2), ($ph*0.2), ($pw*0.6), ($ph*0.6), $hBrush) _GDIPlus_BrushDispose($hBrush) EndSwitch Local $hBitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hBmp) _GUiImageList_Add ( $hImageList, $hBitmap ) _WinAPI_DeleteObject($hBitmap) _WinAPI_ReleaseDC($main, $hGC) _GDIPlus_GraphicsDispose($hGC) _GDIPlus_GraphicsDispose($hGui) _GDIPlus_ImageDispose($hBmp) _GDIPlus_Shutdown() EndFunc ;======================================== Func DrawImage($img) Switch $img Case 0 Local $hDC = _WinAPI_GetDC($main) _GUIImageList_Draw($hImageList, $img, $hDC, 15, 40) _WinAPI_ReleaseDC($main, $hDC) Case Else Local $hDC = _WinAPI_GetDC($main) _GUIImageList_Draw($hImageList, $img, $hDC, 15, 40) _WinAPI_ReleaseDC($main, $hDC) EndSwitch EndFunc ;======================================== Func Pulse() DrawImage($pulse) $pulse += 1 If $pulse > 8 Then $pulse = 1 EndFunc ;======================================== Func FormatCtrl($ctrl, $opt, $fsize, $fg=Default, $bg=Default) Switch $opt Case 1 GUICtrlSetFont($ctrl, $fsize, 500, -1, "Consolas", 4) GUICtrlSetBkColor($ctrl, $bg) GUICtrlSetColor($ctrl, $fg) Case 2 GUICtrlSetFont($ctrl, $fsize, 500, -1, "Wingdings 2", 4) GUICtrlSetBkColor($ctrl, $bg) GUICtrlSetColor($ctrl, $fg) EndSwitch EndFunc
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