Add result using EnumWindow/GetWindowText

P

Paul Steele

I've written a callback function for use with EnumWindow that is intended to
return the URL of all open IE windows. The code seems to do almost exactly
what I want, but fails at the final step when it tries to retrieve the text
of the address bar using the Win32 API GetWindowText. It returns an empty
string instead of the URL. Has anyone tried this? The code is pretty
straightforward, but I don't see what wrong:

private bool ieCheck(int hWnd, int lParam)
{
StringBuilder text = new StringBuilder(256);
if (GetClassName(hWnd, text, 256) == 0)
return true;
if (text.ToString() != "IEFrame")
return true;
int ieHandle = FindWindowEx(hWnd, 0, "WorkerW", null);
if ((int)ieHandle > 0)
{
ieHandle = FindWindowEx(ieHandle, 0, "ReBarWindow32", null);
if ((int)ieHandle > 0)
{
ieHandle = FindWindowEx(ieHandle, 0, "ComboBoxEx32", null);
if ((int)ieHandle > 0)
{
GetWindowText(hWnd, text, 256);
output.Add(text.ToString());
}
}
}
return true;
}
 
G

Guest

Try Spy++ tool which comes with your development environment. The control
that actually has your URL caption has a window class name of 'Edit', and is
a child of the 'ComboBoxEx32' of your 'ReBarWindow32'. Give this a try.
 
G

Guest

Ok here's what's wrong. Replace GetWindowText in the innermost if with, and
you've got your url. Appearently SendMessage works better with out of process
boundaries.

SendMessage((IntPtr) ieHandle, 0x000D, new IntPtr(256), text);

//and here is my SendMessage from pinvoke.net
[DllImport("user32.dll")]
static extern IntPtr SendMessage(IntPtr hWnd, uint Msg, IntPtr wParam,
[Out] StringBuilder lParam);

HTH
 
P

Paul Steele

Serg said:
Ok here's what's wrong. Replace GetWindowText in the innermost if with,
and
you've got your url. Appearently SendMessage works better with out of
process
boundaries.

SendMessage((IntPtr) ieHandle, 0x000D, new IntPtr(256), text);

//and here is my SendMessage from pinvoke.net
[DllImport("user32.dll")]
static extern IntPtr SendMessage(IntPtr hWnd, uint Msg, IntPtr wParam,
[Out] StringBuilder lParam);

Thanks for confirming what I found out through additional googling and
testing!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top