How to fade out a Gui with function + variable?

Get help with using AutoHotkey and its commands and hotkeys
User avatar
Scr1pter
Posts: 492
Joined: 06 Aug 2017, 08:21
Location: Germany

How to fade out a Gui with function + variable?

15 Sep 2018, 15:16

Hello,

I created a script which consists of a Gui with a picture inside of it.
Additionally, there is also a fade-in and a fade-out effect which works perfectly.

I use this Gui in scripts which take some seconds until they have finished.
(Just to inform the user that a script is being run.)

By using the include function, I add my Gui script into any other script.
It looks like this:

Code: Select all

#SingleInstance force
;Info-Meldungen
global d = 5 ; Verzögerung in ms
global bild ; Entweder Start, Ende oder Abbruch (Bild wird in der Gui angezeigt)

Start()
{
  bild = Start.png
  Gui_mit_Effekt()
}

Ende()
{
  bild = Ende.png
  SoundPlay, %A_WinDir%\Media\tada.wav
  Sleep, d
  Gui_mit_Effekt()
}

Gui_mit_Effekt()
{
  Gui +E0x20 -Caption +LastFound +ToolWindow +AlwaysOnTop ; Durchklickbar, rahmenlos, zuletzt gefunden, kein Taskleistensymbol, immer im Vordergrund
  Gui, Add, Picture, x0 y0 w500 h250, %A_ScriptDir%\pics\Info-Meldungen\%bild% ; Vorgang erfolgreich-Bild
  Gui, Show, w500 h250 hide, Ende
  fade := 1 ; Variable für Einblend bzw. Ausblend-Effekt
  Loop 25
  {
    fade := fade + 9 ; Einblend-Effekt
    WinSet, Transparent, %fade% ; Pinke Farbe komplett rausfiltern, den Rest einblenden  0xFC62FD 
    if fade = 10 ; Beim ersten Durchgang:
    {
      WinShow, Ende ; Gui anzeigen
    }
    Sleep, 10
  }
  Sleep, 800
  Loop 25
  {
    fade := fade - 9 ; Ausblend-Effekt
    WinSet, Transparent, %fade% ; Pinke Farbe komplett rausfiltern, den Rest einblenden  0xFC62FD 
    if fade = 217 ; Beim ersten Durchgang:
    {
      WinShow, Ende ; Gui anzeigen
    }
    Sleep, 10
  }
}
I call it from another script by this way:

Code: Select all

#SingleInstance force
;Info-Meldungen-Test
#include Info-Meldungen.ahk
global d = 5 ; Verzögerung in ms

F1::
Start()
return

F2::
Ende()
return
When I press F1, the Start image appears but starts disappearing after 800 ms, which is logical.
I would like that it stays until it gets the information/command to disappear.

I think I will need to include a variable which tells the Start() function when to fade out.
Something like this:

Code: Select all

#SingleInstance force
;Info-Meldungen
global d = 5 ; Verzögerung in ms
global bild ; Entweder Start, Ende oder Abbruch (Bild wird in der Gui angezeigt)

Start(mode)
{
  bild = Start.png
  Gui_mit_Effekt(mode)
}

Ende(mode)
{
  bild = Ende.png
  SoundPlay, %A_WinDir%\Media\tada.wav
  Sleep, d
  Gui_mit_Effekt(mode)
}

Gui_mit_Effekt(mode)
{
  Gui +E0x20 -Caption +LastFound +ToolWindow +AlwaysOnTop ; Durchklickbar, rahmenlos, zuletzt gefunden, kein Taskleistensymbol, immer im Vordergrund
  Gui, Add, Picture, x0 y0 w500 h250, %A_ScriptDir%\pics\Info-Meldungen\%bild% ; Vorgang erfolgreich-Bild
  Gui, Show, w500 h250 hide, Ende
  fade := 1 ; Variable für Einblend bzw. Ausblend-Effekt
  if mode = 1
  {
    Loop 25
    {
      fade := fade + 9 ; Einblend-Effekt
      WinSet, Transparent, %fade% ; Pinke Farbe komplett rausfiltern, den Rest einblenden  0xFC62FD 
      if fade = 10 ; Beim ersten Durchgang:
      {
        WinShow, Ende ; Gui anzeigen
      }
      Sleep, 10
    }
  }
  if mode = 0
  {
    fade := 226
    Sleep, 800
    Loop 25
    {
      fade := fade - 9 ; Ausblend-Effekt
      WinSet, Transparent, %fade% ; Pinke Farbe komplett rausfiltern, den Rest einblenden  0xFC62FD 
      if fade = 217 ; Beim ersten Durchgang:
      {
        WinShow, Ende ; Gui anzeigen
      }
      Sleep, 10
    }
  }
}

Code: Select all

#SingleInstance force
;Info-Meldungen-Test
#include Info-Meldungen.ahk
global d = 5 ; Verzögerung in ms

F1::
Start(1)
return

F2::
Start(0)
return
In this case, it stays forever when pressing F1 (or better when Start() gets called with 1.
As soon as it gets called with a 0, it starts disappearing, but it looks weird.
- it disappears immediately without any effect
- then it appears again without any effect
- after this is starts disappearing, but it doesn't look as smooth as the first code.

Maybe it's just a small issue.
I realized that the fade value has to be set to 226 in the 2nd code, otherwise the script "forgets" it.
This is how it looks like:
Image


Regards
I'm not an expert, just an enthusiastic AutoHotkey user. 8-)
Please do not support cheaters!
Keyboard: Logitech G15 first generation - Mice: Logitech G9, G502, G602 - OS: Windows 7 Pro 64 Bit - AHK version: 1.1.29.00

Return to “Ask For Help”

Who is online

Users browsing this forum: ahketype, kadhri, Mipha, roysubs and 120 guests