【问题标题】:Getting the active process in Compact Framework C#在 Compact Framework C# 中获取活动进程
【发布时间】:2011-05-27 23:33:13
【问题描述】:
我要做的是获取拥有当前从另一个进程获得焦点的窗口的可执行文件的名称。该计划的目的是跟踪您在每个计划中花费的时间。
我尝试使用 GetWindowThreadProcessId(GetForegroundWindow()) (都在“coredll.dll”中)然后在其上使用 Process.GetProcessById() 来执行此操作,但我得到的进程对象总是有 Process.StartInfo.FileName 的“”。它似乎在 Windows Mobile 中无法正常工作。有谁知道如何做到这一点?谢谢
【问题讨论】:
标签:
c#
windows-mobile
compact-framework
【解决方案1】:
如果 GetwindowThreadProcessId 失败,也许获取所有进程并为每个进程调用 EnumWindows 将返回一个与前台窗口具有相同句柄的窗口。
【解决方案2】:
我使用 OpenNETCF 库:
string appName = string.Format("{0}.exe", Assembly.GetExecutingAssembly().GetName().Name.ToLower());
var processes = ProcessEntry.GetProcesses().Where(p => appName.Equals(p.ExeFile.ToLower()));
当前进程正在进程中