python ctypes 不显示控制台
python ctypes does not show console
我想隐藏控制台并显示。但是我隐藏后不显示
ctypes.windll.user32.ShowWindow(ctypes.windll.user32.FindWindowW(None, "L"), 1 if click_thread.hide_status else 0 )
确保完整定义您使用的每个函数的 .argtypes
和 .restype
。 ctypes
默认值并不总是最好的。以下作品:
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)
我想隐藏控制台并显示。但是我隐藏后不显示
ctypes.windll.user32.ShowWindow(ctypes.windll.user32.FindWindowW(None, "L"), 1 if click_thread.hide_status else 0 )
确保完整定义您使用的每个函数的 .argtypes
和 .restype
。 ctypes
默认值并不总是最好的。以下作品:
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)