The following code is kindly provided by an excelent resourse called www.vbapi.com. It lists loads of API calls for windoze and is a great site. In order to "find" the hWnd of a window, you need to know it's title (in the blue bar at the top). This function returns the hWnd so you can use the "SendKeys" function on it.
Regards,
Jonathan
' This code is licensed according to the terms and conditions listed here.
' Declarations and such needed for the example:
' (Copy them to the (declarations) section of a module.)
Public Declare Function FindWindow Lib "user32.dll" Alias "FindWindowA" (ByVal lpClassName As String, _
ByVal lpWindowName As String) As Long
Public Declare Function FlashWindow Lib "user32.dll" (ByVal hWnd As Long, ByVal bInvert As Long) As Long
Public Declare Sub Sleep Lib "kernel32.dll" (ByVal dwMilliseconds As Long)
' * Place the following code inside a form. *
Private Sub cmdFind_Click()
Dim hWnd As Long ' receives handle to the found window
Dim retval As Long ' generic return value
' Attempt to locate a window titled Minesweeper.
hWnd = FindWindow(vbNullString, "Minesweeper")
If hWnd = 0 Then
Debug.Print "Minesweeper is not currently running."
Else
' Flash the window's title bar on and off once. Or use your sendkeys function.
retval = FlashWindow(hWnd, 1)
Sleep 500 ' pause for half a second
retval = FlashWindow(hWnd, 0)
End If
End Sub
Enter your message below
Sign in or Join us (it's free).