Hello all!
Need a suggestion please.
After I get a process, how can I determine if it's main window / module is hidden or not please?
Because there are hidden window-modules running in the background which are system processes. I wanna get windows of apps that the user has opened manually (by clicking on their shortcuts etc). So I need to skip all system bg apps which their windows are hidden, to get to the manually open ones.
procs = Process.GetProcesses();foreach(Process proc in procs)
{// proc.??
}I tried checking MainWindowHandle's validity, but as the screengrab show, in the list i get, the only apps that i've manually executed are Visual Studio and few others. The ones like "Datacard Monitor", "MS text input application" are obviously system processes.


Thanks!


Sam HobbsRank #107 · 20.5K reputationPosted Oct 2, 2022, 6:59 AM EDT
Perhaps you can use p/Invoke to call the IsWindowVisible function. The window handle is in Process.MainWindowHandle.
Or maybe the following will help.
How to get only visible windows with enumwindows - CodeProject
https://www.codeproject.com/Questions/5303477/How-to-get-only-visible-windows-with-enumwindows
Sam HobbsRank #107 · 20.5K reputationPosted Sep 29, 2022, 2:17 AM EDT
I was going to reply to your previous post but then you deleted it.
I do not know what main window / module means. You still have not clarified that (that part is the same as the previous post). I understand what a main window is but I do not know what the slash "/" means. Does it mean or? I am not sure what it means for a module to be hidden.
The following is the code I was going to post for you. Does that work better? The important part is string.IsNullOrEmpty.
Process[] localAll = Process.GetProcesses(); StringBuilder sb = new StringBuilder(); foreach (Process p in localAll) if (!string.IsNullOrEmpty(p.MainWindowTitle) ) sb.AppendLine($"{p.ProcessName}\t{p.MainWindowTitle}");Kasun Lee152 reputationPosted Sep 29, 2022, 3:11 AM EDT
@Sam Hobbs Thanks for the input.
Sorry, forget about the module thing, it's just "A Window".
--
The code. I'm not really searching for empty window titles, but rather windows that are Hidden (not minimized, but the visibility is set to false). I did this in C++ a long time ago (VS6 days), but can't figure it out in C#.