cowofevil Posted April 13, 2012 Share Posted April 13, 2012 (edited) I know you're expecting a question, but actually this is just the answer to the question! I decided to post this here because through some mega-googling and forum snooping I finally came up with a solution to the problem. Since this forum has been very informative to me in the past I decided it was my duty to post this information here so the next guy doesn't need to waste many hours of his life trying to solve the problem.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_GETCURSELThe 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 April 13, 2012 by cowofevil Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now