2
我有一個代碼在這裏,但按鈕點擊一些實例並不真正去最小化或恢復。我盡我所能,但沒有運氣給我。如何最小化和恢復大量實例的過程?
Private Declare Function ShowWindow Lib "user32.dll" (_
ByVal hWnd As IntPtr, _
ByVal nCmdShow As Show_Window _
) As Boolean
Private Enum Show_Window As Integer
Hide = 0
ShowNormal = 1
ShowMinimized = 2
ShowMaximized = 3
Maximize = 3
ShowNormalNoActivate = 4
Show = 5
Minimize = 6
ShowMinNoActivate = 7
ShowNoActivate = 8
Restore = 9
ShowDefault = 10
ForceMinimized = 11
End Enum
Private Sub MinimizeAllToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles MinimizeAllToolStripMenuItem.Click
Dim p() As Process = Process.GetProcessesByName("GameServer")
Dim p1() As Process = Process.GetProcessesByName("AccountServer")
Dim p2() As Process = Process.GetProcessesByName("GateServer")
Dim p3() As Process = Process.GetProcessesByName("GroupServer")
Dim p4() As Process = Process.GetProcessesByName("TradeServer")
Dim p5() As Process = Process.GetProcessesByName("FilterServer")
If MinimizeAllToolStripMenuItem.Text = "Minimize All" Then
For Each pr As Process In p
ShowWindow(pr.MainWindowHandle, Show_Window.ForceMinimized)
Next pr
For Each pr As Process In p1
ShowWindow(pr.MainWindowHandle, Show_Window.ForceMinimized)
Next pr
For Each pr As Process In p2
ShowWindow(pr.MainWindowHandle, Show_Window.ForceMinimized)
Next pr
For Each pr As Process In p3
ShowWindow(pr.MainWindowHandle, Show_Window.ForceMinimized)
Next pr
For Each pr As Process In p4
ShowWindow(pr.MainWindowHandle, Show_Window.ForceMinimized)
Next pr
For Each pr As Process In p5
ShowWindow(pr.MainWindowHandle, Show_Window.ForceMinimized)
Next pr
MinimizeAllToolStripMenuItem.Text = "Restore All"
Else
For Each pr As Process In p
ShowWindow(pr.MainWindowHandle, Show_Window.Restore)
Next pr
For Each pr As Process In p1
ShowWindow(pr.MainWindowHandle, Show_Window.Restore)
Next pr
For Each pr As Process In p2
ShowWindow(pr.MainWindowHandle, Show_Window.Restore)
Next pr
For Each pr As Process In p3
ShowWindow(pr.MainWindowHandle, Show_Window.Restore)
Next pr
For Each pr As Process In p4
ShowWindow(pr.MainWindowHandle, Show_Window.Restore)
Next pr
For Each pr As Process In p5
ShowWindow(pr.MainWindowHandle, Show_Window.Restore)
Next pr
MinimizeAllToolStripMenuItem.Text = "Minimize All"
End If
End Sub
什麼可能是錯的?或者,也許有人可以分享你的代碼,如何最大限度地減少和恢復大量實例的過程。我希望有一個人可以幫助我。
你可以包含什麼地方出了錯一些更多的細節?你有可能發佈自己編譯的工作代碼嗎?這將有助於我們診斷。 – kdbanman
你好@kdbanman,這段代碼正在工作,它的編譯沒有錯誤。問題是,每當我按下按鈕,有時一些實例不會最小化,有時不會恢復。 – Foxseiz