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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C#
  4. Get a window of other application topmost

Get a window of other application topmost

Scheduled Pinned Locked Moved C#
csharpquestion
4 Posts 4 Posters 4 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.
  • O Offline
    O Offline
    outerlimit
    wrote on last edited by
    #1

    Hi, I want to start a new application from my C# program.(this part works ;) ) This new window should then get maximized and topmost. I tried it with WinAPI calls but I was not successful. Is there a way to do this ? Thanks in advance, outerlimit

    K C M 3 Replies Last reply
    0
    • O outerlimit

      Hi, I want to start a new application from my C# program.(this part works ;) ) This new window should then get maximized and topmost. I tried it with WinAPI calls but I was not successful. Is there a way to do this ? Thanks in advance, outerlimit

      K Offline
      K Offline
      kkun
      wrote on last edited by
      #2

      The Form has a boolean TopMost property , set it to true then will topmost , if their two application runs ,and both of them set TopMost to true , then ,which one modified last will be effective ,

      1 Reply Last reply
      0
      • O outerlimit

        Hi, I want to start a new application from my C# program.(this part works ;) ) This new window should then get maximized and topmost. I tried it with WinAPI calls but I was not successful. Is there a way to do this ? Thanks in advance, outerlimit

        C Offline
        C Offline
        Christian Graus
        wrote on last edited by
        #3

        You should post your code so we can see what you're trying

        Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog "I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )

        1 Reply Last reply
        0
        • O outerlimit

          Hi, I want to start a new application from my C# program.(this part works ;) ) This new window should then get maximized and topmost. I tried it with WinAPI calls but I was not successful. Is there a way to do this ? Thanks in advance, outerlimit

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

          Hello, You have to 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);
          }    
          

          Hope it helps! All the best, Martin

          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