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;
}
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;
}