PDA

View Full Version : Sleeper: VBA problem activate window inside a window



Harrij
05-06-2005, 08:04 AM
We use a programshell which has a fully mouse controlled interface.
No menu's to work with from a toolbar.
The main window interface is just the full screenarea, the users-interface is situated in this window. It is not possible to use the send-keys trick the first time as one of the buttons needs to be activated the first time.

We have created a virtual COM port to communicate with this program but we are unable to start the program by VBA does anyone have any knowledge to help us out???

We are desperate in our automisation progress this way.

Help and information is needed

thanks:banghead:

Killian
05-09-2005, 03:52 PM
Hi there and welcome to VBAX :hi:

I think you need to explain in a little more detail what you need.
Are these VBA userforms you need to start? Or are you trying to activate something else from within Office with VBA?

Harrij
05-11-2005, 10:14 AM
Hi there and welcome to VBAX :hi:

I think you need to explain in a little more detail what you need.
Are these VBA userforms you need to start? Or are you trying to activate something else from within Office with VBA?


We use a company made program ( running on Windows XP )which has a full screen interface. Inside ( smaller interface) is the user-program itself. So both are on the desktop but only the larger fullscreen interface is active when starting the program. In order to use the program a mouse is a must.
Once ?NE"click has been made in the smeller interface the buttons become active and VBA is able to activate the buttons by using "send keys" commands.
BUT HOW TO ACTIVATE the inner smaller interface, using NO mouseclicks at all.
Sofar we dont have the knowledge in activating the window within a window.

We need this as we are running a full automisation on our laboratory.

Our communication is through a virtual COM port with this machine:banghead: :banghead: :banghead:

Killian
05-11-2005, 12:17 PM
Well this is an interesting problem... :think:

If the fullscreen interface is active when the code is running (I assume you launch the app with VBA) the you can use a Win API function to get a handle to the fullscreen interface and another to get the child window and activate it.

First a couple of comments:
1) I've no way of knowing how the company application is structured so it may take a bit of trial and error testing to get this right.
2) Using SendKeys can be extremely unreliable and is generally considered a "last resort". You may want to look at some of the other Win API functions to build a more robust method.

That said, here's some code to try out:


Private Declare Function GetActiveWindow Lib "user32" () As Long
Private Declare Function GetWindow Lib "user32" (ByVal hwnd As Long, ByVal wCmd As Long) As Long
Private Declare Function Putfocus Lib "user32" Alias "SetFocus" (ByVal hwnd As Long) As Long

Sub test()
'launch target application
If ActivateSmallInterface <> 0 Then
'start data input with sendkeys
SendKeys "A"
Else
MsgBox "No child window found"
End If
End Sub

Private Function ActivateSmallInterface() As Long
'returns the return value of Putfocus
Dim hMain As Long, hSmall As Long
Const GW_CHILD = 5
'get handle to the active window (fullscreen interface)
hMain = GetActiveWindow
'get handle to the child window (small interface)
hSmall = GetWindow(hMain, GW_CHILD)
'set the small interface to receive keyboard input
ActivateSmallInterface = Putfocus(hSmall)
End Function

Harrij
05-12-2005, 08:41 AM
Will give this atry next week , will respond to you to let you know what works or doesn't
Thanks for now