Jump to content

I’m using WinMove($w,””,-10000,-10000) instead of @SW_HIDE, but I know it’s wrong


Recommended Posts

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

  1. No unnecessary redrawing 
  2. No looping for repaint messages
  3. 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!

#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

 

EC83D13D-908F-478E-9017-322C1D04BDD6.png

DD5AF7E9-D8C3-4373-9AE8-70A766A8951B.png

Edited by JockoDundee

Code hard, but don’t hard code...

Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...