当前位置: 动力学知识库 > 问答 > 编程问答 >

Hide Windows start orb in python (3.2)

问题描述:

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)

网友答案:

You can get a handle to the start orb using FindWindowEx.

user32 = ctypes.WinDLL('user32')

user32.FindWindowExW.restype = wintypes.HWND
user32.FindWindowEx.argtypes = (
   wintypes.HWND,    # hwndParent
   wintypes.HWND,    # hwndChildAfter
   wintypes.LPCWSTR, # lpszClass
   wintypes.LPCWSTR) # lpszWindow

start_atom = wintypes.LPCWSTR(0xC017) # i.e. MAKEINTATOM(...)
hStart = user32.FindWindowExW(None, None, start_atom, None)

Then you can use ShowWindow or SetWindowPos to hide the orb.


The complete code of a working version is:

import ctypes
from ctypes import wintypes

user32 = ctypes.WinDLL("user32")

TOGGLE_UNHIDEWINDOW = 0x40
TOGGLE_HIDEWINDOW   = 0x80

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

user32.SetWindowPos.restype = wintypes.BOOL
user32.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

user32.FindWindowExW.restype = wintypes.HWND
user32.FindWindowExW.argtypes = (
   wintypes.HWND,    # hwndParent
   wintypes.HWND,    # hwndChildAfter
   wintypes.LPCWSTR, # lpszClass
   wintypes.LPCWSTR) # lpszWindow

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

def hide_taskbar():
    handleW1 = user32.FindWindowW(u"Shell_traywnd", u"")
    user32.SetWindowPos(handleW1, 0, 0, 0, 0, 0, TOGGLE_HIDEWINDOW)
    hStart = user32.FindWindowExW(None, None, start_atom, None)
    user32.SetWindowPos(hStart, 0, 0, 0, 0, 0, TOGGLE_HIDEWINDOW)

def unhide_taskbar():
    handleW1 = user32.FindWindowW(u"Shell_traywnd", u"")
    user32.SetWindowPos(handleW1, 0, 0, 0, 0, 0, TOGGLE_UNHIDEWINDOW)
    hStart = user32.FindWindowExW(None, None, start_atom, None)
    user32.ShowWindow(hStart, 3)

And then:

hide_taskbar()
unhide_taskbar()
分享给朋友:
您可能感兴趣的文章:
随机阅读: