Home > front end >  python ctypes does not show console
python ctypes does not show console

Time:04-13

I want to hide the console and show. But after I hid it does not show

ctypes.windll.user32.ShowWindow(ctypes.windll.user32.FindWindowW(None, "L"), 1 if click_thread.hide_status else 0 )

CodePudding user response:

Make sure to fully define the .argtypes and .restype of each function you use. ctypes defaults aren't always best. Below works:

import ctypes as ct
from ctypes import wintypes as w

SW_HIDE = 0
SW_SHOW = 5

dll = ct.WinDLL('user32')
# BOOL ShowWindow(HWND hWnd, int nCmdShow);
dll.ShowWindow.argtypes = w.HWND, ct.c_int
dll.ShowWindow.restype = w.BOOL
# HWND FindWindowW(LPCWSTR lpClassName, LPCWSTR lpWindowName);
dll.FindWindowW.argtypes = w.LPCWSTR, w.LPCWSTR
dll.FindWindowW.restype = w.HWND

h = dll.FindWindowW(None, 'Console')
dll.ShowWindow(h, SW_HIDE)
input(': ')
dll.ShowWindow(h, SW_SHOW)
  • Related