JockoDundee Posted October 8, 2020 Share Posted October 8, 2020 (edited) I’ve been using WinMove to send windows silently to the outer unseen reaches, because it is so much easier than Hiding with ???SetState. Why easier? Because it doesn’t need a redraw after the @SW_SHOW and it even lets me draw on it when it’s off screen. But I know in my heart it’s wrong. I know I could also loop around waiting for GUI messages, but even that seems more complicated. Is there a way to accomplish what I am doing without winmove but still has No unnecessary redrawing No looping for repaint messages Drawing on hidden objects Because of this sites known lust for code, I am providing the following working code, and two .pngs. The code is simplified, but represents a status bar indicator which is either Red, Green and either Hidden or Not Hidden. The Random generator is just used to simulate the various combinations and sequences of states that can occur. Thanks! expandcollapse popup#include <GUIConstantsEx.au3> #include <WinAPIGdi.au3> #include <WindowsConstants.au3> #include <WinAPIShPath.au3> #include <WinAPIFiles.au3> #include <WinAPI.au3> #Include <GDIPlus.au3> Local $statusBar, $sGraphic SRandom(@MSEC) _GDIPlus_Startup() Local $runningImage=_GDIPlus_ImageLoadFromFile("green.png") Local $stoppedImage=_GDIPlus_ImageLoadFromFile("red.png") CreateStatusBar() DrawStatusBar($stoppedImage) Do Local $isRunning=Random(False,True,1) If $isRunning Then DrawStatusBar($runningImage) Else DrawStatusBar($stoppedImage) EndIf Local $isVisible=Random(False,True,1) If $isVisible Then WinMove($statusBar, "", 0, 0) Else WinMove($statusBar, "", -10000, -10000) EndIf Sleep(1000) Until False ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Func CreateStatusBar() ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Local $tcolor=0x12356 $statusBar=GUICreate("STATUS", 100,100,0,0,$WS_POPUP,BitOr($WS_EX_LAYERED,$WS_EX_TOPMOST)) $sGraphic=_GDIPlus_GraphicsCreateFromHWND($statusBar) _WinAPI_SetLayeredWindowAttributes($statusBar, $tcolor,255) GUISetState(@SW_SHOWNA, $statusBar) EndFunc ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Func DrawStatusBar($image) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Static Local $lastImage="" If $image=$lastImage Then Return _GDIPlus_GraphicsClear($sGraphic,0xFF123456) _GDIPlus_GraphicsDrawImageRect($sGraphic,$image,0,0,100,100) $lastImage=$image EndFunc Edited October 12, 2020 by JockoDundee Code hard, but don’t hard code... 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