The ShowWindow function can be used to show, hide, minimize or maximize a window.

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.

2 thoughts on “ShowWindow

  1. Private Declare Function FindWindow Lib “user32” Alias “FindWindowA” (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
    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 FilesRealVNCVNC4vncviewer “ & 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  
        End If
    End If
    End Sub

  2. Runtime Error 49 occurs if a dll isn’t called correctly. In this case, the ShowWindow function wasn’t declared correctly – The return value wasn’t specified: As Boolean

Posting code? Use <pre> tags for VBA and <code> tags for inline.

Leave a Reply

Your email address will not be published.