Jump to content
Sign in to follow this  

Controls and VB6

Recommended Posts


Hi Guys,

I'm wondering if somebody can help with a problem I'm having get AutoIt to simulate selecting controls within one of my applications.

I have tried using the API in VB6 without any success (controls just don't get fired) so I have reverted to writing a script compiling this to an exe and calling this from within VB - basically the script selects a property menu within the application and sets one of the options (a radio button).

The problem is that if I run the exe from windows explorer or the command line the correct option is selected but if I shell out to the same exe within VB it just fires up the property form without selecting an option. I had simlar problems when trying to select this control using the API but am failing miserably with my workaround :)

Sample code for the script is below

AutoItSetOption("WinTitleMatchMode", 2)

WinActivate("Scan", "")


WinMenuSelectItem("Scan", "", "&Scan", "&Properties" )

WinActivate("Source Properties", "")

ControlClick ( "Source Properties", "", 3006)

For info I am running this on Server 2003 (SP1) with Visual Basic 6 (No Service Packs)

Any ideas would be appreciated



Share this post

Link to post
Share on other sites

WinActivate("Source Properties", "")
WinWaitActive("Source Properties", "")
ControlFocus ( "Source Properties", "", 3006)
ControlClick ( "Source Properties", "", 3006)

ControlClick - Remarks

The control might first need to be given focus with the ControlFocus command.

Simulating a click on a control is only 100% accurate when the control's parent window is active - this is done automatically. Nothing will occurs if the control is disabled.

Share this post

Link to post
Share on other sites

Magic! Thanks for this - I can now fire off all controls when I run them through the exe

Ideally I would like to be able to do this through my VB app but if I try and run the same thing with the COM API it doesn't work.

Sample code below..

Dim oAutoIt As AutoItX3

Set oAutoIt = New AutoItX3

Call oAutoIt.WinActivate("Scan")

Call oAutoIt.send("{ALT}!sp") 'Had to do it this way in VB because the WinMenuSelectItem call didn't seem to work?

'Call oAutoIt.WinMenuSelectItem("Scan", "", "&Scan", "&Properties") - This was the line I tried

Call oAutoIt.WinActivate("Source Properties")

Call oAutoIt.WinWaitActive("Source Properties") 'With this line it just seems to hang, without it the control does not get set

Call oAutoIt.ControlFocus("Source Properties", "", 3006)

Call oAutoIt.ControlClick("Source Properties", "", 3006)

Has anybody experienced anything like this when using the API? Is there something extra I need to do to get focus on the form when running it this way?

Thanks in advance

Share this post

Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this