For ctypes.windll
to work, you have to first configure the types of the function's arguments (IIRC you don't have to this if you're on a 32-bit machine).
So your code should look like this:
import pygame
import ctypes
from ctypes import wintypes
def main():
pygame.init()
screen = pygame.display.set_mode((400, 200))
hwnd = pygame.display.get_wm_info()['window']
user32 = ctypes.WinDLL("user32")
user32.SetWindowPos.restype = wintypes.HWND
user32.SetWindowPos.argtypes = [wintypes.HWND, wintypes.HWND, wintypes.INT, wintypes.INT, wintypes.INT, wintypes.INT, wintypes.UINT]
user32.SetWindowPos(hwnd, -1, 600, 300, 0, 0, 0x0001)
while True:
for event in pygame.event.get():
if event.type == pygame.QUIT:
return
screen.fill('grey')
pygame.display.flip()
if __name__ == '__main__':
main()
I prefer to use the pywin32 package instead, because the functions just work and the constants you need are available.
import pygame
import win32gui
import win32con
def main():
pygame.init()
screen = pygame.display.set_mode((400, 200))
hwnd = win32gui.GetForegroundWindow()
win32gui.SetWindowPos(hwnd, win32con.HWND_TOPMOST, 600, 300, 0, 0, win32con.SWP_NOSIZE)
while True:
for event in pygame.event.get():
if event.type == pygame.QUIT:
return
screen.fill('grey')
pygame.display.flip()
if __name__ == '__main__':
main()
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…