Как получить IE8 / 9 активную вкладку HTML-источник C # - PullRequest
1 голос
/ 30 октября 2010

Я пытаюсь создать программу на C # в Visual Studio, которая получит HTML-источник текущей открытой (или выбранной, или всех) вкладок в Internet Explorer 8 / (предпочтительно) 9. Я устал от копированияby - browser-> View Source, alt + a, alt + c, program -> alt + v У кого-нибудь есть идеи, как это решить?

1 Ответ

2 голосов
/ 30 октября 2010

Ну, нет простого решения для этого, я думаю. Может быть, вам следует продолжить копирование и вставку.Во всяком случае, это то, что я нашел в Интернете: (http://www.experts -exchange.com / Microsoft / Development / Q_23767759.html )

{   // used spy++ to get the names of these guys
            // get the handle to the IE toolbar
            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)
                {
                    // 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, 0);
                                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
                                strURL = text.ToString();
                            }
                        }
                    }
                }

Теперь, когда вы получили доступ к URL, отправив HTTP-запрос на получение, вы получите исходный текст сайта.

...