I need to get window handle of minimized window in tray. I know process name, but it has not MainWindowHandle set because it is minimized. How do I get to know the window handle?
Asked
Active
Viewed 217 times
-1
-
Why do you need a window handle of a process that is not showing a window? – BlueMonkMN Oct 30 '14 at 15:06
-
I need to close the application with WM_CLOSE message - for that I need window handle. – Egres Oct 30 '14 at 15:08
-
The premise of the question is nonsensical, a process with a minimized main window certainly *does* have its MainWindowHandle property set. Just try it with Notepad for example. – Hans Passant Oct 30 '14 at 15:20
-
possible duplicate of [How to Close another Process from c#](http://stackoverflow.com/questions/6046916/how-to-close-another-process-from-c-sharp) – BlueMonkMN Oct 30 '14 at 15:43
1 Answers
1
If the goal is to close the main window to end the process, there's a pretty straightforward way of doing that using the System.Diagnostics.Process
object. This example closes the first instance it finds of Notepad.
var procs = System.Diagnostics.Process.GetProcessesByName("Notepad");
if (procs.Length > 0)
procs[0].CloseMainWindow();
foreach (var proc in procs)
proc.Dispose();

BlueMonkMN
- 25,079
- 9
- 80
- 146