minimizar Notepad.exe external program

Asked

Viewed 47 times

-3

I would like to have a Button when clicking on it in my form the Notepad.exe minimize to windows bar.as I do this code I have no idea ?

private void button10_Click(object sender, EventArgs e){

   System.Diagnostics.Process prc = new System.Diagnostics.Process();
   string windir = null;
   prc.StartInfo.FileName = windir + @"filename";
   prc.StartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Minimized;
   prc.Start();
}

1 answer

1


Use the method Process.GetProcessesByName() to obtain an array of the active processes in the system that share the same process name. Use the function ShowWindow() windows API with the parameters Process.MainWindowHandle which informs Handler of the main process window and SW_MINIMIZE who informs ShowWindow() that the window must be minimised.

using System;
using System.Diagnostics;
using System.Windows.Forms;
using System.Runtime.InteropServices;

namespace WindowsFormsApp9
{
    public partial class Form1 : Form
    {

        private const int SW_MINIMIZE = 6;

        [DllImport("user32.dll")]
        [return: MarshalAs(UnmanagedType.Bool)]
        static extern bool ShowWindow(IntPtr hWnd, int nCmdShow);

        private void Button1_Click(object sender, EventArgs e)
        {
            Process[] localByName = Process.GetProcessesByName("notepad");
            foreach (var item in localByName)
            {
                ShowWindow(item.MainWindowHandle, SW_MINIMIZE);
            }
        }

        public Form1()
        {
            InitializeComponent();
        }
    }
}
  • Thank you, Augusto Vasques

Browser other questions tagged

You are not signed in. Login or sign up in order to post.