0

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 )
Michael Butscher
  • 10,028
  • 4
  • 24
  • 25
quessy-dev
  • 15
  • 1
  • 4
  • 1
    What's *"L"*? Make sure to check the return values for functions. And most important read first: [\[SO\]: C function called from Python via ctypes returns incorrect value (@CristiFati's answer)](https://stackoverflow.com/questions/58610333/c-function-called-from-python-via-ctypes-returns-incorrect-value/58611011#58611011). – CristiFati Apr 09 '22 at 19:54
  • "L" is name of window – quessy-dev Apr 10 '22 at 12:14

1 Answers1

0

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)
Mark Tolonen
  • 166,664
  • 26
  • 169
  • 251