While I am trying to make a window's background transparent using win32gui, I am using following code.
hwnd = win32gui.FindWindow(None, "My App Name")
win32gui.SetWindowLong (hwnd, win32con.GWL_EXSTYLE, win32gui.GetWindowLong (hwnd, win32con.GWL_EXSTYLE ) | win32con.WS_EX_LAYERED )
winxpgui.SetLayeredWindowAttributes(hwnd, win32api.RGB(0,0,0), 180, win32con.LWA_ALPHA)
But I am getting an error as
pywintypes.error: (87, 'SetLayeredWindowAttributes', 'The parameter is incorrect.')
I tried different documentation, but could not really find anything very specific or helpful. Would anyone like to give some suggestion or code snippet or idea to fix the issue.
Thanks in advance.
Please double check
if hwnd is not None
. At this answer such code works: Make a window transparent using Win32? All other parameters are constants. Maybe you needFindWindowEx
instead ofFindWindow
.Ex
version works across process boundaries, whileFindWindow
is for this process only.EDIT1: See this answer: https://stackoverflow.com/a/44276373/3648361 It tells that
SetLayeredWindowAttributes()
only works on windows that have theWS_EX_LAYERED
attribute. But fortunately it can be set bySetWindowLongPtr()
.