111,092
社区成员




using System;
using System.Drawing;
using System.Runtime.InteropServices;
using System.Windows.Forms;
using mshtml;
namespace WinApp1
{
public partial class Form1 : Form
{
private WebBrowser webBrowser1;
private Button button1;
public Form1()
{
InitializeComponent();
webBrowser1 = new WebBrowser
{
Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right,
Size = new Size(ClientSize.Width, ClientSize.Height - 40),
};
button1 = new Button
{
Anchor = AnchorStyles.Bottom, // | AnchorStyles.Left | AnchorStyles.Right,
Location = new Point(ClientSize.Width/2 - 40, ClientSize.Height - 30),
Text = "login",
};
Controls.AddRange(new Control[]{webBrowser1, button1});
webBrowser1.Navigate("http://qzone.qq.com/");
button1.Click += (s, e) => QuickLoginQQ();
}
void QuickLoginQQ()
{
HtmlWindow frame = webBrowser1.Document.Window.Frames["login_frame"];
frame = frame.Document.Window.Frames["xui"];
var sp = (IServiceProvider)(frame.DomWindow);
Object browser = null;
sp.QueryService(ref IID_IWebBrowserApp, ref IID_IWebBrowser2, out browser);
var doc = (IHTMLDocument3)((SHDocVw.IWebBrowser2)browser).Document;
var div = (IHTMLElement2)doc.getElementById("qlogin_list");
var a = (IHTMLElement)div.getElementsByTagName("a").item(0);
a.click();
}
private static Guid IID_IWebBrowserApp = new Guid("0002DF05-0000-0000-C000-000000000046");
private static Guid IID_IWebBrowser2 = new Guid("D30C1661-CDAF-11D0-8A3E-00C04FC9E26E");
[ComImport(), ComVisible(true), Guid("6D5140C1-7436-11CE-8034-00AA006009FA"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
public interface IServiceProvider
{
[return: MarshalAs(UnmanagedType.I4)]
[PreserveSig]
int QueryService(ref Guid guidService, ref Guid riid, [MarshalAs(UnmanagedType.Interface)] out object ppvObject);
}
}
}
//using System;
//using System.Runtime.InteropServices;
//using System.Windows.Forms;
//using mshtml;
void QuickLoginQQ()
{
HtmlWindow frame = webBrowser1.Document.Window.Frames["login_frame"];
frame = frame.Document.Window.Frames["xui"];
var sp = (IServiceProvider)(frame.DomWindow);
Object browser = null;
sp.QueryService(ref IID_IWebBrowserApp, ref IID_IWebBrowser2, out browser);
var doc = (IHTMLDocument3)((SHDocVw.IWebBrowser2)browser).Document;
var div = (IHTMLElement2)doc.getElementById("qlogin_list");
var a = (IHTMLElement)div.getElementsByTagName("a").item(0);
a.click();
}
private static Guid IID_IWebBrowserApp = new Guid("0002DF05-0000-0000-C000-000000000046");
private static Guid IID_IWebBrowser2 = new Guid("D30C1661-CDAF-11D0-8A3E-00C04FC9E26E");
[ComImport(), ComVisible(true), Guid("6D5140C1-7436-11CE-8034-00AA006009FA"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
public interface IServiceProvider
{
[return: MarshalAs(UnmanagedType.I4)]
[PreserveSig]
int QueryService(ref Guid guidService, ref Guid riid, [MarshalAs(UnmanagedType.Interface)] out object ppvObject);
}