Results 1 to 7 of 7

Thread: [VB2008 Express] API to determine selected ListBox item in an external application

  1. #1

    Thread Starter
    New Member
    Join Date
    Jul 2020
    Posts
    3

    Question [VB2008 Express] API to determine selected ListBox item in an external application

    Hello, this is my first post- I hope somebody can help.

    First of all, I am using Visual Basic 2008 Express.

    I am trying to write a Helper Utility for an application called RPG Maker MV, so in the application there is a ListBox and I am trying to determine which Item is currently highlighted:
    Name:  rmmv_window_caption.jpg
Views: 393
Size:  41.6 KB

    Looking at the application in UI Spy, the ListBox is a "tree" LocalizedControlType and doesn't appear to have a ClassName:
    Name:  UI_Spy.jpg
Views: 484
Size:  65.0 KB

    The RPG Maker MV main Window has a ClassName- "Qt5QWindowOwnDCIcon":
    Name:  UI_Spy_2.jpg
Views: 448
Size:  79.8 KB

    So I am able to write a function that detects the hWnd of that:
    Code:
    Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
    
    Function RMMVGetWindow()
            Dim hWnd As Long
            hWnd = FindWindow("Qt5QWindowOwnDCIcon", vbNullString)
            Return hWnd
    End Function
    But that's where my know-how ends. I do not know how to proceed from here, especially since the ListBox / "tree" doesn't have a ClassName.

    Would anybody know if there is a FindChildByControlType() or something similar that I could use to get the ListBox / "tree"'s hWnd?

    And then, after that, how do I extract which item is highlighted? Do I need to use SendMessage()?

    I'll appreciate any advice that I can get... thanks in advance!

  2. #2
    Frenzied Member
    Join Date
    Feb 2003
    Posts
    1,801

    Re: [VB2008 Express] API to determine selected ListBox item in an external applicatio

    Quote Originally Posted by aporokizzu View Post
    Hello, this is my first post- I hope somebody can help.

    First of all, I am using Visual Basic 2008 Express.

    I am trying to write a Helper Utility for an application called RPG Maker MV, so in the application there is a ListBox and I am trying to determine which Item is currently highlighted:
    Name:  rmmv_window_caption.jpg
Views: 393
Size:  41.6 KB

    Looking at the application in UI Spy, the ListBox is a "tree" LocalizedControlType and doesn't appear to have a ClassName:
    Name:  UI_Spy.jpg
Views: 484
Size:  65.0 KB

    The RPG Maker MV main Window has a ClassName- "Qt5QWindowOwnDCIcon":
    Name:  UI_Spy_2.jpg
Views: 448
Size:  79.8 KB

    So I am able to write a function that detects the hWnd of that:
    Code:
    Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
    
    Function RMMVGetWindow()
            Dim hWnd As Long
            hWnd = FindWindow("Qt5QWindowOwnDCIcon", vbNullString)
            Return hWnd
    End Function
    But that's where my know-how ends. I do not know how to proceed from here, especially since the ListBox / "tree" doesn't have a ClassName.

    Would anybody know if there is a FindChildByControlType() or something similar that I could use to get the ListBox / "tree"'s hWnd?

    And then, after that, how do I extract which item is highlighted? Do I need to use SendMessage()?

    I'll appreciate any advice that I can get... thanks in advance!
    Hello Aporokizzu. Welcome to the forum!

    You might want to look at this page: https://docs.microsoft.com/en-us/win...trol-reference. Also, there are a few programs on my Github page (see my signature) that deal with interacting with an external application's controls.

    yours,
    Peter Swinkels

  3. #3

    Thread Starter
    New Member
    Join Date
    Jul 2020
    Posts
    3

    Question Re: [VB2008 Express] API to determine selected ListBox item in an external applicatio

    Quote Originally Posted by Peter Swinkels View Post
    Hello Aporokizzu. Welcome to the forum!

    You might want to look at this page: https://docs.microsoft.com/en-us/win...trol-reference. Also, there are a few programs on my Github page (see my signature) that deal with interacting with an external application's controls.

    yours,
    Peter Swinkels
    Peter Swinkels, thank you for your welcome and response- I appreciate the link you gave me to the Tree View Control Reference and the self-promotion of your Git repository... I might just be a bit thick but, it doesn't really seem to answer my question!

    Let me try again-

    I need to be able to get the hWnd of the Tree View Control in the RPG Maker MV application, which is difficult because (as I explained in my OP) the class name of the Tree View Control (according to UI Spy) is just a blank string.

    So, I am asking, again, is there anyway to do a FindChildByControlType() using API so that I can use the parent hWnd (which I am able detect because I know the parent's class is "Qt5QWindowOwnDCIcon") and "ControlType.tree" (which I know is the Tree View's ControlType thanks to UI Spy) so I can determine the hWnd of the Tree View Control? (How does UI Spy determine that it is "ControlType.Tree"?)

    Secondly, once I've determined the Tree View's hWnd- what is the best way (using API) to determine which item is currently selected?

    I look forward to any and will be appreciative of any relevant answers to my query.

    Thanks!

  4. #4
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: [VB2008 Express] API to determine selected ListBox item in an external applicatio

    Quote Originally Posted by aporokizzu
    Would anybody know if there is a FindChildByControlType() or something similar that I could use to get the ListBox / "tree"'s hWnd?
    There are other utilities you can use which will display the hWnds of all windows. Maybe that "UI Spy" does? Just didn't see an hWnd for the selected item. But in this case it may not matter anyway.

    If there is no classname, then there is no hWnd to be used. All Windows have a classname. You may be looking at some custom windowless control, don't know. Can't be sure from what I'm looking at.
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  5. #5

    Thread Starter
    New Member
    Join Date
    Jul 2020
    Posts
    3

    Question Re: [VB2008 Express] API to determine selected ListBox item in an external applicatio

    Quote Originally Posted by LaVolpe View Post
    There are other utilities you can use which will display the hWnds of all windows. Maybe that "UI Spy" does? Just didn't see an hWnd for the selected item. But in this case it may not matter anyway.

    If there is no classname, then there is no hWnd to be used. All Windows have a classname. You may be looking at some custom windowless control, don't know. Can't be sure from what I'm looking at.
    LaVolpe- thank you for your reply... but again, this doesn't answer my question.

    I am sure that there are other utilities that can display the hWnd of the Tree View object, but the point is to have the Visual Basic 2008 program that I am trying to write determine its hWnd.

    So, I am asking, if there is a way- given that I can use a function to determine the hWnd of the object's parent- that I can search through all the objects within that parent hWnd by using their ControlType... that way if the ControlType matches "tree", my program will know that this is the object being searched for and return that object's hWnd.

    Also, it clearly does have a hWnd otherwise it wouldn't show up in UI Spy in the first place.

    Again, I am hoping that somebody who is knowledgeable in the subject can provide a relevant answer.

    What API function is UI Spy using to determine the ControlType of the objects?

    Thanks!

  6. #6
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: [VB2008 Express] API to determine selected ListBox item in an external applicatio

    Also, it clearly does have a hWnd otherwise it wouldn't show up in UI Spy in the first place.
    Then it has a classname. All windows are created from registered classes (globally or locally). If it has an hWnd, then that UI Spy tool isn't working properly.

    The API GetClassName can be used to retrieve the class of any hWnd.

    As for enumerating all the windows on any top level window, there are APIs for that too. Maybe look for examples using EnumChildWindows

    What API function is UI Spy using to determine the ControlType of the objects?
    Don't know, maybe the documentation will tell you. I'm not even sure what ControlType is in the context of that tool. For example: ControlType.Window? What does that even mean? All controls are windows, unless they are windowless.

    Edited: Don't know if that is the Microsoft UI Spy tool or not. If it is, then it uses UIAutomation[xxxx] family of DLLs. And if that's the same tool, then this is a note from Microsoft: "The UI Spy tool is obsolete and no longer available. Developers should use other tools such as Inspect.exe that are available in the Windows Software Development Kit (SDK)"
    Last edited by LaVolpe; Jul 27th, 2020 at 12:06 PM.
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  7. #7
    Frenzied Member
    Join Date
    Feb 2003
    Posts
    1,801

    Re: [VB2008 Express] API to determine selected ListBox item in an external applicatio

    Quote Originally Posted by aporokizzu View Post
    Peter Swinkels, thank you for your welcome and response- I appreciate the link you gave me to the Tree View Control Reference and the self-promotion of your Git repository... I might just be a bit thick but, it doesn't really seem to answer my question!

    Let me try again-

    I need to be able to get the hWnd of the Tree View Control in the RPG Maker MV application, which is difficult because (as I explained in my OP) the class name of the Tree View Control (according to UI Spy) is just a blank string.

    So, I am asking, again, is there anyway to do a FindChildByControlType() using API so that I can use the parent hWnd (which I am able detect because I know the parent's class is "Qt5QWindowOwnDCIcon") and "ControlType.tree" (which I know is the Tree View's ControlType thanks to UI Spy) so I can determine the hWnd of the Tree View Control? (How does UI Spy determine that it is "ControlType.Tree"?)

    Secondly, once I've determined the Tree View's hWnd- what is the best way (using API) to determine which item is currently selected?

    I look forward to any and will be appreciative of any relevant answers to my query.

    Thanks!
    You’re welcome. And yes, I admit to being guilty of self promotion. However I wouldn’t have recommended it unless I believed there would be something that really might help you. Did you actually look before dismissing it as just self promotion?

    yours,
    Peter Swinkels

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width