Click here to Skip to main content
15,896,154 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
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?
C#
//IE
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
                //注意这个函数ObjectFromLresult的声明
            );
        }


        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);//注:第二个参数是RegisterWindowMessage函数的返回值
            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.
Posted
Updated 23-Sep-13 15:42pm
v5
Comments
Sergey Alexandrovich Kryukov 23-Sep-13 21:49pm    
Why?
It would probably be easy to make your own browser based on one of the available browser components (WebKit, IE WebBrowser control...).
—SA
joyoesq 29-Sep-13 10:32am    
能教教我怎么做吗?
Sergey Alexandrovich Kryukov 29-Sep-13 11:57am    
I would love to be able to understand that, but unfortunately I cannot.
—SA
joyoesq 29-Sep-13 10:33am    
could You teach me how to do that?
Sergey Alexandrovich Kryukov 29-Sep-13 11:10am    
Yes. Grab documentation of such controls and read it.
—SA

1 solution

joyoesq asked:
Could you teach me how to do that?
For example, read this:
IE control for System.Windows.Forms: http://msdn.microsoft.com/en-us/library/system.windows.forms.webbrowser.aspx[^],
for WPF: http://msdn.microsoft.com/en-us/library/system.windows.controls.webbrowser.aspx[^],
WebKit for System.Windows.Forms: http://webkitdotnet.sourceforge.net/[^],
Gecko for System.Windows.Forms: https://code.google.com/p/geckofx/[^].

Add one of the controls mentioned above to UI of your project, use the control's public members, according to available documentation.

—SA
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900