Last active
July 28, 2016 22:05
-
-
Save eruffaldi/1dce5b303544a90f8b2bf940f6591bde to your computer and use it in GitHub Desktop.
Always keep window on bottom in Python for Windows and pygame
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# pygame always background | |
# Emanuele Ruffaldi 2016 | |
import sys, pygame | |
import win32gui, win32con | |
import sys, ctypes | |
class WINDOWPOS(ctypes.Structure): | |
_fields_ = [ | |
('hwnd', ctypes.c_ulong), | |
('hwndInsertAfter', ctypes.c_ulong), | |
('x', ctypes.c_int), | |
('y', ctypes.c_int), | |
('cx', ctypes.c_int), | |
('cy', ctypes.c_int), | |
('flags', ctypes.c_ulong) | |
] | |
def mywndproc(oldWndProc, hWnd, msg, wParam, lParam): | |
if msg == win32con.WM_WINDOWPOSCHANGING: | |
pos = WINDOWPOS.from_address(lParam) | |
pos.hwndInsertAfter = win32con.HWND_BOTTOM | |
elif msg == win32con.WM_DESTROY: | |
win32gui.SetWindowLong(hWnd,win32con.GWL_WNDPROC,oldWndProc) | |
return win32gui.CallWindowProc(oldWndProc, hWnd, msg, wParam, lParam) | |
def main(): | |
pygame.init() | |
size = width, height = 320, 240 | |
speed = [2, 2] | |
black = 0, 0, 0 | |
screen = pygame.display.set_mode(size) | |
info = pygame.display.get_wm_info() #retriving dei dati dell'oggetto display | |
HWND = info["window"] #quello che ci serve la voce window. | |
win32gui.SetWindowPos(HWND,win32con.HWND_BOTTOM, 0, 0, 0, 0,win32con.SWP_NOMOVE + win32con.SWP_NOSIZE) #comunicazione al sistema operativo della posizione della finestra. | |
# super trick to avoid global | |
oldWndProc = [None] | |
oldWndProc[0] = win32gui.SetWindowLong(HWND,win32con.GWL_WNDPROC,lambda hWnd,msg,wParam,lParam: mywndproc(oldWndProc[0],hWnd,msg,wParam,lParam)) | |
while 1: | |
for event in pygame.event.get(): | |
if event.type == pygame.QUIT: | |
sys.exit(0) | |
screen.fill(black) | |
pygame.display.flip() | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment