How to minimize/maximize opened Applications

前端 未结 3 1425
再見小時候
再見小時候 2020-12-16 16:48

I have list of open Applications. To get this list i have used following code

 internal static class NativeMethods
{
    public static readonly Int32 GWL_STY         


        
3条回答
  •  一个人的身影
    2020-12-16 17:02

    you can use ShowWindowAsync

    private const int SW_SHOWNORMAL = 1;
    private const int SW_SHOWMINIMIZED = 2;
    private const int SW_SHOWMAXIMIZED = 3;
    
    [DllImport("user32.dll")]
    private static extern bool ShowWindowAsync(IntPtr hWnd, int nCmdShow);
    
    
    ShowWindowAsync(wnd.Handle, SW_SHOWMINIMIZED );
    

    and it's better and to use

        var openWindows = Process.GetProcesses().Where(process=> String.IsNullOrEmpty(process.MainWindowTitle)==false);
    

    to get opened windows

    I have test MainWindowTitle in Porcess and it helps to search on window given it's caption.

     var handles = Process.GetProcesses().Where(x => x.MainWindowTitle == "Untitled - Notepad").Select(y=>y.Handle).ToList();
    

提交回复
热议问题