I have the following code that gives me a window that is transparent and interacts with the window below. How can I lock it to the top layer? I have tried SetWindowPos() but then I get a top most window with no transparency.
def createWindow(width, height, transparentBG):
pygame.init()
os.environ['SDL_VIDEO_CENTERED'] = '2'
window = pygame.display.set_mode((width, height)) # game window
pygame.display.set_caption("recticle") # title
background = (0, 255, 0)
if transparentBG:
hwnd = pygame.display.get_wm_info()["window"]
win32gui.SetWindowLong(hwnd, win32con.GWL_EXSTYLE,
win32gui.GetWindowLong(hwnd, win32con.GWL_EXSTYLE) |
win32con.WS_EX_LAYERED)
win32gui.SetLayeredWindowAttributes(hwnd, , 0, win32con.LWA_COLORKEY)
return window
def main():
global RUNNING
background = (0, 255, 0)
window = createWindow(1920,1080, True)
testImage = loadImage("customRect.bmp", (0,0))
while RUNNING:
window.fill(background) #fill background to transparency colour
for event in pygame.event.get():
if event.type == pygame.QUIT:
RUNNING = False
drawImage(window, testImage, (0,0))
#update window
pygame.display.update() #update window
Any help or suggestions appreciated, I have had a look around stack and I have code that sets a top layer window and does all described but it only displays text with win32api drawText function. I dont mind using this but I am not sure how to use a custom draw to display an image. I have tried saving out as a bitmap but again loosing transparency...
This is a non production app for me at home on a windows operating system. It is literally to draw a custom crosshair over a game window as I can see the one a game provides.
If anything is forgotten lemme know so I can edit.