none
Get Window Parent Class and Window RRS feed

  • Question

  • Apparently, in order to "SendKeys" to another open application's window, I need to know it's Parent Class and Parent Window, as in:

    Dim ParenthWnd As New IntPtr(0)

    Dim myParentClass As String = "Notepad"     
    Dim myParentWindow As String = "Untitled - Notepad"

    ParenthWnd = FindWindow(myParentClass, myParentWindow)     'this finds the notepad that I have previously opened

    But suppose I don't know the Class or Window? How can I retrieve it?

    Thank you.


    BiggyD

    Friday, July 20, 2018 11:45 PM

All replies

  • You can determine a window's caption and window class with Spy++.  I'm not sure if an installation of Visual Studio that did not include Visual C++ will have Spy++ installed.  In the event it is not available, the SDK UI Automation utility inspect.exe is also capable of identifying captions and classes.
    • Edited by RLWA32 Saturday, July 21, 2018 12:03 AM
    • Proposed as answer by Alex Li-MSFT Monday, July 23, 2018 3:07 AM
    Saturday, July 21, 2018 12:01 AM
  • Hi

    RLWA32 gives a good suggestion. If the window title of the external program to be searched is relatively easy to get, the problem is relatively simple. But if the title of the window is not fixed or there is no title at all, how do you get the class of the window? At this time, we can use Microsoft Spy ++, run Spy ++, press ALT + F3, drag the target icon to the program in the pop-up interface.

    Best Regards,

    Alex


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Monday, July 23, 2018 3:17 AM
  • [...]

    But suppose I don't know the Class or Window? How can I retrieve it?



    I think that FindWindow works even if you do not know Class or Window. Use Nothing instead of the string. At least one of the parameters should be specified.

    Monday, July 23, 2018 5:01 AM
  • [...]

    But suppose I don't know the Class or Window? How can I retrieve it?



    I think that FindWindow works even if you do not know Class or Window. Use Nothing instead of the string. At least one of the parameters should be specified.

    However, recognize that FindWindow will find the FIRST top-level window that satisfies the search criteria.  So for example, if there are multiple instances of Notepad.exe running, each with a different document, then just calling FindWindow to search for the Notepad window class may not return the desired window.  Similarly, more than one window could have the same caption.  So searching on only the caption could also return a window other than the desired target.

    In such cases you can use EnumWindows and when the callback function receives a window whose class or caption matches the single criteria you can then use anything else you know about the target window (e.g., number of child windows, class of child windows, etc.) to determine if you have found the target or should continue enumerating.

    Monday, July 23, 2018 9:45 AM