开发者

Getting the active process in Compact Framework C#

开发者 https://www.devze.com 2023-01-31 14:06 出处:网络
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 prog

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

0

精彩评论

暂无评论...
验证码 换一张
取 消