Page 1 of 1

calling Win32 Functions in pythonscript

Posted: Tue Jul 25, 2006 3:01 pm
by thug

this is what i have in as a pythonscript (python editor)

Code: Select all

from win32gui import FindWindow

def SomeFunctionIWantToUse():

  strAString = ""

  hWnd = FindWindow("XYZApp", None)

  return strAString

but when I execute it I get this :-

Code: Select all

Python Script
Traceback (most recent call last):
  Python script "38", line 11, in ?
  Python script "38", line 7, in SomeFunctionIWantToUse
    hWnd = FindWindow("XYZApp", None)
error: (2, 'FindWindow', 'The system cannot find the file specified.')
how do i use FindWindow (or any win32 function) in a python script?

Posted: Tue Jul 25, 2006 3:17 pm
by Bitmonster
Well, you actually did it right. But FindWindow is not finding any window class with the value "XYZApp" and therefor (very pythonic) is raising an exception.

To catch such things, you have to use try/except blocks.

Posted: Tue Jul 25, 2006 3:24 pm
by thug
Nice one! :wink: