user-interfaceautohotkeyalways-on-top

How can I make options apply to a GUI in AHK?


I'm trying to make a simple script that shows and hides a small GUI over the "close" button on a window (in the top right of the screen). For some reason, the GUI is not applying any of the options I added (or subtracted). The options I want to apply are +LastFound +AlwaysOnTop +ToolWindow -Caption.

I have tried rearranging the code, named GUIs, and pausing the other script that I normally use.

Here is the entire script:

ShowWindow := false

#Persistent
#SingleInstance Force
#NoEnv
SetWorkingDir %A_ScriptDir%
SetBatchLines -1

Gui New, +LastFound +AlwaysOnTop +ToolWindow -Caption, Protect
    Winset, TransColor, F0F0F0 175

#+^CapsLock::
    ShowWindow:=!ShowWindow
    If (ShowWindow) {
        Gui Show, x1226 y0 w140 h10 NA Restore, Protect
    } Else {
        Gui Hide
    }
Return

Solution

  • What about:

    #Persistent
    #SingleInstance Force
    #NoEnv
    SetWorkingDir %A_ScriptDir%
    SetBatchLines -1
    
    #+^CapsLock::
        ShowWindow  :=  !ShowWindow
        Gui, +LastFound +AlwaysOnTop +ToolWindow -Caption
        Winset, TransColor, F0F0F0 175
    
        Gui, Add, Button, , Button
    
        Gui,% ShowWindow ? "Show" : "Destroy",% ShowWindow ? "x1226 y0 w140 h50" : "",% ShowWindow ? "Protect" : ""
    
    Return