Example #1
0
def topWindow(hwnd):
    hwndList = [hwnd]
    while True:
        hwnd = getParentWindow(hwnd)
        if not hwnd:
            break
        hwndList.append(hwnd)
    topHwnd = None
    while len(hwndList) > 0:
        hwnd = hwndList.pop()
        if not isRawWindow(hwnd):
            topHwnd = hwnd
            break
    if not topHwnd:
        return False
    place = autoutil.tryExcept(win32gui.GetWindowPlacement, topHwnd)
    if autoutil.isExcept(place):
        return False
    if place[1] == win32con.SW_SHOWMINIMIZED and not showWindow(topHwnd):
        return False
    hwnd = win32gui.GetForegroundWindow()
    if hwnd == topHwnd:
        return True
    rst = autoutil.tryExcept(win32gui.SetForegroundWindow, topHwnd)
    if not autoutil.isExcept(rst):
        return True
    return getWindowClass(hwnd) == 'Progman' and getWindowText(hwnd) == 'Program Manager'
Example #2
0
def getProcessGDI(pid):
    proc = autoutil.tryExcept(win32api.OpenProcess, win32con.PROCESS_ALL_ACCESS, 0, pid)
    if autoutil.isExcept(proc):
        return
    gdi = autoutil.tryExcept(win32process.GetGuiResources, proc.handle, win32con.GR_GDIOBJECTS)
    autoutil.tryExcept(proc.close)
    if not autoutil.isExcept(gdi):
        return gdi
Example #3
0
def getUserProcessIds(user):
    rst, count = autoutil.queryWmi('select * from Win32_Process')
    pidList = []
    for i in range(count):
        owner = autoutil.tryExcept(rst[i].ExecMethod_, 'GetOwner')
        if not autoutil.isExcept(owner) and owner.User and owner.User.lower() == user.lower():
            pidList.append(rst[i].ProcessId)
    return pidList
Example #4
0
 def __getChildWindows__(hwnd, hwnds):
     hwnds.add(hwnd)
     rst = set()
     hcwnd = autoutil.tryExcept(win32gui.GetWindow, hwnd or win32gui.GetDesktopWindow(), win32con.GW_CHILD)
     while hcwnd and not autoutil.isExcept(hcwnd) and hcwnd not in hwnds:
         __fillWindowAttrs__(hcwnd, rst)
         if hwnd:
             rst.update(__getChildWindows__(hcwnd, hwnds))
         hcwnd = autoutil.tryExcept(win32gui.GetWindow, hcwnd, win32con.GW_HWNDNEXT)
     return rst
Example #5
0
 def __findChildWindows__(hwnd, hwnds):
     hwnds.add(hwnd)
     rst = set()
     hcwnd = autoutil.tryExcept(win32gui.FindWindowEx, hwnd, None, None, None)
     while hcwnd and not autoutil.isExcept(hcwnd) and hcwnd not in hwnds:
         __fillWindowAttrs__(hcwnd, rst)
         if hwnd:
             rst.update(__findChildWindows__(hcwnd, hwnds))
         hcwnd = autoutil.tryExcept(win32gui.FindWindowEx, hwnd, hcwnd, None, None)
     return rst
Example #6
0
def createProcess(cmd, wait = False):
    if wait:
        proc = autoutil.tryExcept(subprocess.Popen, cmd, stdout = subprocess.PIPE, stderr = subprocess.PIPE)
    else:
        proc = autoutil.tryExcept(subprocess.Popen, cmd)
    if autoutil.isExcept(proc):
        print cmd
        print 'createProcess 发生异常: %s' % str(traceback.format_exc())
        return
    if not wait:
        return proc.pid
    proc.communicate()
Example #7
0
def setWindowText(hwnd, text):
    rst = autoutil.tryExcept(win32gui.SendMessageTimeout, hwnd, win32con.WM_SETTEXT, 0, text, win32con.SMTO_ABORTIFHUNG, 30)
    return not autoutil.isExcept(rst)
Example #8
0
def getWindowRect(hwnd):
    rect = autoutil.tryExcept(win32gui.GetWindowRect, hwnd)
    if not autoutil.isExcept(rect):
        return rect
Example #9
0
def getParentWindow(hwnd):
    hwnd = autoutil.tryExcept(win32gui.GetParent, hwnd)
    if not autoutil.isExcept(hwnd):
        return hwnd
Example #10
0
 def __clickWindowFor__(hwnd, cond, clkCfg):
     rst = cond.do()
     if not rst or autoutil.isExcept(rst):
         clickWindow(hwnd, clkCfg)
     return rst
Example #11
0
def getCmdLineById(pid):
    rst,count= autoutil.queryWmi('select * from Win32_Process where ProcessId=%s' % pid)
    if count:
        cmdLine = autoutil.tryExcept(rst[0].CommandLine.encode, sys.getfilesystemencoding())
        if not autoutil.isExcept(cmdLine):
            return cmdLine
Example #12
0
def getProcessNameById(pid):
    rst, count = autoutil.queryWmi('select * from Win32_Process where ProcessId = %d' % pid)
    if count:
        pname = autoutil.tryExcept(rst[0].Name.encode, sys.getfilesystemencoding())
        if not autoutil.isExcept(pname):
            return pname