Re: Specifying the parent when adding treeview nodes?
- From: SQACSharp <lsdisciples@xxxxxxxxxxx>
- Date: Tue, 27 Nov 2007 15:01:07 -0800 (PST)
Sorry it's hard to explain for me, so maybe you will understand the
problem of enumerating child windows and adding the node to the
correct parent with an example :
//...
private bool EnumChildWindowsCallBack(IntPtr hWnd, Int32 lParam)
{
System.Text.StringBuilder buffer = new
System.Text.StringBuilder(256);
GetClassName(hWnd, buffer, buffer.Capacity);
ChildWindows.Add(hWnd.ToString() + " " + buffer.ToString());
return true;
}
private bool EnumWindowCallback(IntPtr hWnd,UInt32 lParam)
{
System.Text.StringBuilder buffer = new
System.Text.StringBuilder(256);
GetClassName(hWnd, buffer, buffer.Capacity);
ChildWindows = new ArrayList();
EnumChildWindows(hWnd, new
EnumChildWindowsProc(EnumChildWindowsCallBack), 0);
ListOfWindows.Add(hWnd.ToString() + " " + buffer.ToString());
ListOfChildWindows.Add(ChildWindows);
return true;
}
//...
Process[] processlist = Process.GetProcesses();
int Counter = 0;
treeView1.BeginUpdate();
foreach (Process theprocess in processlist)
{
ProcessThreadCollection myThreads;
myThreads = theprocess.Threads;
int processId;
IntPtr ThreadID1 =
GetWindowThreadProcessId(theprocess.MainWindowHandle,IntPtr.Zero);
ListOfWindows = new ArrayList();
ListOfChildWindows = new ArrayList();
EnumThreadWndProc cb = new EnumThreadWndProc(EnumWindowCallback);
EnumThreadWindows((uint)ThreadID1, cb, 0);
//At this point ListOfWindows contains all the windows associated
to the process
//At this point ListOfChildWindows contains all the childs windows
associated to the window (kind of 2 dimension array)
// Add a node with the main process name
TreeNode MyNode = new TreeNode();
MyNode.Text = theprocess.ProcessName + " - " +
theprocess.MainWindowTitle + " [" + theprocess.Id.ToString() + "]";
Counter++;
int WindowCounter = 0;
foreach (string MyWindow in ListOfWindows)
{
// Add a node for each windows associated to the processId
MyNode.Nodes.Add(new TreeNode(MyWindow));
foreach (string child in
(ArrayList)ListOfChildWindows[WindowCounter])
{
//Add all the childs associated to the window
//*** PROBLEM BEGIN ***
//The following node must be added to the correct
parent..it's added to the same level as other windows for now
MyNode.Nodes.Add("->"+child.ToString());
//*** PROBLEM END ***
}
WindowCounter++;
}
}
The problem is when looping to add the child windows, the parent can
be my Window or another child...since EnumChildWindowsCallback list
child that can be parent of another child.
In other words i'm trying to match the child window to the correct
parent window node with something like (this is not valid ;o)) :
//Begin Fictive code
ParentHandle=GetParent(ChildHandle); //GetParent win32 api
ParentNodeObject=GetNodeObjectWithHandle(ParentHandle);
ParentNodeObject.Nodes.Add(Child.ToString());
//End Fictive code ;o)
How can i get a reference to to parent window?
.
- Follow-Ups:
- Re: Specifying the parent when adding treeview nodes?
- From: Peter Duniho
- Re: Specifying the parent when adding treeview nodes?
- References:
- Specifying the parent when adding treeview nodes?
- From: SQACSharp
- Re: Specifying the parent when adding treeview nodes?
- From: Nicholas Paldino [.NET/C# MVP]
- Specifying the parent when adding treeview nodes?
- Prev by Date: Re: Checking that an event has handlers added to it - using Reflection
- Next by Date: Re: Specifying the parent when adding treeview nodes?
- Previous by thread: Re: Specifying the parent when adding treeview nodes?
- Next by thread: Re: Specifying the parent when adding treeview nodes?
- Index(es):
Relevant Pages
|