如果我在主窗口上有一个处理程序,我该如何处理子窗口?从进程中我看不到子窗口,但在桌面上我看到了它们。有人可以帮我打印主窗口的所有子窗口吗?
答案 0 :(得分:1)
Use System.Management;
//Return all processes
public static string ListAllProcesses()
{
StringBuilder sbAllProcess = new StringBuilder();
// list out all processes and write them into a stringbuilder
ManagementClass MgmtClass = new ManagementClass("Win32_Process");
foreach (ManagementObject mobject in MgmtClass.GetInstances())
{
sbAllProcess .Append("Name:\t" + mobject ["Name"] + Environment.NewLine);
sbAllProcess .Append("ID:\t" + mobject ["ProcessId"] + Environment.NewLine);
sbAllProcess .Append(Environment.NewLine);
}
return sbAllProcess .ToString();
}
//Return all applications
public static string ListAllApplications()
{
StringBuilder sbAllApplication = new StringBuilder();
foreach (Process runningProcess in Process.GetProcesses("."))
{
try
{
if (runningProcess .MainWindowTitle.Length > 0)
{
sbAllApplication .Append("Window Title:\t" + runningProcess .MainWindowTitle.ToString()+ Environment.NewLine);
sbAllApplication .Append("Process Name:\t" + runningProcess .ProcessName.ToString() + Environment.NewLine);
sbAllApplication .Append("Window Handle:\t" + runningProcess .MainWindowHandle.ToString() + Environment.NewLine);
sbAllApplication .Append("Memory Allocation:\t" + runningProcess .PrivateMemorySize64.ToString() + Environment.NewLine);
sbAllApplication .Append(Environment.NewLine);
}
}
catch { }
}
return sbAllApplication .ToString();
}
使用pinvoke.net/default.aspx/user32/EnumChildWindows.html Enumchildwindows你将了解特定窗口的子窗口的处理程序
答案 1 :(得分:0)
MdiChildren 会为您提供一组属于特定表单的所有表单。
您也可以使用 Application.OpenForms
获取表单