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. Set window on top from ShellExecute?

Set window on top from ShellExecute?

Scheduled Pinned Locked Moved C#
3 Posts 3 Posters 1 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.
  • K Offline
    K Offline
    kenw232
    wrote on last edited by
    #1

    I'm using shellexecute in .NET 4.5 to run an program like notepad.

    Process newProcess = new Process();
    newProcess.StartInfo.UseShellExecute = true;
    newProcess.StartInfo.FileName = "C:\Windows\Notepad.exe";
    newProcess.Start();

    How do I set this notepad.exe that it runs to be the top most window?

    L B 2 Replies Last reply
    0
    • K kenw232

      I'm using shellexecute in .NET 4.5 to run an program like notepad.

      Process newProcess = new Process();
      newProcess.StartInfo.UseShellExecute = true;
      newProcess.StartInfo.FileName = "C:\Windows\Notepad.exe";
      newProcess.Start();

      How do I set this notepad.exe that it runs to be the top most window?

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      You're running a process, one which may or may not open a multitude of windows. The "top most" is a highly contested place; my 3G connection thinks it is the most important application on my machine, but my MP3 player sometimes has similar feelings*. It is frustrating to see them fight for focus while reading your answer. You can enumerate which windows a process opened. Find yours, and set the WS_EX_TOPMOST[^] style. --edit; *) there can be only one :)

      Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^][](X-Clacks-Overhead: GNU Terry Pratchett)

      1 Reply Last reply
      0
      • K kenw232

        I'm using shellexecute in .NET 4.5 to run an program like notepad.

        Process newProcess = new Process();
        newProcess.StartInfo.UseShellExecute = true;
        newProcess.StartInfo.FileName = "C:\Windows\Notepad.exe";
        newProcess.Start();

        How do I set this notepad.exe that it runs to be the top most window?

        B Offline
        B Offline
        BillWoodruff
        wrote on last edited by
        #3

        I think the code in this solution to a QA question here: [^] will show you how to make the instance of NotePad.exe the top-most Window using the 'SetForeGroundWindow API call.

        «There is a spectrum, from "clearly desirable behaviour," to "possibly dodgy behavior that still makes some sense," to "clearly undesirable behavior." We try to make the latter into warnings or, better, errors. But stuff that is in the middle category you don’t want to restrict unless there is a clear way to work around it.» Eric Lippert, May 14, 2008

        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