ShowWindow
The ShowWindow function can be used to show, hide, minimize or maximize a window.
Public Declare Function ShowWindow Lib “user32″ _
(ByVal lHwnd As Long, _
ByVal lCmdShow As Long) As Boolean
The lHwnd argument is the handle that you get using the FindWindow function. The lCmdShow argument is a Long that tells ShowWindow what to do. Some common numbers used for lCmdShow are:
| Action | Value | Typical Constant Name |
| Hide | 0 | SW_HIDE |
| Show | 5 | SW_SHOW |
| Minimize | 2 | SW_MINIMIZE |
| Maximize | 3 | SW_MAXIMIZE |
These examples show ShowWindow in action to hide and show the main Excel window, respectively.
Sub HideMainXlWindow()
Dim lHwnd As Long
Const SW_HIDE As Long = 0
lHwnd = FindWindow(”XLMAIN”, Application.Caption)
ShowWindow lHwnd, SW_HIDE
End Sub
Sub ShowMainXlWindow()
Dim lHwnd As Long
Const SW_SHOW As Long = 5
lHwnd = FindWindow(”XLMAIN”, vbNullString)
ShowWindow lHwnd, SW_SHOW
End Sub

Private Declare Function ShowWindow Lib "user32" (ByVal hwnd As Long, ByVal nCmdShow As Long)
Private Sub NetName_Click()
Dim lHwnd As Long
If vncinstall = True And NetName.Caption "" Then
Shell "C:\Program Files\RealVNC\VNC4\vncviewer " & NetName.Caption, vbNormalFocus
Application.Wait (Now + TimeValue("0:00:01"))
SendKeys "*****~"
Application.Wait (Now + TimeValue("0:00:02"))
lHwnd = FindWindow(vbNullString, NetName.Caption)
If lHwnd 0 Then
ShowWindow lHwnd, 1
'Every time it gets to here I get a Runtime Error 49
'Bad DLL calling convention
Else
Beep
End If
End If
End Sub