添加链接
link管理
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接
Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

for example at first you have to find hwnd of skype

hwnd = win32gui.FindWindow(None, 'skype')

and than all his child windows and their titles

child = ???

any idea?

You will have to find hwnd of your application, and then use this handle with EnumChildWindows. I extended example code with it. Once you get application hwnd you can enumerate only its windows. When you give 0 as hwnd to EnumChildWindows you will get handles of all runing windows. Add some prints to my code and check it!

Extended code:

import win32gui
MAIN_HWND = 0
def is_win_ok(hwnd, starttext):
    s = win32gui.GetWindowText(hwnd)
    if s.startswith(starttext):
            print s
            global MAIN_HWND
            MAIN_HWND = hwnd
            return None
    return 1
def find_main_window(starttxt):
    global MAIN_HWND
    win32gui.EnumChildWindows(0, is_win_ok, starttxt)
    return MAIN_HWND
def winfun(hwnd, lparam):
    s = win32gui.GetWindowText(hwnd)
    if len(s) > 3:
        print("winfun, child_hwnd: %d   txt: %s" % (hwnd, s))
    return 1
def main():
    main_app = 'EditPlus'
    hwnd = win32gui.FindWindow(None, main_app)
    print hwnd
    if hwnd < 1:
        hwnd = find_main_window(main_app)
    print hwnd
    if hwnd:
        win32gui.EnumChildWindows(hwnd, winfun, None)
main()
                im a little bit confused here ... when i turn on an aplication it returns main hwnd and tree childs despite the fact there are no child windows and when the application isnt running it prints far too many results when there shouldnt be any btw is there a way to determinate whitch window is running under whitch process?
– nabizan
                Jun 1, 2010 at 11:56
        

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question. Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.