Results 1 to 8 of 8

Thread: Read from Popup Menu

  1. #1

    Thread Starter
    New Member
    Join Date
    Mar 2008
    Posts
    8

    Question Read from Popup Menu

    I need the VB6 code that will be able to read the highlighted text from a popup menu generated by a separate application.

    This type of menu can be located using the following code.
    ‘Begin code
    Declare Function GetDesktopWindow Lib "User32" () As Long

    Declare Function FindWindowEx Lib "User32" Alias "FindWindowExA" (ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) As Long

    Hwnd = FindWindowEx(GetDesktopWindow(), ByVal 0&, "#32768", vbNullString)

    ‘end code

    What I need is a function that I can send the Hwnd for the menu to, and have it return the text of the selected item if any item is selected.

    Ideally, the function would return all text from the menu but must be able to determine which item is selected.

    Popup menus do not seem to respond to normal menu calls, such as GetMenuItemCount, GetMenuItemInfo . Can't use the mouse, this is an automation project.

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

    Re: Read from Popup Menu

    The more correct answer: You can't.
    You would have to subclass the other application and monitor its wm_menuselect messages and other messages as well. That still won't give you the text of the message; so other APIs will be required for that. VB can't, by itself, subclass stuff that exists in other processes, transferring text from one process to another can be tricky.

    Now if it is that important; at the moment I can think of one way: Find and use a subclassing DLL created in another language (there is one, I believe in the code bank section of this forum) that enables you to subclass windows in other processes. As always, using any subclassing leads to huge potential of crashes, both in your application and the other as well; worse case is bringing down the entire system -- be careful & expect nasty effects until you get all the bugs worked out.
    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}

  3. #3

    Thread Starter
    New Member
    Join Date
    Mar 2008
    Posts
    8

    Re: Read from Popup Menu

    I have a commercial product http://www.renovation-software.com/ (TextGRAB-SDK-2.1) that is capable of doing what I need so I know it can be done. Question is how are they doing it? .

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

    Re: Read from Popup Menu

    I already told you how it is being done. That app is not using VB to do the subclassing. It is using a DLL, probably created with C++, Delphi, Pascal or something else. Once you have access to a DLL that windows will allow you to use, subclassing and intercepting windows messages is a piece of cake. If you have no experience with subclassing, there is a big learning curve you must first overcome.
    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
    Mar 2008
    Posts
    8

    Re: Read from Popup Menu

    Yes, yes I understand Hooking and subclassing. I don’t have a good enough handle on it to do it by myself. I don’t have time to learn C++ or reinvent the wheel nor am I a master VB programmer as yourself. I’m sure that you understand darning and knitting but I doubt that you have a good enough handle on it to make yourself a pair of socks, and yet you are probably wearing a pair at this very moment. You were, however, somewhat helpful. You did mention that “(is one, I believe in the code bank section of this forum)” and I did find it. I am hoping that Mr. Moeur could give me a little of his time. He seem well seasoned and very generous with his experience. Thanks for the post.

  6. #6

    Thread Starter
    New Member
    Join Date
    Mar 2008
    Posts
    8

    Cool Re: Read from Popup Menu

    Solved. I figured it out myself. Taking a little here and a little there. See the attached demo.
    Attached Files Attached Files

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

    Re: Read from Popup Menu

    Haven't played with it yet. Is the MainHook.DLL from this site or did you get it from elsewhere? If from elsewhere, do you also have its source code? Curious.
    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}

  8. #8

    Thread Starter
    New Member
    Join Date
    Mar 2008
    Posts
    8

    Re: Read from Popup Menu

    It is from this site. http://www.vbforums.com/showthread.php?t=322261 I tried severalothers. One was very easy to use but wouldnot unhook at all. Crashes the app every time. The one frome here seems very stable.
    Last edited by SDG101; Mar 9th, 2008 at 10:27 PM.

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