套壳直接用webBrower就行,不过在使用过程中,主要存在两个问题,
一个是网页内核h5兼容问题,通过设置系统注册表解决
[(HKEY_CURRENT_USER or HKEY_LOCAL_MACHINE)\Software\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BROWSER_EMULATION]
"MyApplication.exe" = dword 8000 (Hex: 0x1F40)
这里MyApplicaiton.exe 是你的应用程序的EXE文件名。 8000 表示8.0的渲染模式,请对照下表:
IE8 Standards Mode 8000 (0x1F40) -- IE8 标准模式 (Standard Mode), IE8默认的模式
IE7 Standards Mode 7000 (0x1B58) -- IE7 兼容视图模式 (Compatible View), IE8的WebBrowser控件默认模式
IE8 Standards Mode (Forced) 8888 (0x22B8) -- IE8 强制标准模式,在渲染失败的情况下不尝试用兼容视图模式
一个是网络问题导致第一次打开失败,自动刷新问题:
private void openUrl()
{
this.webBrowser1.Url = new System.Uri(str, System.UriKind.Absolute);///读取
this.webBrowser1.DocumentCompleted += new WebBrowserDocumentCompletedEventHandler(wb_DocumentCompleted);
}
private void wb_DocumentCompleted(object sender, EventArgs e)//这个就是当网页载入完毕后要进行的操作
{
//无法访问
Trace.WriteLine(this.webBrowser1.DocumentText);
if (this.webBrowser1.DocumentText.IndexOf("无法访问") >= 0)
{
//打开失败
if (idx > Int32.Parse(ConfigurationManager.AppSettings["Sum"]))
{
return;
}
idx++;
new Thread(o =>
{
Thread.Sleep(Int32.Parse(ConfigurationManager.AppSettings["Time"]));
openAgain();
})
{ IsBackground = true}.Start();
}
else
{
//打开成功
}
}
private void openAgain()
{
if (this.InvokeRequired)
{
this.Invoke(new Action(() =>
{
this.openAgain();
}));
}
else
{
openUrl();
}
}