Hi,
I am a c# program beginner.
I used functions FindWindows() , EnumChildWindow() and GetWindowText() to get the current URL of chrome, but it is not work now.
By using spy++, I can't find the handle and class for the URL window with chrome ver 29...so my old solution doesn't work anymore.
I have searched google , but I still not find a solution.
Can anyone give a solution for me? thanks...
How do to Get current URL and HTML in Chrome,360 and Firefox using C# given hwnd?
Is there a recommended way of retrieving the current URL given the hwnd of Chrome,360 or Firefox?
mshtml.IHTMLDocument2 id = GetHtmlDocument(int.Parse(IDC_EDIT1.Text));
richTextBox1.Text = id.body.innerHTML;
textBox1.Text = id.url;
class Win32API
{
[DllImport("user32", EntryPoint = "SendMessage")]
public static extern int SendMessage(int hwnd, int wMsg, int wParam, ref int lParam);
[DllImport("user32", EntryPoint = "RegisterWindowMessage")]
public static extern int RegisterWindowMessage(string lpString);
[DllImport("OLEACC.DLL", EntryPoint = "ObjectFromLresult")]
public static extern int ObjectFromLresult(
int lResult,
ref System.Guid riid,
int wParam,
[MarshalAs(UnmanagedType.Interface), System.Runtime.InteropServices.In, System.Runtime.InteropServices.Out]ref System.Object ppvObject
);
}
public mshtml.IHTMLDocument2 GetHtmlDocument(int hwnd)
{
System.Object domObject = new System.Object();
int tempInt = 0;
System.Guid guidIEDocument2 = new Guid();
int WM_Html_GETOBJECT = Win32API.RegisterWindowMessage("WM_Html_GETOBJECT");
int W = Win32API.SendMessage(hwnd, WM_Html_GETOBJECT, 0, ref tempInt);
int lreturn = Win32API.ObjectFromLresult(W, ref guidIEDocument2, 0, ref domObject);
mshtml.IHTMLDocument2 doc = (mshtml.IHTMLDocument2)domObject;
return doc;
}
The classname of the tab window is Chrome_RenderWidgetHostHWND (by using spy++),
I think that i cant get the html from current tab Handle,
But maybe i can convert the handle to WebKit.DOM.Document - But I prefer to check the first option.
It is extremely important to me to make the project in the right way and the best possible way.