by xbyang » Thu Jan 14, 2010 7:15 am
Thank you for your reply. My algorithm is as following, it takes 10 seconds to read read the gui objects for 1 application.
private void CreateStateFromRealGUI()
{
Process process = Process.GetProcessById((int)YGUIStates.m_ProcessId);
if (process == null)
{
return;
}
try
{
foreach (Ranorex.Adapter a in Ranorex.Host.Local.Children) //Read the forms of the give process
{
string temp = a.ToString();
int i = temp.IndexOf(':');
if (i >= 0)
{
temp = temp.Substring(1, i - 1);
}
object o = a.Element.GetAttributeValue("ProcessId");
if (o != null)
{
int id = YOftenUsedFunctions.ToInt(o);
if (id == process.Id)
{
if (temp == "Form")
{
YWindow w = new YWindow();
w.relatedObj = a;
int no = m_GUIForms.Add(w);
w.ID = no;
w.ParentID = -1;
w.m_isForm = true;
w.m_WindowName = w.m_objectText;
}
}
}
}
foreach (YWindow win in m_GUIForms)
{
win.GetRealFormObjects(); //Create object tree for each window
}
}
catch { }
}
Class YWindow{ //the class of YWindow
....
public void GetRealFormObjects()
{
if (relatedObj == null) return;
GatherInfoFromAdapter((Ranorex.Adapter)relatedObj);
CreateObjects((Ranorex.Adapter)relatedObj, m_Children, -1, this);
}
void CreateObjects(Ranorex.Adapter tosearch, ArrayList subchildren, int parentID, YWindow w) //Load the object recursively
{
if (tosearch == null) return;
int c = tosearch.Children.Count;
if (c <= 0) return;
int i = 0;
for (i = 0; i < c; i++)
{
Ranorex.Adapter a = tosearch.Children[i];
YGUIObject obj = new YGUIObject();
int no = m_ObjectList.Add(obj);
obj.ParentID = parentID;
obj.ID = no;
obj.GatherInfoFromAdapter(a);
obj.relatedObj = a;
obj.m_Window = w;
subchildren.Add(no);
if (a.Children.Count > 0)
{
CreateObjects(a, obj.m_Children, no, w);
}
}
}
...
}