Hiding process by clicking the button

1

I would like to know if it is possible for me to get the id of a program as in the example and hide it (it's already open), by taking it from the navigation bar ( link ), that is, clicking on the button hides the program, however it continues to run normally and hidden. I have not tried anything yet because I still did not understand how to do it.

    
asked by anonymous 10.05.2016 / 13:16

1 answer

1

There are several ways to do this, but here's one of the easiest ones.

Mainly, refer to this namespace:

Imports System.Runtime.InteropServices

Now declare this function.

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

And use this method to display or hide something.

Public Sub AlterarStatus(ByVal NomeDoProcesso$, ByVal Status As Integer)
    Dim mywindow As Integer
    Dim processRunning As Process() = Process.GetProcesses()
    For Each pr As Process In processRunning
        ' Uso do ToLower() para ignorar maiúsculas de minúsculas, se não quiser isso, remova
        ' nos dois membros
        If pr.ProcessName.ToLower() = NomeDoProcesso.ToLower() Then
            mywindow = pr.MainWindowHandle.ToInt32()
            ShowWindow(mywindow , Status)
        End If
    Next
End Sub

In the argument Status , if its value is 0 , the window will be hidden , if it is 1 displayed .

    
15.05.2016 / 20:27