Get the Min/Max State of a window

bmatumbura used Ask the Experts™
I need a VB boolean function that takes a handle to a window (hWnd as Long) as a parameter. The function then checks the Min/Max status of the Window. It must return True if the Window is Minimized, False otherwise.
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Software Team Lead
Try use the IsIconic function, determines whether the specified window is minimized (iconic).

Declare Function IsIconic Lib "user32" Alias "IsIconic" (ByVal hwnd As Long) As Long

Here is an example:

'This project needs a timer
Private Declare Function GetUserName Lib "advapi32.dll" Alias "GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long
Private Declare Function GetTempPath Lib "kernel32" Alias "GetTempPathA" (ByVal nBufferLength As Long, ByVal lpBuffer As String) As Long
Private Declare Function IsIconic Lib "user32" (ByVal hwnd As Long) As Long
Private Sub Form_Load()
    'KPD-Team 1998
    Timer1.Interval = 100
    Timer1.Enabled = True
    Dim strTemp As String, strUserName As String
    'Create a buffer
    strTemp = String(100, Chr$(0))
    'Get the temporary path
    GetTempPath 100, strTemp
    'strip the rest of the buffer
    strTemp = Left$(strTemp, InStr(strTemp, Chr$(0)) - 1)

    'Create a buffer
    strUserName = String(100, Chr$(0))
    'Get the username
    GetUserName strUserName, 100
    'strip the rest of the buffer
    strUserName = Left$(strUserName, InStr(strUserName, Chr$(0)) - 1)

    'Show the temppath and the username
    MsgBox "Hello " + strUserName + Chr$(13) + "The temp. path is " + strTemp
End Sub
Private Sub Timer1_Timer()
    Dim Boo As Boolean
    'Check if this form is minimized
    Boo = IsIconic(Me.hwnd)
    'Update the form's caption
    Me.Caption = "Form minimized: " + Str$(Boo)
End Sub
Ryan ChongSoftware Team Lead

The use isZoom API to determine whether a window is maximized.
Declare Function IsZoomed Lib "user32" Alias "IsZoomed" (ByVal hwnd As Long) As Long


Private Declare Function IsZoomed Lib "user32" (ByVal hwnd As Long) As Long
Private Sub Form_Activate()
    'KPD-Team 2000
    Me.AutoRedraw = True
    Me.Print "Was the window maximized onstartup? " + Str$(CBool(IsZoomed(Me.hwnd)))
    Me.WindowState = vbMaximized
    Me.Print "Is the window now maximized? " + Str$(CBool(IsZoomed(Me.hwnd)))
End Sub


Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial