Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Switch to process

Switch to process

Scheduled Pinned Locked Moved C#
helpquestion
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    Cliffer
    wrote on last edited by
    #1

    Hi all, I have to switch from one application to another, I have found this method: System.Diagnostics.Process.Start("application"); that allow me to open an application... Then when i press my button for the second time, i don't want to start a new application but i want to open the existing one. in this way: System.Diagnostics.Process[] myProcesses; myProcesses = System.Diagnostics.Process.GetProcessesByName("application"); i can know if my process is already running but now I don't know to show this application... Can someone help me?? Thanks a lot. Cliffer

    M 1 Reply Last reply
    0
    • C Cliffer

      Hi all, I have to switch from one application to another, I have found this method: System.Diagnostics.Process.Start("application"); that allow me to open an application... Then when i press my button for the second time, i don't want to start a new application but i want to open the existing one. in this way: System.Diagnostics.Process[] myProcesses; myProcesses = System.Diagnostics.Process.GetProcessesByName("application"); i can know if my process is already running but now I don't know to show this application... Can someone help me?? Thanks a lot. Cliffer

      M Offline
      M Offline
      Martin 0
      wrote on last edited by
      #2

      Hello, You could use the MainWindowHandle property of the process in combination with BringWindowtoTop method of user32.dll. [System.Runtime.InteropServices.DllImport("user32.dll")] public static extern int BringWindowToTop(IntPtr hwnd); public IntPtr HWND_TOPMOST =(IntPtr)(-1); public IntPtr HWND_NOTOPMOST =(IntPtr)(-2);

      //Your method
      System.Diagnostics.ProcessStartInfo psi;
      psi.WindowStyle = System.Diagnostics.ProcessWindowStyle.Maximized;
      psi.FileName = "???.exe";
      using(System.Diagnostics.Process process = new System.Diagnostics.Process())
      {
      process.Start(psi);
      process.WaitForInputIdle();
      BringWindowToTop(process.Handle);
      }

      I'm using this in .Net1.1, maybe in .Net 2.0 there is a more elegant way. Hope it helps! All the best, Martin

      C 1 Reply Last reply
      0
      • M Martin 0

        Hello, You could use the MainWindowHandle property of the process in combination with BringWindowtoTop method of user32.dll. [System.Runtime.InteropServices.DllImport("user32.dll")] public static extern int BringWindowToTop(IntPtr hwnd); public IntPtr HWND_TOPMOST =(IntPtr)(-1); public IntPtr HWND_NOTOPMOST =(IntPtr)(-2);

        //Your method
        System.Diagnostics.ProcessStartInfo psi;
        psi.WindowStyle = System.Diagnostics.ProcessWindowStyle.Maximized;
        psi.FileName = "???.exe";
        using(System.Diagnostics.Process process = new System.Diagnostics.Process())
        {
        process.Start(psi);
        process.WaitForInputIdle();
        BringWindowToTop(process.Handle);
        }

        I'm using this in .Net1.1, maybe in .Net 2.0 there is a more elegant way. Hope it helps! All the best, Martin

        C Offline
        C Offline
        Cliffer
        wrote on last edited by
        #3

        Yes thanks this work fine... The only problem is that I hope to find a method that works without import user32.dll So now i work with this but if someone know a method that not use user32.dll it would be better.. thanks

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups