Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

switching to a background window?

Status
Not open for further replies.

craigey

Technical User
Apr 18, 2002
510
GB
HI guys

I'm trying to send a refresh command to an app every 20 minutes. Each time I send the command I need to activate the window in case someone has open IE or outlook etc. I've tried using:

appactivate "the window title"

But this just produces a runtime error. I've searched google & on here, but haven't found what I need.

Cheers
Craig
 
This is a stretch for me, but I think you need to use two (and possibly three) API: FindWindow, and SetForgroundWindow.

SetForegroundWindow uses FindWindow, as in:
Code:
Declare Function SetForegroundWindow Lib "user32" _
   Alias "SetForegroundWindow" _
   (ByVal hwnd as Long) As Long

Declare Function FindWindow Lib "user32" _
   Alias "FindWindow"A _
   (ByVal lpClassName As String, _
   By Val lpWindowName As String) As Long

Sub BringToForeground(Caption As String)
  Dim hwnd As Long

' find the window
  hwnd = FindWindow("", Caption)

' then set it to foreground
  SetForegroundWindow hwnd
End Sub

lpClassname is the string of the classname. If you need to find the classname, use the GetClassname API.

Code:
Public Function Find(Caption As String, _
   Optional ClassName As String) As Long

  If IsNull(ClassName Then Classname = ""
  Find = FindWindow(Classname, Caption)
End Function

As I am NOT an API expert....use carefully, and at your own peril.

Gerry
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top