如何使用 VB.NET 按进程名称或进程 ID 隐藏/取消隐藏窗口?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/21411724/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-17 16:36:29  来源:igfitidea点击:

how to hide/unhide window by process name or processid using VB.NET?

vb.netprocesswindow

提问by K3rnel31

im trying to hide/unhide window process by name or PID i have tried

我试图按名称或 PID 隐藏/取消隐藏窗口进程我试过

<DllImport("user32.dll", SetLastError:=True, CharSet:=CharSet.Auto)> _
Private Shared Function ShowWindow(ByVal hwnd As IntPtr, ByVal nCmdShow As ShowWindowCommands) As Boolean

End Function

结束函数

but ShowWindowCommandswhat is and how to find it ?

ShowWindowCommands什么是以及如何找到它?

thanks !

谢谢 !

回答by K3rnel31

there is many ways to do this the easiest one should be this :

有很多方法可以做到这一点,最简单的方法应该是:

'GENERAL IMPORT

'一般进口

Imports System.Runtime.InteropServices

'FORM CLASS DECLARATION

'表格类声明

  <DllImport("user32.dll")> _
Private Shared Function ShowWindow(ByVal hWnd As IntPtr, ByVal nCmdShow As Integer) As Boolean
End Function

'then if you want to hide firefox'swindow:

'那么如果你想隐藏firefox'swindow

 Dim mywindow As Integer
    Dim processRunning As Process() = Process.GetProcesses()
    For Each pr As Process In processRunning
        If pr.ProcessName = "Firefox" Then
            mywindow = pr.MainWindowHandle.ToInt32()
            ShowWindow(mywindow , 0)
        End If
    Next

回答by Bj?rn-Roger Kringsj?

You can do it like this:

你可以这样做:

Form.FromHandle(Process.GetProcessById(PID).MainWindowHandle).Show()