Jump to content



Photo

Python: Get Current Index Selection of ComboBox


  • Please log in to reply
No replies to this topic

#1 cowofevil

cowofevil

    Seeker

  • New Members
  • 1 posts

Posted 13 April 2012 - 10:59 PM

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_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.









0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users