2011-12-12 30 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

相關問題