def shell__open_start_menu(show_taskbar):
# Find the task bar window
taskbar_hwnd = windll.user32.FindWindowW("Shell_TrayWnd", None)
if taskbar_hwnd is None or 0 == taskbar_hwnd:
raise WinError()
taskbar_size = wintypes.RECT()
windll.user32.GetWindowRect(taskbar_hwnd, byref(taskbar_size))
# Find the process ID of the taskbar window.
taskbar_pid = wintypes.DWORD()
windll.user32.GetWindowThreadProcessId(taskbar_hwnd, byref(taskbar_pid))
triggered_start = [False]
# Find the "Start" button in the taskbar.
def child_window_callback(hwnd, lparam):
class_buff = create_unicode_buffer(256)
length = windll.user32.GetClassNameW(hwnd, class_buff, 256)
if length <= 0:
class_buff = None
else:
class_buff = class_buff.value[:length]
length = windll.user32.GetWindowTextLengthW(hwnd)
if length > 0:
title_buff = create_unicode_buffer(length + 1)
windll.user32.GetWindowTextW(hwnd, title_buff, length + 1)
print("DEBUG - Inspecting {0} | {2} = {1}".format(hwnd, title_buff.value, class_buff))
if title_buff.value == "Start":
# Found the window
print("DEBUG sending Click message")
# Attach our thread input to the start button, so we can send it a message.
current_thread_id = windll.kernel32.GetCurrentThreadId()
thread_process_id = windll.user32.GetWindowThreadProcessId(hwnd, None)
m_res = windll.user32.AttachThreadInput(thread_process_id, current_thread_id, True)
m_res = windll.user32.SendMessageW(hwnd, WM_LBUTTONDOWN, MK_LBUTTON, 0)
if m_res == 0:
# Don't look anymore
triggered_start[0] = True
return False
else:
try:
print("<<ERROR pressing start button>>")
raise WinError()
except OSError:
import traceback
traceback.print_exc()
return True
callback_type = CFUNCTYPE(wintypes.BOOL, wintypes.HWND, wintypes.LPARAM)
callback_ptr = callback_type(child_window_callback)
print("DEBUG Iterating over windows for taskbar pid {0}".format(taskbar_pid.value))
windll.user32.EnumChildWindows(taskbar_hwnd, callback_ptr, 0)
# if not triggered_start[0]:
# raise OSError("Could not find start button")
评论列表
文章目录