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