calling Win32 Functions in pythonscript

Do you have questions about writing plugins or scripts in Python? Meet the coders here.
Post Reply
thug
Plugin Developer
Posts: 64
Joined: Sat Jul 22, 2006 2:37 pm
Location: Australia

calling Win32 Functions in pythonscript

Post by thug » Tue Jul 25, 2006 3:01 pm

how?

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

print(SomeFunctionIWantToUse())
but when I execute it I get this :-

Code: Select all

Python Script
Traceback (most recent call last):
  Python script "38", line 11, in ?
    print(SomeFunctionIWantToUse())
  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?

User avatar
Bitmonster
Site Admin
Posts: 2239
Joined: Mon Feb 06, 2006 10:28 pm

Post by Bitmonster » Tue Jul 25, 2006 3:17 pm

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.

thug
Plugin Developer
Posts: 64
Joined: Sat Jul 22, 2006 2:37 pm
Location: Australia

Post by thug » Tue Jul 25, 2006 3:24 pm

Nice one! :wink:

Post Reply