我正在研究扫描我的活动进程的应用程序,并且在选择之后将关键命令传递给该进程。我遇到的问题是,并非我所有的流程似乎都有MainWindowTitle
。下面是代码片段,我立即意识到了这个问题:对所有正在运行的进程不显示进程MainWindowTitle
Dictionary<int, string> procInfo = new Dictionary<int, string>();
Process[] processes = Process.GetProcesses();
foreach (Process procData in processes)
{
if (procData.MainWindowTitle.Length > 0)// || procData.ProcessName == "notepad++")
{
procInfo.Add(procData.Id, procData.ProcessName);
}
}
foreach (KeyValuePair<int, string> proc in procInfo)
{
lstProcesses.Items.Add(proc.Value + " (" + proc.Key.ToString() + ")");
}
如果你看一下第5行,你会看到我在那里迫使记事本++到列表中,以测试对来自WinSpy我的成绩++(替代间谍++)并且没有它拒绝显示的力量,因为它的MainWindowTitle
属性是空的。
没有MainWindowTitle
我无法为应用程序获取类名称:
//procID set earlier and shown to be working
Process proc = Process.GetProcessById(procID);
string winTitle = proc.MainWindowTitle;
IntPtr hWnd = proc.MainWindowHandle;
StringBuilder buffer = new StringBuilder(1024);
GetClassName(hWnd, buffer, buffer.Capacity);
string winCaption = buffer.ToString();
这样我就不能定位到应用程序中的关键命令传递:
//winCaption currently blank, winTitle tested and working
IntPtr appHandler = FindWindow(winCaption, winTitle);
SetForegroundWindow(appHandler);
SendKeys.SendWait("things and junk");
我有为我的项目设置适当的DllImports
,所以问题不存在,我还没有在这里找到答案或任何可靠的巡航其他互联网。我是否在代码中丢失了某些东西,或者这是不好的,我应该感觉不好吗?
可能的重复[为什么Process.MainWindowTitle总是空的除了一个窗口?](http://stackoverflow.com/questions/10063847/why-is-process-mainwindowtitle-always-empty-for-all-但一个窗口) – MethodMan 2014-11-24 20:40:41
我发现答案,虽然这是类似的,但我的问题遍及我的所有进程,而不仅仅是IE。 – 2014-11-24 21:10:15