Is there a way to make my application tell something else to minimize/maximize/restore itself.
Example: My form commands Windows Media Player to minimize, but not just Media Player. I want to minimize/maximize/restore any window.
Printable View
Is there a way to make my application tell something else to minimize/maximize/restore itself.
Example: My form commands Windows Media Player to minimize, but not just Media Player. I want to minimize/maximize/restore any window.
assuming you already knew the window handle, you can use SendMessage with WM_SYSCOMMAND message and SC_CLOSE, SC_RESTORE, SC_MAXIMIZE, SC_MINIMIZE constant
I am just a newbie, could you give me a rundown of each of those?
PHP Code:
Private Const SW_MAXIMIZE As Long = 3
Private Const SW_MINIMIZE As Long = 6
Private Const SW_RESTORE As Long = 9
Private Declare Function FindWindow Lib "user32.dll" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function ShowWindow Lib "user32.dll" (ByVal hwnd As Long, ByVal nCmdShow As Long) As Long
Private Sub cmdMax_Click()
Dim noteHwnd As Long
'Find notepad window, class name can be found using Spy++
noteHwnd = FindWindow("Notepad", vbNullString)
'or if you know the exact window title
noteHwnd = FindWindow(vbNullString, "Untitled - Notepad")
If noteHwnd <> 0 Then
'maximize the window
ShowWindow noteHwnd, SW_MAXIMIZE
End If
End Sub
Thank you Luthv for the help. I have come up with the solution without specifying a certain program.
Private Declare Function GetForegroundWindow Lib "user32" () As Long
Private Declare Function ShowWindow Lib "user32.dll" (ByVal hwnd As Long, ByVal nCmdShow As Long) As Long
Private Const SW_MAXIMIZE As Long = 3
Private Const SW_MINIMIZE As Long = 6
Private Const SW_RESTORE As Long = 9
' Enter this in Sub-Routine
Ret = GetForegroundWindow()
ShowWindow Ret, SW_MAXIMIZE
This code will minimize whatever the active window is at the time.
Many thanks for posting this, Luthv! It works perfectly for my purposes, which was to find a previously opened window and bring it to the front, whether it is minimized or sits behind other windows. I modified the code to add restore, then maximize, to account for all issues.
Private Declare Function GetForegroundWindow Lib "user32" () As Long
Private Declare Function ShowWindow Lib "user32.dll" (ByVal hwnd As Long, ByVal nCmdShow As Long) As Long
Private Const SW_MAXIMIZE As Long = 3
Private Const SW_MINIMIZE As Long = 6
Private Const SW_RESTORE As Long = 9
Public Function FindAndMaximizeWindow(strWindowName) As Boolean
Dim noteHwnd As Long
'Find notepad window, class name can be found using Spy++
noteHwnd = FindWindow(strWindowName, vbNullString)
'or if you know the exact window title
noteHwnd = FindWindow(vbNullString, strWindowName)
If noteHwnd <> 0 Then
'maximize the window
ShowWindow noteHwnd, SW_RESTORE
ShowWindow noteHwnd, SW_MAXIMIZE
FindAndMaximizeWindow = True
Else
FindAndMaximizeWindow = False
End If
End Function
12 years later???