Hide Windows start orb in python (3.2)

*爱你&永不变心* 提交于 2019-12-25 01:44:40

问题


I am creating a program that will replace the windows start menu in Python. I have managed to find a way to hide the taskbar as shown below but i can't find a way to hide the start orb(Windows button).

import ctypes
from ctypes import wintypes

FindWindow = ctypes.windll.user32.FindWindowA
FindWindow.restype = wintypes.HWND
FindWindow.argtypes = [
    wintypes.LPCSTR, #lpClassName
    wintypes.LPCSTR, #lpWindowName
]

SetWindowPos = ctypes.windll.user32.SetWindowPos
SetWindowPos.restype = wintypes.BOOL
SetWindowPos.argtypes = [
    wintypes.HWND, #hWnd
    wintypes.HWND, #hWndInsertAfter
    ctypes.c_int,  #X
    ctypes.c_int,  #Y
    ctypes.c_int,  #cx
    ctypes.c_int,  #cy
   ctypes.c_uint, #uFlags
] 

TOGGLE_HIDEWINDOW = 0x80
TOGGLE_UNHIDEWINDOW = 0x40

def hide_taskbar():
    handleW1 = FindWindow(b"Shell_traywnd", b"")
    SetWindowPos(handleW1, 0, 0, 0, 0, 0, TOGGLE_HIDEWINDOW)

def unhide_taskbar():
    handleW1 = FindWindow(b"Shell_traywnd", b"")
    SetWindowPos(handleW1, 0, 0, 0, 0, 0, TOGGLE_UNHIDEWINDOW)

回答1:


You can get a handle to the start orb using FindWindow with the class atom for the orb, 0xC017. Then use ShowWindow or SetWindowPos to hide the taskbar and the orb. For example:

import ctypes
from ctypes import wintypes

user32 = ctypes.WinDLL("user32")

SW_HIDE = 0
SW_SHOW = 5

START_ATOM = wintypes.LPCWSTR(0xC017) # i.e. MAKEINTATOM(...)

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():
    hWndTray = user32.FindWindowW(u"Shell_traywnd", None)
    user32.ShowWindow(hWndTray, SW_HIDE)
    hWndStart = user32.FindWindowW(START_ATOM, None)
    if hWndStart:
        user32.ShowWindow(hWndStart, SW_HIDE)

def unhide_taskbar():
    hWndTray = user32.FindWindowW(u"Shell_traywnd", None)
    user32.ShowWindow(hWndTray, SW_SHOW)
    hWndStart = user32.FindWindowW(START_ATOM, None)
    if hWndStart:
        user32.ShowWindow(hWndStart, SW_SHOW)


来源:https://stackoverflow.com/questions/16649425/hide-windows-start-orb-in-python-3-2

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!