c# main window and child window
If I have a handler over a main window how can I handle the child windows? From processes i can't 开发者_StackOverflow社区see the child windows, but on the desktop i see them. Can someone help me to print all the child window that a main window has?
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();
}
Using pinvoke.net/default.aspx/user32/EnumChildWindows.html Enumchildwindows u will get to know handlers of child window of specific window
MdiChildren will give you a set of all forms belonging to a particular form.
Also you can get the forms using Application.OpenForms
精彩评论