最小化除我的应用程序之外的所有其他应用程序
Minimize all other applications except my application
我想最小化除我自己的应用程序之外的所有应用程序,但是使用下面的代码,我的 ow 应用程序不会再次显示。
Private Declare Sub keybd_event Lib "user32" (ByVal bVk As Byte, ByVal bScan As Byte, _
ByVal dwFlags As Long, ByVal dwExtraInfo As Long)
Private Const KEYEVENTF_KEYUP = &H2
Private Const VK_LWIN = &H5B
Sub minimizeAllOthers()
Me.WindowState=WindowState.Minimized
keybd_event(VK_LWIN, 0, 0, 0)
keybd_event(77, 0, 0, 0)
keybd_event(VK_LWIN, 0, KEYEVENTF_KEYUP, 0)
While Me.WindowState=WindowState.Minimized
Me.WindowState=WindowState.Normal
Me.windowstate=WindowState.Maximized
Threading.Thread.Sleep(400)
End Sub
要检测表单何时被最小化,here's 一个很好的解决方案(阅读解决方案的 "To react after" 部分)。
所以这是一个工作代码:
Dim Minimizing As Boolean = False
Dim Normalizing As Boolean = False
Sub minimizeAllOthers()
Minimizing = True
keybd_event(VK_LWIN, 0, 0, 0)
keybd_event(77, 0, 0, 0)
keybd_event(VK_LWIN, 0, KEYEVENTF_KEYUP, 0)
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
minimizeAllOthers()
End Sub
Private Sub Form1_Resize(sender As Object, e As EventArgs) Handles Me.Resize
If Minimizing AndAlso Me.WindowState = FormWindowState.Minimized Then
Me.WindowState = FormWindowState.Normal
If Normalizing Then
Minimizing = False
End If
If Normalizing Then Normalizing = False Else Normalizing = True
End If
End Sub
希望对您有所帮助,并且我已经正确理解了您的问题...
你可以试试这个^_^
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
我想最小化除我自己的应用程序之外的所有应用程序,但是使用下面的代码,我的 ow 应用程序不会再次显示。
Private Declare Sub keybd_event Lib "user32" (ByVal bVk As Byte, ByVal bScan As Byte, _
ByVal dwFlags As Long, ByVal dwExtraInfo As Long)
Private Const KEYEVENTF_KEYUP = &H2
Private Const VK_LWIN = &H5B
Sub minimizeAllOthers()
Me.WindowState=WindowState.Minimized
keybd_event(VK_LWIN, 0, 0, 0)
keybd_event(77, 0, 0, 0)
keybd_event(VK_LWIN, 0, KEYEVENTF_KEYUP, 0)
While Me.WindowState=WindowState.Minimized
Me.WindowState=WindowState.Normal
Me.windowstate=WindowState.Maximized
Threading.Thread.Sleep(400)
End Sub
要检测表单何时被最小化,here's 一个很好的解决方案(阅读解决方案的 "To react after" 部分)。
所以这是一个工作代码:
Dim Minimizing As Boolean = False
Dim Normalizing As Boolean = False
Sub minimizeAllOthers()
Minimizing = True
keybd_event(VK_LWIN, 0, 0, 0)
keybd_event(77, 0, 0, 0)
keybd_event(VK_LWIN, 0, KEYEVENTF_KEYUP, 0)
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
minimizeAllOthers()
End Sub
Private Sub Form1_Resize(sender As Object, e As EventArgs) Handles Me.Resize
If Minimizing AndAlso Me.WindowState = FormWindowState.Minimized Then
Me.WindowState = FormWindowState.Normal
If Normalizing Then
Minimizing = False
End If
If Normalizing Then Normalizing = False Else Normalizing = True
End If
End Sub
希望对您有所帮助,并且我已经正确理解了您的问题...
你可以试试这个^_^
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