private ScalingMode TabStripScalingMode() { IntPtr containerHandle = NM.GetAncestor(Handle, NM.GetAncestorFlags.GetParent); NM.tagPoint containerClientPoint = new NM.tagPoint(); NM.ClientToScreen(containerHandle, ref containerClientPoint); NM.tagPoint clientPoint = new NM.tagPoint(); NM.ClientToScreen(Handle, ref clientPoint); int containerOffsetX = clientPoint.x - containerClientPoint.x; int containerOffsetY = clientPoint.y - containerClientPoint.y; int placement = TabStripPlacement(); switch (placement) { case 0: //Top case 1: //Bottom GUI.m_APE.AddFirstMessageFindByHandle(DataStores.Store0, Identity.ParentHandle, Identity.Handle); GUI.m_APE.AddQueryMessageReflect(DataStores.Store0, DataStores.Store1, "ClientLeft", MemberTypes.Property); GUI.m_APE.AddRetrieveMessageGetValue(DataStores.Store1); GUI.m_APE.SendMessages(EventSet.APE); GUI.m_APE.WaitForMessages(EventSet.APE); //Get the value(s) returned MUST be done straight after the WaitForMessages call int clientLeft = (int)(Math.Round(GUI.m_APE.GetValueFromMessage())); if (clientLeft - containerOffsetX < 10) { return(ScalingMode.Pixel); } if (TwipsToPixels(clientLeft, Direction.Horizontal) - containerOffsetX < 10) { return(ScalingMode.Twip); } throw GUI.ApeException("Unsupported scaling mode"); case 2: //Left case 3: //Right GUI.m_APE.AddFirstMessageFindByHandle(DataStores.Store0, Identity.ParentHandle, Identity.Handle); GUI.m_APE.AddQueryMessageReflect(DataStores.Store0, DataStores.Store1, "ClientTop", MemberTypes.Property); GUI.m_APE.AddRetrieveMessageGetValue(DataStores.Store1); GUI.m_APE.SendMessages(EventSet.APE); GUI.m_APE.WaitForMessages(EventSet.APE); //Get the value(s) returned MUST be done straight after the WaitForMessages call int clientTop = (int)(Math.Round(GUI.m_APE.GetValueFromMessage())); if (clientTop - containerOffsetY < 10) { return(ScalingMode.Pixel); } if (TwipsToPixels(clientTop, Direction.Vertical) - containerOffsetY < 10) { return(ScalingMode.Twip); } throw GUI.ApeException("Unsupported scaling mode"); default: throw GUI.ApeException("The " + Description + " placement is of unsupported type " + placement.ToString()); } }
private unsafe void DumpControl(Message *ptrMessage, int messageNumber) { //must be first message if (messageNumber != 1) { throw new Exception("DumpControl must be first message"); } CleanUpMessage(ptrMessage); StringBuilder dump = new StringBuilder(); //Get the buckets Array hashBuckets = (Array)HashBucketsArrayFieldInfo.GetValue(null); for (int item = 0; item < hashBuckets.Length; item++) { IntPtr handle = (IntPtr)HashBucketHandleFieldInfo.GetValue(hashBuckets.GetValue(item)); if (handle == IntPtr.Zero || handle == MinusOneIntPtr) { //Nothing as not a real window handle } else { Control control = Control.FromHandle(handle); if (control == null) { GCHandle gcHandle = (GCHandle)HashBucketGCHandleFieldInfo.GetValue(hashBuckets.GetValue(item)); Type controlType = gcHandle.Target.GetType(); dump.Append("TypeName: " + controlType.Name); dump.Append(" TypeNameSpace: " + controlType.Namespace); dump.Append(" ModuleName: " + controlType.Module.Name); } else { dump.Append("Name: " + control.Name); Type controlType = control.GetType(); dump.Append(" TypeName: " + controlType.Name); dump.Append(" TypeNameSpace: " + controlType.Namespace); dump.Append(" ModuleName: " + controlType.Module.Name); } //IntPtr parent = NM.GetAncestor(handle, NM.GetAncestorFlags.GetRoot); IntPtr parent = NM.GetAncestor(handle, NM.GetAncestorFlags.GetParent); dump.Append(" Handle: " + handle.ToString()); dump.Append(" Parent: " + parent.ToString()); dump.AppendLine(); } } AddReturnValue(new Parameter(this, dump.ToString())); }
private void AddToolStripDropDownMenuToPropertyListbox() { int Items; IntPtr temp; temp = m_Identity.ParentHandle; m_Identity.ParentHandle = NM.GetAncestor(m_Identity.Handle, NM.GetAncestorFlags.GetRootOwner); //Get the number of items on the menustrip m_APE.AddFirstMessageFindByHandle(DataStores.Store0, m_Identity.ParentHandle, m_Identity.Handle); m_APE.AddQueryMessageReflect(DataStores.Store0, DataStores.Store1, "Items", MemberTypes.Property); m_APE.AddQueryMessageReflect(DataStores.Store1, DataStores.Store2, "Count", MemberTypes.Property); m_APE.AddRetrieveMessageGetValue(DataStores.Store2); m_APE.SendMessages(EventSet.APE); m_APE.WaitForMessages(EventSet.APE); //get the values returned Items = m_APE.GetValueFromMessage(); //Loop through all items for (int Item = 0; Item < Items; Item++) { m_APE.AddFirstMessageFindByHandle(DataStores.Store0, m_Identity.ParentHandle, m_Identity.Handle); m_APE.AddQueryMessageReflect(DataStores.Store0, DataStores.Store1, "Items", MemberTypes.Property); m_APE.AddQueryMessageReflect(DataStores.Store1, DataStores.Store2, "Item", MemberTypes.Property, new Parameter(m_APE, Item)); m_APE.AddQueryMessageReflect(DataStores.Store2, DataStores.Store3, "Text", MemberTypes.Property); m_APE.AddRetrieveMessageGetValue(DataStores.Store3); m_APE.SendMessages(EventSet.APE); m_APE.WaitForMessages(EventSet.APE); //get the values returned string ItemText = m_APE.GetValueFromMessage(); PropertyListbox.Items.Add("Menu item\t: " + ItemText); } m_Identity.ParentHandle = temp; }
private void IdentifyButton_Click(object sender, EventArgs e) { m_CurrentAttached = (KeyValuePair <Process, string>)WinformsProcessesCombobox.SelectedItem; if (m_CurrentAttached.Key.HasExited) { WinformsProcessesCombobox.SelectedIndex = 0; Populate(); return; } IdentifyButton.Enabled = false; WinformsProcessesCombobox.Enabled = false; label1.Text = "Move the mouse cursor over the desired window and then press the control key"; //install hotkey hook for control key if (!NM.RegisterHotKey(this.Handle, 1, NM.MOD_CONTROL, NM.VK_CONTROL)) { throw new Exception("Failed to register hotkey"); } m_ControlKey = false; IntPtr OldHandle = IntPtr.Zero; while (m_ControlKey == false) { Point cursorPosition = Cursor.Position; NM.tagPoint screenLocation; NM.tagPoint Location; IntPtr Handle; IntPtr ChildWindow; IntPtr parent = NM.GetDesktopWindow(); screenLocation.x = cursorPosition.X; screenLocation.y = cursorPosition.Y; while (true) { Location = screenLocation; NM.ScreenToClient(parent, ref Location); ChildWindow = NM.RealChildWindowFromPoint(parent, Location); if (ChildWindow == IntPtr.Zero || parent == ChildWindow) { Handle = parent; break; } parent = ChildWindow; } uint Pid; NM.GetWindowThreadProcessId(Handle, out Pid); if (Handle != OldHandle) { if (OldHandle != IntPtr.Zero) { ClearHighlight(m_Area); } if (m_CurrentAttached.Key.Id == Pid) { PopulatePropertyListbox(NM.GetAncestor(Handle, NM.GetAncestorFlags.GetRoot), Handle); Highlight(Handle); OldHandle = Handle; } else { OldHandle = IntPtr.Zero; } } Application.DoEvents(); Thread.Sleep(100); } if (OldHandle != IntPtr.Zero) { ClearHighlight(m_Area); TreeNode[] Nodes = WindowTree.Nodes.Find(m_Identity.ParentHandle.ToString() + ":" + m_Identity.Handle.ToString(), true); if (Nodes.GetLength(0) == 0) { BuildTree(); Nodes = WindowTree.Nodes.Find(m_Identity.ParentHandle.ToString() + ":" + m_Identity.Handle.ToString(), true); } if (Nodes.GetLength(0) > 0) { WindowTree.SelectedNode = Nodes[0]; WindowTree.Focus(); } } if (!m_Closing) { NM.UnregisterHotKey(this.Handle, 1); label1.Text = ""; IdentifyButton.Enabled = true; WinformsProcessesCombobox.Enabled = true; } }
private void FindByIdentifierRenderedActiveX(ControlIdentifier identifier, ref IntPtr handle, ref string name, ref string theText, ref string typeNameSpace, ref string typeName, ref string technologyType, ref string uniqueId, ref bool foundControl) { IntPtr parentHandle = IntPtr.Zero; int currentIndex = 0; if (Ax.Items.Count > 0) { lock (Ax.AxItemsLock) { object control = null; int item; int items = Ax.Items.Count; for (item = 0; item < items; item++) { if (Ax.Items[item].Control == null) { continue; } handle = Ax.Items[item].Handle; parentHandle = Ax.Items[item].ParentHandle; name = Ax.Items[item].Name; uniqueId = Ax.Items[item].UniqueId; control = Ax.Items[item].Control; if (identifier.ParentHandle == parentHandle || NM.GetAncestor(identifier.ParentHandle, NM.GetAncestorFlags.GetRoot) == parentHandle || (identifier.ParentHandle == IntPtr.Zero && parentHandle == handle)) { } else { continue; } if (!NM.IsWindowVisible(handle)) { continue; } //if (!Ax.Items[item].Rendered) //{ // continue; //} if (identifier.Name != null) { if (name != identifier.Name) { continue; } } if (identifier.TechnologyType != null) { if ("Windows ActiveX" != identifier.TechnologyType) { continue; } } if (identifier.TypeNameSpace != null) { typeNameSpace = Ax.Items[item].TypeNameSpace; //Lazy load it only if we need it if (typeNameSpace == null) { continue; } else { if (!Regex.IsMatch(typeNameSpace, identifier.TypeNameSpace)) { continue; } } } if (identifier.TypeName != null) { typeName = Ax.Items[item].TypeName; //Lazy load it only if we need it if (typeName == null) { continue; } else { if (!Regex.IsMatch(typeName, identifier.TypeName)) { continue; } } } if (identifier.ModuleName != null) { if (Path.GetFileName(NM.GetWindowModuleFileName(handle)) != identifier.ModuleName) { continue; } } if (identifier.AssemblyName != null) { continue; } if (identifier.ChildOf != IntPtr.Zero) { if (identifier.ChildOf == handle || NM.IsChild(identifier.ChildOf, handle)) { } else { continue; } } if (identifier.SiblingOf != IntPtr.Zero) { continue; } if (identifier.ParentOf != IntPtr.Zero) { continue; } //Make sure the type name space and type name are populated typeName = Ax.Items[item].TypeName; typeNameSpace = Ax.Items[item].TypeNameSpace; if (typeName == "Label" && string.IsNullOrEmpty(typeNameSpace)) { theText = (string)m_ComReflectDelegater.Invoke("Caption", Ax.Items[item].Control, null); } if (identifier.Text != null) { if (theText == null) { continue; } else { if (!Regex.IsMatch(theText, identifier.Text)) { continue; } } } if (identifier.AccessibilityObjectName != null) { continue; } currentIndex++; if (identifier.Index > 0) { if (currentIndex != identifier.Index) { continue; } } technologyType = "Windows ActiveX"; //WF.MessageBox.Show("Found handle: " + name + " " + handle.ToString()); foundControl = true; return; } } } }
private Rectangle TabRectangle(int actualTabIndex) { int x; int y; int width; int height; switch (Identity.TechnologyType) { case "Windows Forms (WinForms)": GUI.m_APE.AddFirstMessageFindByHandle(DataStores.Store0, Identity.ParentHandle, Identity.Handle); GUI.m_APE.AddQueryMessageReflect(DataStores.Store0, DataStores.Store1, "GetTabRect", MemberTypes.Method, new Parameter(GUI.m_APE, actualTabIndex)); GUI.m_APE.AddQueryMessageReflect(DataStores.Store1, DataStores.Store2, "X", MemberTypes.Property); GUI.m_APE.AddQueryMessageReflect(DataStores.Store1, DataStores.Store3, "Y", MemberTypes.Property); GUI.m_APE.AddQueryMessageReflect(DataStores.Store1, DataStores.Store4, "Width", MemberTypes.Property); GUI.m_APE.AddQueryMessageReflect(DataStores.Store1, DataStores.Store5, "Height", MemberTypes.Property); GUI.m_APE.AddRetrieveMessageGetValue(DataStores.Store2); GUI.m_APE.AddRetrieveMessageGetValue(DataStores.Store3); GUI.m_APE.AddRetrieveMessageGetValue(DataStores.Store4); GUI.m_APE.AddRetrieveMessageGetValue(DataStores.Store5); GUI.m_APE.SendMessages(EventSet.APE); GUI.m_APE.WaitForMessages(EventSet.APE); //Get the value(s) returned MUST be done straight after the WaitForMessages call x = GUI.m_APE.GetValueFromMessage(); y = GUI.m_APE.GetValueFromMessage(); width = GUI.m_APE.GetValueFromMessage(); height = GUI.m_APE.GetValueFromMessage(); break; case "Windows ActiveX": switch (Identity.TypeName) { case "SftTabs": GUI.m_APE.AddFirstMessageFindByHandle(DataStores.Store0, Identity.ParentHandle, Identity.Handle); GUI.m_APE.AddQueryMessageReflect(DataStores.Store0, DataStores.Store1, "Tab", MemberTypes.Method, new Parameter(GUI.m_APE, actualTabIndex)); GUI.m_APE.AddQueryMessageGetTabRect(DataStores.Store1); GUI.m_APE.SendMessages(EventSet.APE); GUI.m_APE.WaitForMessages(EventSet.APE); //Get the value(s) returned MUST be done straight after the WaitForMessages call x = GUI.m_APE.GetValueFromMessage(); y = GUI.m_APE.GetValueFromMessage(); width = GUI.m_APE.GetValueFromMessage(); height = GUI.m_APE.GetValueFromMessage(); break; case "TabStrip": GUI.m_APE.AddFirstMessageFindByHandle(DataStores.Store0, Identity.ParentHandle, Identity.Handle); GUI.m_APE.AddQueryMessageReflect(DataStores.Store0, DataStores.Store1, "Tabs", MemberTypes.Method, new Parameter(GUI.m_APE, actualTabIndex)); GUI.m_APE.AddQueryMessageReflect(DataStores.Store1, DataStores.Store2, "Left", MemberTypes.Property); GUI.m_APE.AddQueryMessageReflect(DataStores.Store1, DataStores.Store3, "Top", MemberTypes.Property); GUI.m_APE.AddQueryMessageReflect(DataStores.Store1, DataStores.Store4, "Width", MemberTypes.Property); GUI.m_APE.AddQueryMessageReflect(DataStores.Store1, DataStores.Store5, "Height", MemberTypes.Property); GUI.m_APE.AddRetrieveMessageGetValue(DataStores.Store2); GUI.m_APE.AddRetrieveMessageGetValue(DataStores.Store3); GUI.m_APE.AddRetrieveMessageGetValue(DataStores.Store4); GUI.m_APE.AddRetrieveMessageGetValue(DataStores.Store5); GUI.m_APE.SendMessages(EventSet.APE); GUI.m_APE.WaitForMessages(EventSet.APE); //Get the value(s) returned MUST be done straight after the WaitForMessages call x = (int)(Math.Round(GUI.m_APE.GetValueFromMessage())); y = (int)(Math.Round(GUI.m_APE.GetValueFromMessage())); width = (int)(Math.Round(GUI.m_APE.GetValueFromMessage())); height = (int)(Math.Round(GUI.m_APE.GetValueFromMessage())); IntPtr containerHandle = NM.GetAncestor(Handle, NM.GetAncestorFlags.GetParent); NM.tagPoint containerClientPoint = new NM.tagPoint(); NM.ClientToScreen(containerHandle, ref containerClientPoint); NM.tagPoint clientPoint = new NM.tagPoint(); NM.ClientToScreen(Handle, ref clientPoint); int containerOffsetX = clientPoint.x - containerClientPoint.x; int containerOffsetY = clientPoint.y - containerClientPoint.y; ScalingMode scaleMode = TabStripScalingMode(); switch (scaleMode) { case ScalingMode.Twip: //Twip x = TwipsToPixels(x, Direction.Horizontal); y = TwipsToPixels(y, Direction.Vertical); width = TwipsToPixels(width, Direction.Horizontal); height = TwipsToPixels(height, Direction.Vertical); break; case ScalingMode.Pixel: //Pixel //do nothing break; case ScalingMode.User: case ScalingMode.Point: case ScalingMode.Character: case ScalingMode.Inch: case ScalingMode.Millimeter: case ScalingMode.Centimeter: throw GUI.ApeException("The " + Description + " scaling mode is of unsupported type " + scaleMode.ToString()); default: throw GUI.ApeException("The " + Description + " scaling mode is of unsupported type " + scaleMode.ToString()); } x = x - containerOffsetX; y = y - containerOffsetY; int placement = TabStripPlacement(); switch (placement) { case 0: //Top case 1: //Bottom //do nothing break; case 2: //Left case 3: //Right //swap width and height int temp = width; width = height; height = temp; break; default: throw GUI.ApeException("The " + Description + " placement is of unsupported type " + placement.ToString()); } break; default: throw GUI.ApeException("The " + Description + " is of an unsupported type " + Identity.TypeNameSpace + "." + Identity.TypeName); } break; default: throw GUI.ApeException("The " + Description + " is of an unsupported type " + Identity.TypeNameSpace + "." + Identity.TypeName); } Rectangle tabRectangle = new Rectangle(x, y, width, height); return(tabRectangle); }