Skip to content

Instantly share code, notes, and snippets.

@ethanhs
Created September 22, 2015 03:04
Show Gist options
  • Save ethanhs/790ac1b0c28a1193ef31 to your computer and use it in GitHub Desktop.
Save ethanhs/790ac1b0c28a1193ef31 to your computer and use it in GitHub Desktop.
Needs IronPython!! As asked for. This gets the names, and rects of the tiles on your start screen. I also found that it grabs text of a start tile. Yay accessibility!
import ctypes
from ctypes import wintypes
#import pyscreenshot as ImageGrab
titles=[]
def GetHWND(self, hwnd, lParam):
if IsWindowVisible(hwnd):
length = GetWindowTextLength(hwnd)
buff = ctypes.create_unicode_buffer(length + 1)
GetWindowText(hwnd, buff, length + 1)
if buff.value != u'':
titles.append(hwnd)
else:
pass
return True
EnumChildren = ctypes.windll.user32.EnumChildWindows
import clr
clr.AddReference('UIAutomationClient')
clr.AddReference('UIAutomationTypes')
from System.Windows.Automation import *
import System
EnumWindowsProc = ctypes.WINFUNCTYPE(ctypes.c_bool, ctypes.POINTER(ctypes.c_int),
ctypes.POINTER(ctypes.c_int))
def GrabStart(hwnd):
Rect=wintypes.RECT()
ctypes.windll.user32.GetWindowRect(hwnd, ctypes.byref(Rect))
win_box=(Rect.left,Rect.top,Rect.right,Rect.bottom)
_hwnd=System.IntPtr(hwnd)
_mainWindow=AutomationElement.FromHandle(_hwnd)
start_list=None
Lists=_mainWindow.FindAll(TreeScope.Children, PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.List))
for _list in Lists:
name=_list.GetCurrentPropertyValue(AutomationElement.NameProperty)
if "Start Apps" in name:
start_list=_list
if start_list:
groups=start_list.FindAll(TreeScope.Descendants, PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.ListItem))
print("========================")
for tile in groups:
print(tile.GetCurrentPropertyValue(AutomationElement.NameProperty))
print("-------------")
print(tile.GetCurrentPropertyValue(AutomationElement.BoundingRectangleProperty))
print("========================")
else:
print("no start list found")
while 1:
fore=ctypes.windll.user32.GetForegroundWindow()
name_buff= ctypes.create_unicode_buffer(6)
ctypes.windll.user32.GetWindowTextW(fore,name_buff,6)
name=name_buff.value
if name!=u"Start":
continue
class_buff=ctypes.create_unicode_buffer(28)
ctypes.windll.user32.GetClassNameW(fore, class_buff,28)
class_name=class_buff.value
if class_name!= u"Windows.UI.Core.CoreWindow":
continue
else:
GrabStart(fore)
break
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment