Cheap Web Hosting Providers
C# Programming‎ > ‎

Find Main Window of Other Process


To find window handle of main windows of any process we can make use of System.Diagnostics.Process class which has following related methods               

IntPtr MainWindowHandle()         // Gets the caption of the main window of the process & returns :   The process's main window title. 
          string MainWindowTitle()           //  Gets the caption of the main window of the process.


        private void button1_Click(object sender, EventArgs e)
        {
            listBox1.Visible = false;
            listBox1.Items.Clear();

            try
            {
                Process[] prlist = Process.GetProcessesByName(textBox1.Text);    // return list of processes with matching name

                foreach (Process p in prlist)
                {
                   listBox1.Items.Add( p.MainWindowHandle.ToString().PadRight(10) +
                                                 p.MainWindowTitle);
                }
                listBox1.Visible = true;
            }
            catch (Exception ex)
            {
                
                throw ex;
            }
        }

A complete application is attached below.

Comments

Č
ċ
ď
MainWindow.zip
(33k)
Rajesh NK,
Jul 23, 2010 10:52 AM