locked
Retrieving info from other windows RRS feed

  • Question

  • How can I retrieve info from other windows? For example, what should I use to get the http adress from Firefox from the most active window? Or the playlist in currently running WMP?
    Friday, August 4, 2006 1:04 AM

Answers

  • Alright, it is possible to get the URL entered in Firefox.  You have a few options.

    1) Create a firefox extension, which I assume has access to the url. Make the extension able to communicate with your program.
    2) Unfortunately, the address bar does not have its own window handle. Still, it is possible using the Active Accessibility SDK. Try downloading AccExplorer32.exe from Microsoft, and you'll notice that you can target the address bar and it will retrieve the value. For some VB6 sample code illustrating the process of navigating the accessible window hierarchy, take a look at http://www.jsware.net/jsware/vbcode.php3 under Active Accessibility.
    3) Alright, this is a really ugly hack. You could give firefox the focus, use SendKeys to send Ctrl+L (which selects the address bar). Send Ctrl+A, Ctrl+C, and then you have it on the clipboard, if you're lucky. Make sure that you save the previous state of the clipboard and then restore it. It's possible that the address bar was already selected, in which case you'll have to do it again.

    Personally, I would try #2, and I would never do #3--but it could be an option for personal use, as long as you don't distribute the application.

    No clue about getting the currently playing song, although it may be difficult. I know it's easy in iTunes, so hopefully WMP exposes a similar interface.
    Friday, August 4, 2006 3:40 PM
  • The 0x001c02a4 value is probably not a constant, so I don't think you can use that.  What you're going to have to do is something like the sample code on http://www.pinvoke.net/default.aspx/user32.FindWindowEx to get the URL from IE.  First, find the main window handle for firefox (if there is more than one open, you'll have to choose one, possibly using the z-order).  However, unlike IE, in firefox you'll have to use the accessibility sdk, as I mentioned before.  So after you have the firefox window handle, use AccessibleObjectFromWindow and then AccessibleChildren functions (in those links, click near the bottom for the MSDN documentation for a better idea of how to use them).

    Hope it helps!
    Friday, August 4, 2006 6:44 PM

All replies

  • It's not easy if the application does not provide a way to get the information.  There's no universal way to get such information--you'll have to do something different for each situation, if it's possible at all.  Before I try to answer anything, are those the tasks you actually want to do, or were those just examples?
    Friday, August 4, 2006 3:37 AM
  • Ok so I need to:
    1. Get the URL of most active window in Firefox.
    2. Get the currently playing song title, artist, album in WMP.
    Friday, August 4, 2006 11:00 AM
  • Alright, it is possible to get the URL entered in Firefox.  You have a few options.

    1) Create a firefox extension, which I assume has access to the url. Make the extension able to communicate with your program.
    2) Unfortunately, the address bar does not have its own window handle. Still, it is possible using the Active Accessibility SDK. Try downloading AccExplorer32.exe from Microsoft, and you'll notice that you can target the address bar and it will retrieve the value. For some VB6 sample code illustrating the process of navigating the accessible window hierarchy, take a look at http://www.jsware.net/jsware/vbcode.php3 under Active Accessibility.
    3) Alright, this is a really ugly hack. You could give firefox the focus, use SendKeys to send Ctrl+L (which selects the address bar). Send Ctrl+A, Ctrl+C, and then you have it on the clipboard, if you're lucky. Make sure that you save the previous state of the clipboard and then restore it. It's possible that the address bar was already selected, in which case you'll have to do it again.

    Personally, I would try #2, and I would never do #3--but it could be an option for personal use, as long as you don't distribute the application.

    No clue about getting the currently playing song, although it may be difficult. I know it's easy in iTunes, so hopefully WMP exposes a similar interface.
    Friday, August 4, 2006 3:40 PM
  • Ok so I got the adress: "0x001c02a4, class: "MozillaUIWindowClass" what next should I do? Something with Interop DLL, but I'm weak in this subject, pls if possible add a simple code to this particular problem..

    Thx alot for prev answer!
    Friday, August 4, 2006 4:11 PM
  • The 0x001c02a4 value is probably not a constant, so I don't think you can use that.  What you're going to have to do is something like the sample code on http://www.pinvoke.net/default.aspx/user32.FindWindowEx to get the URL from IE.  First, find the main window handle for firefox (if there is more than one open, you'll have to choose one, possibly using the z-order).  However, unlike IE, in firefox you'll have to use the accessibility sdk, as I mentioned before.  So after you have the firefox window handle, use AccessibleObjectFromWindow and then AccessibleChildren functions (in those links, click near the bottom for the MSDN documentation for a better idea of how to use them).

    Hope it helps!
    Friday, August 4, 2006 6:44 PM
  • Thx a lot, it should works now :)
    Friday, August 4, 2006 7:07 PM
  • Could you please post the working code here?
    Eli Gazit (try this free icons site: http://www.iconbuffet.com/people/new?ref=EliGazit)
    Wednesday, September 3, 2008 4:05 PM