2011-12-12 28 views
3

如果您在任务管理器中注意过,当您右键单击正在运行的任务时,您有许多选项,包括“最小化”和“最大化”。无论如何要做到这一点在VB中?如何使与应用程序无关的窗口最小化或最大化其在vb中的窗口状态?

+0

最小化/最大化您自己的应用程序,或在不同的应用程序上执行它? – JohnFx

+0

好的我想让我的应用程序最大化/最小化与我的应用程序无关的另一个应用程序,以及任务管理器的工作方式。 – user959631

回答

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 
+0

嘿,伙计,非常感谢。你现在是否已经做好了,或者你之前用过这个?如果你现在就完成它,我爱你!大声笑= P谢谢 – user959631

+0

曾经使用过的技术。必须查找一些常量和API方法(ShowWindow),但除此之外从头开始写这个。请不要将它用于邪恶(例如创建一个超级应用程序,最大限度地减少其他所有事情,以便它可以成为桌面之王) – JohnFx

+0

lmao桌面之王,naa我想用它来做一些永恒的事弹出,然后我想关闭它的过程,然后最大化我的窗口=]谢谢无论如何 – user959631

相关问题