C#.NetでWebKit
HMDTさんは実現されたみたいですが(アイコンを見た限りでは.Netかなと思った)、私の方はまだ動いていません。
途中のプログラム
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Runtime.InteropServices;
public class Form1 : System.Windows.Forms.Form
{
private WebKit.WebViewClass Webview;
#region Win32API
[DllImport("user32.dll")]
private static extern bool SetWindowPos(IntPtr hWnd,int hWndInsertAfter,int X,int Y,int cx,int cy,uint uFlags);
#endregion Win32API
#region CoreGraphics
[DllImport("CoreGraphics.dll")]
private static extern bool InitializeCoreGraphics();
#endregion CoreGraphics
private System.Windows.Forms.Button button1;
public Form1()
{
//
// Windows フォーム デザイナ サポートに必要です。
//
InitializeComponent();
//
// TODO: InitializeComponent 呼び出しの後に、コンストラクタ コードを追加してください。
//
}
/// <summary>
/// 使用されているリソースに後処理を実行します。
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows フォーム デザイナで生成されたコード
/// <summary>
/// デザイナ サポートに必要なメソッドです。このメソッドの内容を
/// コード エディタで変更しないでください。
/// </summary>
private void InitializeComponent()
{
this.button1 = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// button1
//
this.button1.Location = new System.Drawing.Point(16, 224);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(128, 24);
this.button1.TabIndex = 0;
this.button1.Text = "button1";
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 12);
this.ClientSize = new System.Drawing.Size(292, 273);
this.Controls.Add(this.button1);
this.Name = "Form1";
this.Text = "Form1";
this.ResumeLayout(false);
}
#endregion
/// <summary>
/// アプリケーションのメイン エントリ ポイントです。
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
}
private void button1_Click(object sender, System.EventArgs e)
{
Webview = new WebKit.WebViewClass();
InitializeCoreGraphics();
Webview.setHostWindow( (int)this.Handle );
WebKit.tagRECT rect;
rect.bottom = rect.left = rect.top = rect.right = 0;
Webview.initWithFrame(rect, null, null);
//
SetWindowPos((System.IntPtr)Webview.viewWindow(), 0, 0, 0, this.ClientSize.Width, this.ClientSize.Height, 0);
//
Webview.addAdditionalPluginPath("");
//
WebKit.WebPreferences preferences = Webview.preferences();
string standardFamily = "MS UI Gothic, 9pt";
string fixedFamily = "MS UI Gothic, 9pt";
string sansSerifFamily = "MS UI Gothic, 9pt";
string cursiveFamily = "MS UI Gothic, 9pt";
string fantasyFamily = "MS UI Gothic, 9pt";
preferences.setStandardFontFamily(standardFamily);
preferences.setFixedFontFamily(fixedFamily);
preferences.setSerifFontFamily(standardFamily);
preferences.setSansSerifFontFamily(sansSerifFamily);
preferences.setCursiveFontFamily(cursiveFamily);
preferences.setFantasyFontFamily(fantasyFamily);
//
//Webview.setPreferences( preferences );
//
WebKit.IWebFrame frame = Webview.mainFrame();
frame.loadHTMLString("<html><p>Hello!Hello!</p></html>", null);
}
}
注意:このコードのコピペではコンパイルすらできません。
たとえ設定できたとしても、ヌルポ例外で落ちます。
気になるのが、InitializeCoreGraphicsの呼び場所かな。
やはり、最初にすべきなのかもしれませんが、そうするとDLLの場所がわからんという例外が発生します・・・
次に考えられるのは、setUIDelegateでDelegateを設定しないといけないのかな?
もし、C#.NetでWebKit使うのに成功された方がいらっしゃったら助言いただければ幸いです。