简体   繁体   中英

Getting the active process in Compact Framework C#

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.GetProcessById() 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

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

如果GetwindowThreadProcessId使您失败,则可能获取所有进程并为每个进程调用EnumWindows将返回一个与前景窗口具有相同句柄的窗口。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM