What I am trying to do is get the name of the executable that owns the window that currently has focus from another process. The purpose of the program is to track how much time you spend in each program. I tried to do this with GetWindowThreadProcessId(GetForegroundWindow()) (both in "coredll.dll") then use Process.GetProc开发者_如何学JAVAessById() on that, but the process object I get always has "" for Process.StartInfo.FileName. It doesn't seem to work properly in Windows Mobile. Does anyone know how this could be done? Thanks
If GetwindowThreadProcessId fails you, perhaps getting all processes and calling EnumWindows for each process will return a window with the same handle as the foreground window.
I use OpenNETCF library:
string appName = string.Format("{0}.exe", Assembly.GetExecutingAssembly().GetName().Name.ToLower());
var processes = ProcessEntry.GetProcesses().Where(p => appName.Equals(p.ExeFile.ToLower()));
and current process is in processes
精彩评论