隐藏/显示流程 [英] Hide/Show a process

查看:57
本文介绍了隐藏/显示流程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在C#/WPF中以隐藏模式启动一个进程(例如:NotePad),然后再显示该进程.虽然我可以在启动过程中隐藏该过程,但稍后再显示是行不通的.这是这两个代码:

I am trying to start a process (eg:NotePad) in hidden mode in C#/WPF and later show that process. While I am able to hide the process during start, showing it later doesn't work. Heres the code for both:

以隐藏模式开始

Process p = new Process();
p.StartInfo.FileName = "Notepad.exe";
p.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
p.Start();

显示过程.

Process[] processes = Process.GetProcessesByName("Notepad");
foreach (Process p in processes)
{

 p.StartInfo.WindowStyle = ProcessWindowStyle.Normal;
 ShowWindow(p1,  SW_SHOW);
}

此代码有什么问题?如何使该过程可见?

What's is wrong with this code? How can I make the process visible?

推荐答案

代码是VB,但可以使用:

The code is VB but it works:

Imports System.Runtime.InteropServices
Imports System.Diagnostics

Class MainWindow

    Const SW_HIDE As Integer = 0
    Const SW_RESTORE As Integer = 9
    Dim hWnd As Integer
    Dim p As Process() = Process.GetProcessesByName("notepad")
    <DllImport("User32")> Private Shared Function ShowWindow(ByVal hwnd As Integer, ByVal nCmdShow As Integer) As Integer
    End Function


    Private Sub StartProcess(sender As Object, e As RoutedEventArgs)
        hWnd = p(0).MainWindowHandle.ToInt32
    End Sub

    Private Sub ShowProcess(sender As Object, e As RoutedEventArgs)
        ShowWindow(hWnd, SW_RESTORE)
    End Sub

    Private Sub HideProcess(sender As Object, e As RoutedEventArgs)
        ShowWindow(hWnd, SW_HIDE)
    End Sub
End Class


这篇关于隐藏/显示流程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆