日期:2014-05-18  浏览次数:20966 次

如何获取当前浏览器地址
如何获取当前激活的浏览器地址栏的网址?谢谢!

------解决方案--------------------
C# code
using System;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;

namespace WindowsApplication13
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        [DllImport("user32.dll")]
        private static extern int FindWindow(string lpClassName, string lpWindowName); 

        [DllImport("user32.dll", SetLastError = true)]
        private static extern int FindWindowEx(int parentHandle, int childAfter, string className, string windowTitle); 

        [DllImport("user32.dll", EntryPoint = "SendMessage")]
        private static extern int SendMessage(int hWnd, uint Msg, int wParam, StringBuilder sb);

        [DllImport("user32.dll")] 
        private static extern int GetForegroundWindow();

        private const int WM_GETTEXT = 0x000D;

        private void button1_Click(object sender, EventArgs e) 
        { 
            int hwnd;

           // hwnd = GetForegroundWindow();
            hwnd = FindWindow("IEFrame", null);
            hwnd = FindWindowEx(hwnd, 0, "WorkerW", null);

            StringBuilder sb = new StringBuilder(256);

            hwnd = FindWindowEx(hwnd, 0, "ReBarWindow32", null);
            hwnd = FindWindowEx(hwnd, 0, "ComboBoxEx32", null);
            hwnd = FindWindowEx(hwnd, 0, "ComboBox", null);
            hwnd = FindWindowEx(hwnd, 0, "Edit", null);

            if (hwnd != 0)
            {
                SendMessage(hwnd, WM_GETTEXT, sb.Capacity, sb);
                MessageBox.Show(sb.ToString());
            }
        } 

    }
}