I have implemented the control IE browser, just can't control and detect or pause ie flash player for IE play
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private SHDocVw.InternetExplorer getWindowObject(String ieWindowName)
{
if (ieWindowName == String.Empty || ieWindowName.Equals(""))
{
return null;
}
SHDocVw.InternetExplorer v_ie = null;
/*
获得所有ie进程。因为windows下资源窗口使用ie内核,所以不光是我们通常指的web浏览器,它还包括你打开我的电脑这样的窗口
*/
SHDocVw.ShellWindows sws = new SHDocVw.ShellWindows();
/*遍历ie进程*/
foreach (SHDocVw.InternetExplorer iew in sws)
{
//MessageBox.Show(iw.LocationName);
/*
* 将获取到的窗口URL和输入的要控制的部分URl比较,如果包含,则说明此窗口是需要被控制的,将其句柄返回即可。
*/
//MessageBox.Show(iew.LocationURL);
if (iew.LocationURL.Contains(ieWindowName))
{
//MessageBox.Show(iw.LocationName);
//HtmlDocument doc = iw.get (HtmlDocument)iw.Document;
//MessageBox.Show(doc.DomDocument.ToString());
//mshtml.HTMLDocument doc = (mshtml.HTMLDocument)iw.Document;
//MessageBox.Show(((HTMLInputTextElement)doc.getElementById("t1")).value);
//ihtmldocument2接口.可以查看msdn6. 做法有点类似于js对页面htmlelement操作了。
//((HTMLInputTextElement)doc.getElementById("t1")).value = textSetStr.Text;
v_ie = iew;
}
}
return v_ie;
}
////////////显示或隐藏////////////////////////////////////////////////////////////////////////////////////////////
private void isShowOrHiddenIEInput(String ieWindowName, String ieInputName, String isShow)
{
SHDocVw.InternetExplorer iw = getWindowObject(ieWindowName);
if (iw != null)
{
mshtml.HTMLDocument doc = (mshtml.HTMLDocument)iw.Document;
if (isShow.Equals("true"))
{
((HTMLInputTextElement)doc.getElementById(ieInputName)).style.display = "block";
}
else
{
((HTMLInputTextElement)doc.getElementById(ieInputName)).style.display = "none";
}
}
}
private void button3_Click(object sender, EventArgs e)
{
isShowOrHiddenIEInput(this.textUrl.Text, this.textIEInputID.Text, "true");
}
private void button4_Click(object sender, EventArgs e)
{
isShowOrHiddenIEInput(this.textUrl.Text, this.textIEInputID.Text, "false");
}
////////////////禁用或启用按钮////////////////////////////////////////////////////////////////////////////////////////////////////
private void isEnableOrDisableIEInput(String ieWindowName, String ieInputName, String isable)
{
SHDocVw.InternetExplorer iw = getWindowObject(ieWindowName);
if (iw != null)
{
mshtml.HTMLDocument doc = (mshtml.HTMLDocument)iw.Document;
if (isable.Equals("enable"))
{
((HTMLInputTextElement)doc.getElementById(ieInputName)).disabled = false;
}
else
{
((HTMLInputTextElement)doc.getElementById(ieInputName)).disabled = true;
}
}
}
private void button5_Click(object sender, EventArgs e)
{
isEnableOrDisableIEInput(this.textUrl.Text, this.textEnableIEinput.Text, "disable");
}
private void button6_Click(object sender, EventArgs e)
{
isEnableOrDisableIEInput(this.textUrl.Text, this.textEnableIEinput.Text, "enable");
}
//给IE浏览器中的文本框赋值
private void txtIEInput(String ieWindowName, String ietxtInputName, String txt)
{
SHDocVw.InternetExplorer iw = getWindowObject(ieWindowName);
if (iw != null)
{
mshtml.HTMLDocument doc = (mshtml.HTMLDocument)iw.Document;
((HTMLInputTextElement)doc.getElementById(ietxtInputName)).value = txt;
}
}
private void button7_Click(object sender, EventArgs e)
{
txtIEInput(this.textUrl.Text, this.textBox3.Text, this.textBox2.Text);
}
//获取IE浏览器的body内容
private string getbodytxt(String ieWindowName)
{
SHDocVw.InternetExplorer iw = getWindowObject(ieWindowName);
if (iw != null)
{
mshtml.HTMLDocument doc = (mshtml.HTMLDocument)iw.Document;
string html = doc.documentElement.innerHTML;
mshtml.HTMLBody body = (mshtml.HTMLBody)doc.body;
return body.innerHTML.ToString();
}
return "0";
}
private void button1_Click(object sender, EventArgs e)
{
this.richTextBox1.Text = getbodytxt(this.textUrl.Text);
}
//获取IE浏览器html内容
private string gethtmltxt(String ieWindowName)
{
SHDocVw.InternetExplorer iw = getWindowObject(ieWindowName);
if (iw != null)
{
mshtml.HTMLDocument doc = (mshtml.HTMLDocument)iw.Document;
string html = doc.documentElement.innerHTML;
return html;
}
return "0";
}
private void button8_Click(object sender, EventArgs e)
{
this.richTextBox2.Text = gethtmltxt(this.textUrl.Text);
}
//点击提交按钮方法
public void SearchbtnInbaidu(String ieWindowName,string btntxt)
{
//mshtml.HTMLInputElementClass input;
SHDocVw.InternetExplorer iw = getWindowObject(ieWindowName);
if (iw != null)
{
mshtml.HTMLDocument doc = (mshtml.HTMLDocument)iw.Document;
((HTMLInputTextElement)doc.getElementById(btntxt)).click();
}
}
private void button9_Click(object sender, EventArgs e)
{
SearchbtnInbaidu(this.textUrl.Text,this.textBox4.Text);
}
}