简体   繁体   中英

Hide taskbar using Python in Windows XP

Is there a way to hide the Windows taskbar using Python? If not- is there a way to disable or to re-size and lock it using the registry?

Microsoft support document KB186119 demonstrates how to hide the taskbar using Visual Basic. Here's a ctypes version for Python, but using ShowWindow instead of SetWindowPos :

import ctypes
from ctypes import wintypes

user32 = ctypes.WinDLL("user32")

SW_HIDE = 0
SW_SHOW = 5

user32.FindWindowW.restype = wintypes.HWND
user32.FindWindowW.argtypes = (
    wintypes.LPCWSTR, # lpClassName
    wintypes.LPCWSTR) # lpWindowName

user32.ShowWindow.argtypes = (
    wintypes.HWND, # hWnd
    ctypes.c_int)  # nCmdShow

def hide_taskbar():
    hWnd = user32.FindWindowW(u"Shell_traywnd", None)
    user32.ShowWindow(hWnd, SW_HIDE)

def unhide_taskbar():
    hWnd = user32.FindWindowW(u"Shell_traywnd", None)
    user32.ShowWindow(hWnd, SW_SHOW)

Just to add to @eryksun answer, if you try this in windows 7 you would still get to see the start button... I did i little tweek in his code to

1) Hide the start button (with the hWnd_btn_start = user32.FindWindowW(u"Button", 'Start') )

2) Now you can pass Hide (default behaviour) or Show to the command line to show or hide the taskbar.

import ctypes
import sys

from ctypes import wintypes

user32 = ctypes.WinDLL("user32")

SW_HIDE = 0
SW_SHOW = 5

HIDE = True;

for idx,item in enumerate(sys.argv):
    print(idx, item);
    if (idx == 1 and item.upper() == 'SHOW'):
        HIDE = False;

#HIDE = sys.argv[1] = 'HIDE' ? True : False;


user32.FindWindowW.restype = wintypes.HWND
user32.FindWindowW.argtypes = (
    wintypes.LPCWSTR, # lpClassName
    wintypes.LPCWSTR) # lpWindowName

user32.ShowWindow.argtypes = (
    wintypes.HWND, # hWnd
    ctypes.c_int)  # nCmdShow

def hide_taskbar():
    hWnd = user32.FindWindowW(u"Shell_traywnd", None)
    user32.ShowWindow(hWnd, SW_HIDE)

    hWnd_btn_start = user32.FindWindowW(u"Button", 'Start')
    user32.ShowWindow(hWnd_btn_start, SW_HIDE)

def unhide_taskbar():
    hWnd = user32.FindWindowW(u"Shell_traywnd", None)
    user32.ShowWindow(hWnd, SW_SHOW)

if (HIDE):
    hide_taskbar();
else:
    unhide_taskbar();

Usage: To show the taskbar python hideTaskBar.py Show To hide the taskbar python hideTaskBar.py Hide

Again, many thanks to @eryksun

Here's how to do it in VisualBasic: http://support.microsoft.com/kb/186119

Here's a similar thread: How to programmatically move Windows taskbar?

You could probably do it with PyWinAuto, but that would move your mouse around the screen. Not sure if that would be an issue for you or not.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM