Re: Specifying the parent when adding treeview nodes?

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



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?
.



Relevant Pages

  • Re: : )
    ... In Windows overlapped (forms are such a windows when TopLevel property is ... set to true) and popup windows doesn't have parent. ... They have owner. ... child windows have parent. ...
    (microsoft.public.dotnet.languages.csharp)
  • Enumeration Oddity - EnumChildWindows
    ... I have a program that enumerates all the open ... clicked and all the child windows should be enumerated. ... parent handle is XYZ but when I all ENumChildWindows for handle XYZ, ...
    (microsoft.public.vb.general.discussion)
  • Re: MDI Forms
    ... I read your posts back and forth from Garry and you and I fully understand where Garry is coming from. ... The user can still "RESTORE" the child window and see other child windows behind them, they can resize them, but the kind of app I'm making they will not have a use for seeing multiple windows. ... I am not sure if the same thing happens on non "MDI" apps, but I dont risk it anymore. ...
    (microsoft.public.dotnet.languages.vb)
  • Re: Group Membership Problem
    ... >> Domain A is The parent Windows 2000 ... >> Domain C is the Child Windows 2003 mixed ... > DCs must be first upgraded to Win2003 prior to upgrading any child domains. ... > /forestprep and adprep /domainprep have been run on the forest root domain. ...
    (microsoft.public.windows.server.active_directory)
  • Re: WS_EX_LAYERED/UpdateLayeredWindow with owned WS_CHILD windows
    ... child windows do NOT recieve their own WM_PAINT messages. ... I understand that a ULW window does not receive WM_PAINT messages. ... Whether an owner ULW window causes the WM_PAINT message to be ...
    (microsoft.public.win32.programmer.gdi)