Make a window transparent using Win32?

扶醉桌前 提交于 2019-11-28 10:27:02
PabloG

SetLayeredWindowsAttributes example:

import win32gui
import win32con
import winxpgui
import win32api
import subprocess
import time

subprocess.Popen("notepad.exe", shell=True)
time.sleep(1)
hwnd = win32gui.FindWindow(None, "New file - metapad")  ## The caption of my empty notepad (MetaPad)

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)

You can use the SetLayeredWindowAttributes WIN32 API function for creating transparent windows:

BOOL WINAPI SetLayeredWindowAttributes(
  __in  HWND hwnd,
  __in  COLORREF crKey,
  __in  BYTE bAlpha,
  __in  DWORD dwFlags
);

Here is a code sample that you can use for wrapping WIN32 API functions for setting transparency.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!