有人可以在这个片段中轻描淡写吗? 我正在使用IE 9,有时它可以工作到有点,有时不会,但不会更远。
IntPtr IEwindowHandle = GetForegroundWindow();
IntPtr childHandle = IntPtr.Zero;
childHandle = FindWindowEx(IEwindowHandle, IntPtr.Zero, "WorkerW", IntPtr.Zero);
if (childHandle != IntPtr.Zero)
{
//get the handle to the address bar on IE
childHandle = FindWindowEx(childHandle, IntPtr.Zero, "ReBarWindow32", IntPtr.Zero);
if (childHandle != IntPtr.Zero)
{
// Usually it get until HERE <---------
// get a handle to comboBoxEx32
childHandle = FindWindowEx(childHandle, IntPtr.Zero, "ComboBoxEx32", IntPtr.Zero);
if (childHandle != IntPtr.Zero)
{
// get a handle to combo box
childHandle = FindWindowEx(childHandle, IntPtr.Zero, "ComboBox", IntPtr.Zero);
if (childHandle != IntPtr.Zero)
{
//get handle to edit
childHandle = FindWindowEx(childHandle, IntPtr.Zero, "Edit", IntPtr.Zero);
if (childHandle != IntPtr.Zero)
{
// now to get the URL we need to get the Text - but first get the length of the URL
int length = SendMessage(childHandle, WM_GETTEXTLENGTH, 0, null);
length += 1; // because the length returned above included 0
StringBuilder text = new StringBuilder(length); // need stringbuilder - not string
int hr = SendMessage(childHandle, WM_GETTEXT, length, text); // get the URL
string strURL = text.ToString();
}
}
}
}
}
还有FindWindowEx的声明
[DllImport("user32.dll", SetLastError = true)]
static extern IntPtr FindWindowEx(IntPtr parentHandle, IntPtr childAfter, string className, IntPtr windowTitle);
它让我发疯...这应该工作!!
答案 0 :(得分:1)
string url = string.Empty;
try
{
DdeClient oDde = new DdeClient("IExplore", "WWW_GetWindowInfo");
try
{
oDde.Connect();
url = oDde.Request("1", int.MaxValue);
oDde.Disconnect();
}
catch (Exception ex)
{
throw ex;
}
}
catch (Exception ex)
{
throw ex;
}