views:

431

answers:

2

I have some VB code which makes use of a COM api and results in a certain dialog box popping up on the screen. My program is a console application, that needs to run in a batch file, but I haven't found any other way to do things other than finding a way to automatically manipulate the dialog box.

Here is the api call (omitting setup code) that results in the dialog popping up:

  Dim oScript = New ProvideX.Script()

  ' Setup code here '

  oScript.Run(commName)

This method has no return value, and no extra parameters that would enable me to fill in the values I need through the API.

I have found one method to get the handle of the dialog window, but I'm not sure if it will work, or if it will grab onto the Command line window instead.

Dim windowHandle = Process.GetCurrentProcess().MainWindowHandle

Is there any way to get a list of windows that were created by my process so I can identify the one that corresponds to my dialog?

Also, can anyone point me in the right direction of how to do send mouse clicks and keyboard presses to an unmanaged dialog box, or is there some better way to do what I need.

This is a fairly simple dialog box that has a warning prompt that needs to be accepted by clicking on an ok button. Then there are two text boxes that need to be filled out with data I have. And then I need to click on another button.

I'm not asking for a complete answer, I'm just looking for the general jist of how to do it.

Edit: I was doing research at PINVOKE.net and I think SendInput will work if I can get the right handle. I've walked through the dialog and it can all be handled by keyboard input.

+1  A: 

To get an HWND of the dialog, I would call FindWindow(). You can pass it the class name and caption of your dialog, and it should return its HWND to you. You can use a tool like Spy++ (installed by Visual Studio, at least the Professional Edition) or WinCheat to find this for your dialog.

From there, if you want to get an HWND for the OK button, try calling either GetDlgItem() (passing it the HWND of your dialog and its ID (Spy++ can get this for you, I'm not sure if WinCheat can or not). If that doesn't work, you could always try calling EnumChildWindows() and see if you can find it that way.

I'm not a VB expert, and calling some of these functions from VB might be hard and/or not work (especially EnumChildWindows(), since it requires a callback function). But hopefully this will give you a place to start looking.

Andy
A: 

IIRC I'm using EnumChildWindows() in StaxRip, you can find the VB.NET code at http://www.stax76.bplaced.net or when you find C# code you can translate it to VB.NET with Reflector, SharpDevelop or the SharpDevelop online convertor service.