Article ID: 152261
Article Last Modified on 10/10/2006
104710 INF: How to Activate an Application with Class Name (2.0)
' 32 Bit Declares.
Declare Function ShowWindow32 Lib "user32" Alias "ShowWindow" _
(ByVal hwnd As Long, ByVal nCmdShow As Long) As Long
Declare Function FindWindow32 Lib "user32" Alias "FindWindowA" _
(ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Declare Function SetForegroundWindow32 Lib "user32" Alias _
"SetForegroundWindow" (ByVal hwnd As Long) As Long
' 16 Bit Declares.
Declare Function ShowWindow Lib "User" (ByVal hwnd As Integer, _
ByVal nCmdShow As Integer) As Integer
Declare Function SetActiveWindow Lib "User" (ByVal hwnd As _
Integer) As Integer
Declare Function FindWindow Lib "User" (ByVal lpClassName As _
Any, ByVal lpWindowName As Any) As Integer
' Test routine. Run this subroutine.
Sub TestIt_ActivateAppClass()
Dim strClassName As String
Dim iRetVal As Integer
strClassName = "opusapp"
iRetVal = AppActivateClass(strClassName)
If Not iRetVal Then MsgBox strClassName & " Is NOT currently " & _
"running"
End Sub
' VB Api encapsulation function for ShowWindow.
Function vb_ShowWindow(ByVal hwnd As Long)
Const SW_SHOW = 9
If is32Bit Then
iRetVal = SetForegroundWindow32(hwnd)
iRetVal = ShowWindow32(hwnd, SW_SHOW)
Else
iRetVal = SetActiveWindow(hwnd)
iRetVal = ShowWindow(hwnd, SW_SHOW)
End If
vb_ShowWindow = iRetVal
End Function
' VB Api encapsulation function for FindWindow.
Function vb_FindWindow(ByVal lpClassName As String) As Long
Dim strNullString As String 'Define Null String Variable
If is32Bit Then
vb_FindWindow = FindWindow32(lpClassName, strNullString)
Else
vb_FindWindow = FindWindow(lpClassName, 0&)
End If
End Function
Function is32Bit() As Boolean
is32Bit = False ' Assume Failure.
If InStr(1, Application.OperatingSystem, "32", 1) > 1 Then
is32Bit = True
End If
End Function
Function AppActivateClass(lpClassName As String) As Boolean
Dim hwnd As Long ' The application's window handle.
Dim iRetVal As Integer ' Temp variable.
Dim iCmdShow As Integer ' The ShowWindow cmdshow argument.
ActivateAppClass = False ' Assume Failure.
hwnd = vb_FindWindow(lpClassName) ' Get the Window Handle for
' the className.
If hwnd <> 0 Then ' The class was found.
iRetVal = vb_ShowWindow(hwnd) ' Activate the Application.
ActivateAppClass = True ' Return True if Application
' Running.
End If
End Function
Additional query words: 5.00a 5.00c 97 8.00 XL97 API SDK ALIAS XL
Keywords: kbdtacode kbhowto kbprogramming KB152261