![]() ![]() The specific method required to get the text of a control depends on the previously mentioned class type of the control. *But this does not work for all controls. You can sometimes get the text of a control using GetWindowText(): (v=vs.85).aspx If you are looking for a specific one then you need to find it based on its position in the control hierarchy relative to its parent container and possibly its siblings. ![]() Note that in an application there may be many instances of a particular class type in existence. You can use tools like Spy++ or WinSpector to inspect an application and determine what the class type is for a particular control. At run-time, controls simply have a handle, and even then some controls are "lightweight" and do not have a handle at all (they are rendered directly to the screen by something else that has a handle).Ĭontrols do have a CLASS TYPE, however, which you can determine with GetClassName(): (v=vs.85).aspxĮxamples of class types could be "Button", "TextBox", etc, but there is no universal naming convention as each language often has its own names that it uses. ![]() Names are something you do at design-time. "What I'm trying to do is identify the control name of a control that is under the mouse cursor, regardless of the application it's in."įor the most part, things do not have names at run-time. Public Class Form1 Public Declare Function WindowFromPoint Lib "user32" (ByVal pt As PointAPI) As IntPtr Private prevHandle As IntPtr Public Structure PointAPI Public X As Integer Public Y As Integer Public Sub New(ByVal x As Integer, ByVal y As Integer) Me.X = x Me.Y = y End Sub End Structure Private Sub tmr1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tmr1.Tick Dim pt As New PointAPI(, ) Dim handle As IntPtr = WindowFromPoint(pt) If Not handle.Equals(prevHandle) Then txtOutput.Text = txtOutput.Text & vbCrLf & "New - " & handle.ToString("X") txtOutput.SelectionStart = txtOutput.ScrollToCaret() End If prevHandle = handle End Sub Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) prevHandle = IntPtr.Zero End Sub End Class On the form I have a timer control and a multiline text box control. Here is the code I have at the moment that will determine the window under the mouse cursor, which also appears to identify child windows, but I'm not sure how to drill down further. Perhaps part of my stumbling block as well, is that I'm not sure whether there is a distinct different in class between, say the control panel items, items in a pull down menu (like the Programs menu within the Start button), or controls on a dialog like Internet Explorer Options ones. If I could get the hWnd and caption / text of that item, that would be great. As an example, if all windows are minimised, except the control panel, I would like to know which of the menu items the mouse was over. What I'm trying to do is identify the control name of a control that is under the mouse cursor, regardless of the application it's in. I've been trying to figure out how to reach my goal, but I think I'm not understanding the function heirarchy required to get there. ![]()
0 Comments
Leave a Reply. |