1

I want send and execute hello script to current tab active, how i can do that? here i have code to check current tab active chrome

private Dictionary<IntPtr, string> chromeWindows = new Dictionary<IntPtr, string>();
public Form1()
{
    InitializeComponent();
}

private string ClassName(IntPtr hWnd)
{
    StringBuilder sbClassName = new StringBuilder(256);
    GetClassName(hWnd, sbClassName, 256);
    return sbClassName.ToString();
}

[DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto)]
private static extern int GetWindowText(IntPtr hwnd, StringBuilder lpString, int cch);

[DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto)]
private static extern int GetClassName(IntPtr hWnd, StringBuilder lpClassName, int nMaxCount);
[DllImport("user32", CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]

private static extern bool EnumWindows(EnumWindowsProcDelegate lpEnumFunc, IntPtr lParam);
private delegate bool EnumWindowsProcDelegate(IntPtr hWnd, IntPtr lParam);
private bool ClassesByName(IntPtr hWnd, IntPtr lParam)
{
    //Google Chrome main window class name.
    if (ClassName(hWnd) == "Chrome_WidgetWin_1")
    {
        StringBuilder capText = new StringBuilder(255);
        if (GetWindowText(hWnd, capText, capText.Capacity) > 0)
        {
            chromeWindows.Add(hWnd, capText.ToString());
        }
    }
    return true;
}
private void button1_Click(object sender, EventArgs e)
{
    chromeWindows.Clear();
    // clear dic.
    EnumWindows(ClassesByName, IntPtr.Zero);
    if (chromeWindows.Count == 0)
    {
        MessageBox.Show("None found, list is empty!");
    }
    else
    {
        foreach (var chrome_loopVariable in chromeWindows)
        {
            var chrome = chrome_loopVariable;
            Debug.WriteLine("hWnd={0}, Title={1}", chrome.Key, chrome.Value);
        }
    }

//how to send and run hello scrip?
}

and when user change tab how to I can resend hello script?

Backs
  • 24,430
  • 5
  • 58
  • 85
  • thank for reply, I had used selenium but selenium seem create new WebDriver and just control this, here I want control current browser user using? selenium can do this? and you can show me example – Nguyễn Quốc Tân Oct 15 '17 at 02:08

0 Answers0