Himanshu P
Himanshu P

Reputation: 9945

creating a window using AHK that is semi transparent

Using AutoHotkey, I am trying to create a window which is semi transparent.

Here is the code I have so far:

WinTitle := "mywin"
Gui, New, , %WinTitle%
Gui, Color, 0x000000,
WinSet, Transparent, 150, %WinTitle%          ; THIS NEEDS FIXING?
w := A_ScreenWidth/4
h := A_ScreenHeight/4
Gui, Show, x100 y100 w%w% h%h%

This does create a black window, but it is not semi transparent. Any help would be appreciated.

Upvotes: 0

Views: 674

Answers (1)

0x464e
0x464e

Reputation: 6499

The window doesn't exist before you show it.
So, you have to set the transparency after you show the window.

Gui, +hwnd_hwnd
Gui, Color, 0x000000

w := A_ScreenWidth / 4
h := A_ScreenHeight / 4
Gui, Show, % "x100 y100 w" w " h" h

WinSet, Transparent, 150, % "ahk_id " _hwnd

Misc improvements:

  • Not using Gui, New.
    (It's fine to use, but be sure to know what you're using it for, and how to use it, to avoid tricky problems such as this one)
  • Refer to the window using hwnd.
    Hwnd can be retrieved via e.g +hwnd(docs) option.
  • Ditched the legacy syntax in favor of the modern expression syntax.

Upvotes: 1

Related Questions