How can I tell if an external window is maximized? Also, if it is maximized, I want to restore it so that its not maximized (the equivilant of clicking the middle button on the window).
Any ideas?
Jordan
Printable View
How can I tell if an external window is maximized? Also, if it is maximized, I want to restore it so that its not maximized (the equivilant of clicking the middle button on the window).
Any ideas?
Jordan
Use the IsZoomed api function to tell if a window is maximized or not.
Code:Private Declare Function FindWindow Lib "user32" _
Alias "FindWindowA" (ByVal lpClassName As String, ByVal _
lpWindowName As String) As Long
Private Declare Function IsZoomed Lib "user32" (ByVal _
hwnd As Long) As Long
Private Declare Function ShowWindow Lib "user32.dll" (ByVal hwnd As _
Long, ByVal nCmdShow As Long) As Long
Private Const SW_RESTORE = 9
Private Sub Command1_Click()
hWin = FindWindow("notepad", vbNullString)
If hWin <> 0 Then
If IsZoomed(hWin) Then
ShowWindow hWin, SW_RESTORE
End If
End If
End Sub
Thanks Matthew, works great. Just wondering, whats the difference between SW_NORMAL and SW_RESTORE? I'm using SW_NORMAL and it seems to work fine.
Thanks,
Jordan
SW_NORMAL = 1
SW_RESTORE = 9
Normal shows window as normal, which will just bring up and give focus to the window.
Restore restores the window when it has been maximized (and maybe minimized ?)
Glad it worked for you.