如果您在任务管理器中注意到,当您右键单击正在运行的任务时,您有许多选项,包括“最小化”和“最大化”。反正有没有在vb中实现这个目标?
答案 0 :(得分:3)
以下是您要查找的代码示例。它将遍历所有活动进程并最小化所有窗口。
在您的应用中,您可能希望使用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