Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make a window not associated with the application minimize or maximize its window state in vb?

If you have ever noticed in the Task Manager, when you right-click on the running task, you have many options which include 'Minimize' and 'Maximize'. Is there anyway to do achieve this in vb?

like image 601
user959631 Avatar asked Oct 14 '25 07:10

user959631


1 Answers

Here is an example of the code you are looking for. It will loop through all the active processes and minimize all the windows.

In your app you will probably want to use something like Process.GetProcessesByName to find the specific window you want to manipulate.

Imports System.Runtime.InteropServices

Module ManipulateWindows

    Const SW_HIDE As Integer = 0
    Const SW_RESTORE As Integer = 1
    Const SW_MINIMIZE As Integer = 2
    Const SW_MAXIMIZE As Integer = 3

    <DllImport("User32")> _
    Private Function ShowWindow(ByVal hwnd As Integer, ByVal nCmdShow As Integer) As Integer
    End Function

    Public Sub Main()

        'iterate through all the open processes.
        For Each p As Process In Process.GetProcesses    

            'Get the Window Handle
            Dim hWnd as integer = CType(p.MainWindowHandle, Integer)

            'Write out the title of the main window for the process.
            System.Console.WriteLine(p.MainWindowTitle)

            'Minimize the Window
            ShowWindow(hWnd, SW_MINIMIZE)
        Next p    
    End Sub    
End Module
like image 52
JohnFx Avatar answered Oct 17 '25 08:10

JohnFx



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!