4

如果您曾经在任务管理器中注意到,当您右键单击正在运行的任务时,您有很多选项,包括“最小化”和“最大化”。无论如何在vb中实现这一点?

4

1 回答 1

5

这是您正在寻找的代码示例。它将遍历所有活动进程并最小化所有窗口。

在您的应用程序中,您可能想要使用类似Process.GetProcessesByName的方法来查找您想要操作的特定窗口。

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
于 2011-12-12T22:05:15.663 回答