Issue:
You need to know the index of the current selection of a combo box using AutoIt via the COM interface in Python.
Pre-Reqs:
Python 2.7 or greater.
PyWin32 (If you just have the ActiveState version of Python installed this will be done automatically)
AutoIt 3.3 or greater.
Imports:
from win32com.client import Dispatch from win32api import SendMessage from win32con import CB_GETCURSEL
The first import is for actually loading the COM class of AutoIt.
The second import is a Win32 function for sending messages to controls.
The third import is a constant that represents the message type you want to send.
Solution:
#init strWindowTitle = 'TESTAPP' strComboBoxID = '[CLASS:ComboBox; INSTANCE:1]' #COM handle for AutoIt comAutoIt = Dispatch("AutoItX3.Control") #Get handle on combobox control. #We get a string representation of hex that needs to be converted to int. hdlComboBox = int(comAutoIt.ControlGetHandle(strWindowTitle, '', strComboBoxID), 16) #Get the current index of the combobox. (Index is 0 based) intIndex = SendMessage(hdlComboBox, CB_GETCURSEL, 0, 0)
Hope that was helpful!
Edited by cowofevil, 13 April 2012 - 11:00 PM.



