Page 1 of 1

How NOT to display AHK icon on the taskbar when script is running?

Posted: 29 Mar 2024, 19:45
by slishnevsky
How NOT to display AHK icon on the taskbar when script is running?

image.png
image.png (331.41 KiB) Viewed 186 times

On this screenshot the script is running, and AHK icon is displayed by default in the taskbar, thus intercepting a focus (when you are playing a fullscreen game, for example).

Is there any way NOT to display it?

Is there any way for AHK NOT to intercept focus, so that the PC will not throw me out of the game?

Thanks.

Re: How NOT to display AHK icon on the taskbar when script is running?

Posted: 29 Mar 2024, 20:59
by mikeyww
Disables the showing of a tray icon.
Source: #NoTrayIcon - Syntax & Usage | AutoHotkey v2

Re: How NOT to display AHK icon on the taskbar when script is running?

Posted: 29 Mar 2024, 21:06
by gregster
The taskbar button can be hidden by using the ToolWindow option for GUIs:

Code: Select all

MyGui.Opt("+ToolWindow")
https://www.autohotkey.com/docs/v2/lib/Gui.htm#Opt wrote:ToolWindow: Provides a narrower title bar but the window will have no taskbar button. This always hides the maximize and minimize buttons, regardless of whether the WS_MAXIMIZEBOX and WS_MINIMIZEBOX styles are present.

The owner option could be another solution:

Code: Select all

MyGui.Opt("+Owner")  ; Make the GUI owned by the script's main window to prevent display of a taskbar button.

Re: How NOT to display AHK icon on the taskbar when script is running?

Posted: 29 Mar 2024, 21:23
by mikeyww
An example is below.

Code: Select all

#Requires AutoHotkey v2.0

F3:: {
 If '' = t := getTimerInterval()
      ToolTip
 Else ToolTip '===> ' t ' <==='
}

getTimerInterval() {
 g := Gui('+ToolWindow', 'Timer'), g.SetFont('s10')
 g.AddText , 'Set timer interval (in minutes)'
 ed := g.AddEdit('w300')
 g.AddButton('w300 Default', 'OK').OnEvent('Click', (btn, info) => (txt := ed.Text, btn.Gui.Destroy()))
 g.OnEvent('Escape', (gui) => gui.Destroy())
 g.OnEvent('Close' , (gui) => gui.Destroy())
 txt := '', g.Show()
 WinWaitClose g
 Return txt
}

Re: How NOT to display AHK icon on the taskbar when script is running?

Posted: 29 Mar 2024, 21:46
by Seven0528
 Please press F5 to open the window.
I'm not sure if there's a better trick, but I did my best...
No matter how much I think about it, using MyGui.Opt("+Owner") seems like a cleaner approach.
(To ensure that the ownership relationship of the window remains unchanged, refer to my second example using OnMessage.)

Code: Select all

#Requires AutoHotkey v2.0
#SingleInstance
myGui:=gui("+AlwaysOnTop +Owner")
myEdit:=myGui.Add("Edit", "w300 r10")
F5::  {
    myGui.show("NoActivate")
}

Code: Select all

#Requires AutoHotkey v2.0
#SingleInstance
onMessage(0x0201,WM_LBUTTONDOWN)
onMessage(0x00A1,WM_NCLBUTTONDOWN)
myGui:=gui("+AlwaysOnTop +E" WS_EX_NOACTIVATE:=0x08000000)
myEdit:=myGui.Add("Edit", "w300 r10")
F5::  {
    myGui.show("NoActivate")
}

WM_LBUTTONDOWN(wParam, lParam, Msg, hWnd)    {
    static GA_ROOT:=2
    switch (rootWnd:=dllCall("User32.dll\GetAncestor", "Ptr",hWnd, "UInt",GA_ROOT, "Ptr"))
    {
        case myGui.Hwnd:
            if (dllCall("User32.dll\GetForegroundWindow", "Ptr")!==rootWnd)
                dllCall("User32.dll\SetForegroundWindow", "Ptr",rootWnd, "Ptr")
    }
}
WM_NCLBUTTONDOWN(wParam, lParam, Msg, hWnd)    {
    switch (hWnd)
    {
        case myGui.Hwnd:
            if (dllCall("User32.dll\GetForegroundWindow", "Ptr")!==hWnd)
                dllCall("User32.dll\SetForegroundWindow", "Ptr",hWnd, "Ptr")
    }
}
20240330_114724.png
20240330_114724.png (5.48 KiB) Viewed 149 times