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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

FindWindow when caption isn't constant

Status
Not open for further replies.

huskerdon

Programmer
Aug 26, 2002
67
0
0
US
I'm using the API's FindWindow, ShowWindow, and SetForegroundWindow to determine if a program is already running. If it is, I want to bring it to the top. So far this code works:

hwnd1 = FindWindow(vbNullString, "thecaption")

If hwnd1 = 0 then
' use shell to open the program since it's not already running
Else
' it's a borderless form, so want it maximized
ShowWindow hwnd1, SW_MAXIMIZE
SetForegroundWindow hwnd1
End If

THIS WORKS, and will bring the program with the caption "thecaption" to the top.

My question is, can you detect the window even though the caption is constantly changing? I am changing the caption, ie, showing different ones depending on the time, which form is displayed, etc. Any help would be appreciated. Thanks.
 
You can use the window's class name where you currently pass in vbNullString and pass an empty string into the capation parameter.

If you don't know the class name, there's a free utility on my web site that browses open windows and displays their properties:


Paul Bent
Northwind IT Systems
 
hi huskerdon,


The code for finding window even it's captions is changing.

Private Declare Function FindWindow Lib "user32" Alias
"FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function SetForegroundWindow Lib "user32" (ByVal hwnd As Long) As Long
Private Sub Form_Load()



Dim lHandle As Long

lHandle = FindWindow("ThunderRT5Form", Me.Caption)

lHandle = SetForegroundWindow(lHandle)
End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top