Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

how to get URLs of Internet Explorer documents

Posted on 2006-06-09
10
Medium Priority
?
537 Views
Last Modified: 2008-02-01
I would like to be able to get the URLs of all documents that are open in IE. I tried by using the tcom package (Windwos com objects, http://www.vex.net/~cthuang/tcom/) of Tcl/Tk. But when I try to get an handle of an existing instance of IE I get an "operation unavailable" error message. Instead I can create a new object with tcom and use it without any problem. Any way of doing it in Windows with C would be fine for me. Thanks.
0
Comment
Question by:s_federici
  • 6
  • 2
  • 2
10 Comments
 
LVL 86

Expert Comment

by:jkr
ID: 16871820
See http://support.microsoft.com/kb/q176792/ ("How to connect to a running instance of Internet Explorer") which demonstrates that. The sample code there however is VB or C++, but it is almost complete, all you need to call is 'IWebBrowser2::get_LocationURL()' instead of 'GetDocument()'.
0
 
LVL 3

Expert Comment

by:srinims
ID: 16891728
HI, I think IWebBrowser@ is used to create a new instance of IE, And get_LocationURL() will get the address of created instance.
For Getting the url's of already openend windows. U have do the Spy program Which can idendify all the Windows under the Destop handle, And then you have to locate the Internet Explorer application on that. After then you can find the URL of all opened IE windows.  
pls find the below details,which I got from one site.

In the Internet Explorer the current URL is displayed inside the combo box component on the Address bar. In order to "steal" the current URL from IE, you'll need to find the (control class) name of that combo box, locate it, and grab its text. Now, this seems easy, but how do you do that?
To be able to grab a text from an arbitrary window (and its child windowed controls) on the Windows Desktop, you'll need to play with Windows API calls and Windows Messages. First, or better to say last, when you find that combo box with the current URL in it, you can send a WM_GETTEXT message to that window and pick the text displayed inside. Second, or better to say first, you need to know the exact order of controls that are parents to that URL combo box. Then, you use the FindWindowEx API call in order to retrieve the handle (an integer number that uniquely identifies each control / window) of the child window. Ok, all seems easy, but again how do you know the structure of IEs controls and their parenthood?

the main IE window is called "IEFrame".To retrieve the handle to the top-level window whose class name is provided (in our case: IEFrame), you can use the FindWindow API call. When you have the IE handle you then use the FindWindowEx API, to locate that ComboBox control with the URL. Finally, as already mentioned above, you send that ComboBox the WM_GETTEXT message to obtain the text from it.
This seems easy. However, note that FindWindow API retrieves the handle to the top-level window. What this means is that if you have multiple instances of IE opened (as you probably have) the function will locate the last activated IE window

Enumerate all top-level windows using the EnumWindows callback (this gives us a Handle)
Grab the Caption (Title) of each Window
Look only for windows whose class name is "IEFrame"
Use the FindWindow provided with the Handle and the Caption to locate the correct IE window
Call FindWindowEx several times to locate the ComboBox carying the URL, as it is the child to some parent which is a child to our top-level IEFrame (this is the class name) window
Send a message to the ComboBox to retrieve the text inside it
0
 
LVL 3

Expert Comment

by:srinims
ID: 16891741
A VB sample

http://www.mvps.org/access/api/api0051.htm

U could use the same thing for windows application, or you can convert into the Vc++ code using the same api calls.

srini ms
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 86

Expert Comment

by:jkr
ID: 16891743
>>HI, I think IWebBrowser@ is used to create a new instance of IE, And get_LocationURL() will get the
>>address of created instance.

Thank you, I really appreciate when people repeat what I already wrote.
0
 

Author Comment

by:s_federici
ID: 16919204
Sorry, after deep study, I'm totally unable to implement srinims' suggestion in C. Help is needed.
0
 
LVL 3

Expert Comment

by:srinims
ID: 16919313
hi jkr,   I'm really sorry for my comments. I haven't read the documment given in the microsoft site. I have read out only from my local msdn, that's the problem. Any way I'm really sorry for the comments on your post.


hi federici, could u post the problem you are facing.  have u tried the code using vb given in the second link.

srini ms
0
 
LVL 3

Expert Comment

by:srinims
ID: 16919372
the vb code is working fine.

u can covert the same vb code in vc++ sdk code.
get the .bas file in the above link, i have given.
try to load in to one VB. and change some code as below mentioned to get the message box with address

                If hWndChild > 0 Then
                    '   Get the length of the URL in Editbox
                    lngLen = apiSendMessage(hWndChild, WM_GETTEXTLENGTH, _
                                    0, ByVal 0&)
                    strURL = Space$(lngLen + 1)
                    '   Get the URL itself
                    lngLen = apiSendMessage(hWndChild, WM_GETTEXT, _
                                            lngLen + 1, ByVal strURL)
                    MsgBox (strURL)

the strURL is the string responsible for address, the sniphet is from the Refresh method.
i have the problem in the first line related with database, just comment it out.

srini ms
0
 
LVL 3

Accepted Solution

by:
srinims earned 2000 total points
ID: 16919621
finaly I, solved for u,
find it usefull.

srini ms

void GetIEAddress( )
{
      #define MAX_LEN  255
      long lngStyle,lngLen;
      HWND hWnd,hWndChild;      
      char strBuffer[MAX_LEN];
      char strURL[MAX_LEN];
      char strCAPTION[MAX_LEN];
      char *mconCAPTION = " - Microsoft Internet Explorer";
      char *partFOUND;
      OSVERSIONINFO tOSInfo;
      tOSInfo.dwOSVersionInfoSize = sizeof(tOSInfo);
      GetVersionEx(&tOSInfo);

      hWnd =GetWindow(GetDesktopWindow(), GW_CHILD);
      while(hWnd!=0)
      {
            lngStyle = GetWindowLong(hWnd, GWL_STYLE);
            if(lngStyle & WS_VISIBLE)
            {
                  GetClassName(hWnd, strBuffer, MAX_LEN);
                  if(!strcmp(strBuffer,"IEFrame"))
                  {
                        GetWindowText(hWnd, strCAPTION, MAX_LEN);
                        partFOUND = strstr(strCAPTION,mconCAPTION);
                        if(partFOUND)
                        {
                              if(tOSInfo.dwPlatformId == VER_PLATFORM_WIN32_NT)
                                    hWndChild = FindWindowEx(hWnd, 0, "WorkerW",0);
                              else
                                    hWndChild = FindWindowEx(hWnd, 0, "WorkerA",0);
                              if(hWndChild>0)
                                    hWndChild = FindWindowEx(hWndChild, 0, "ReBarWindow32",0);
                              if(hWndChild>0)
                                    hWndChild = FindWindowEx(hWndChild, 0, "ComboBoxEx32",0);
                              if(hWndChild>0)
                                    hWndChild = FindWindowEx(hWndChild, 0, "ComboBox",0);
                              if(hWndChild>0)
                                    hWndChild = FindWindowEx(hWndChild, 0, "Edit",0);
                              if(hWndChild>0)
                              {
                                    lngLen = SendMessage(hWndChild, WM_GETTEXTLENGTH, 0,0);
                                    SendMessage(hWndChild, WM_GETTEXT,((lngLen + 1) > MAX_LEN)?(lngLen + 1):MAX_LEN, (long)&strURL);
                                    MessageBox(NULL,strURL,strCAPTION,0);
                              }
                        }
                  }
            }
            hWnd = GetWindow(hWnd, GW_HWNDNEXT);
      }
}
0
 
LVL 3

Expert Comment

by:srinims
ID: 16919650
change the statement from ((lngLen + 1) > MAX_LEN)?(lngLen + 1):MAX_LEN
into
((lngLen + 1) < MAX_LEN)?(lngLen + 1):MAX_LEN
0
 

Author Comment

by:s_federici
ID: 16992879
Thanks a lot. Sorry if I didn't test immediately, but I was out of the office. It worked very well.
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you thought about creating an iPhone application (app), but didn't even know where to get started? Here's how: ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ Important pre-programming comments: I’ve never tri…
Examines three attack vectors, specifically, the different types of malware used in malicious attacks, web application attacks, and finally, network based attacks.  Concludes by examining the means of securing and protecting critical systems and inf…
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use while-loops in the C programming language.
The goal of this video is to provide viewers with basic examples to understand and use conditional statements in the C programming language.
Suggested Courses

916 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question