How to Activate a Window API to Show in VB6
- 1). Open your VB6 script in your preferred VB editor.
- 2). Copy and paste the following code into the declarations code:
Private Declare Function FindWindow Lib "user32" _
Alias "FindWindowA" _
(ByVal lpClassName As String, _
ByVal lpWindowName As String) As Long
Private Declare Function GetClassName Lib "user32" _
Alias "GetClassNameA" _
(ByVal hWnd As Long, _
ByVal lpClassName As String, _
ByVal nMaxCount As Long) As Long - 3). Copy and paste the following code into the procedures section:
Public Sub GetClassNameFromTitle()
Dim sInput As String
Dim hWnd As Long
Dim lpClassName As String
Dim nMaxCount As Long
Dim lresult As Long
' pad the return buffer for GetClassName
nMaxCount = 256
lpClassName = Space(nMaxCount)
' Note: must be an exact match
sInput = InputBox("Enter the exact window title:")
' No validation is done as this is a debug window utility
hWnd = FindWindow(vbNullString, sInput)
' Get the class name of the window, again, no validation
lresult = GetClassName(hWnd, lpClassName, nMaxCount)
Debug.Print "Window: " & sInput
Debug.Print "Class name: " & Left$(lpClassName, lresult)
End Sub - 4). Click "GetClassNameFromTitle" in the debug window and click "Run". This should display the class name of the window. This provides the basic structure for the process.
- 5). Add the following script if you want to include the process in a wrapper:
Public Function fActivateWindowClass(psClassname As String) As Boolean
Dim hWnd As Long
hWnd = FindWindow(psClassname, vbNullString)
If hWnd > 0 Then
' ShowWindow returns True if the window was previously hidden.
' I don't care so I use the sub style
' ShowWindow and SW_SHOW declared elsewhere
' SW_SHOW will display the window in its current size and position
Call ShowWindow hWnd, SW_SHOW
fActivateWindowClass = True
Else
' FindWindow failed, return False
fActivateWindowClass = False
End If
End Function
Source...