-
Notifications
You must be signed in to change notification settings - Fork 0
/
HtmlUI.cs
172 lines (128 loc) · 5.17 KB
/
HtmlUI.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
//
// HtmlUI
//
// HtmlUI shows how to use the advanced hosting interfaces
// with a web browser control.
//
// Nikhil Dabas, ndabas@hotmail.com
//
namespace NikhilDabas.HtmlUI
{
using System;
using System.Windows.Forms;
using System.Drawing;
using System.Runtime.InteropServices;
using MSHTML;
using MsHtmHstInterop;
using AxSHDocVw;
[Serializable]
public class HtmlUIForm : Form, IDocHostUIHandler
{
private System.ComponentModel.Container components = null;
protected AxWebBrowser WebBrowser;
public HtmlUIForm()
{
InitializeComponent();
this.WebBrowser.DocumentComplete += new DWebBrowserEvents2_DocumentCompleteEventHandler(this.WebBrowser_DocumentComplete);
object flags = 0;
object targetFrame = String.Empty;
object postData = String.Empty;
object headers = String.Empty;
this.WebBrowser.Navigate("about:blank", ref flags, ref targetFrame, ref postData, ref headers);
ICustomDoc cDoc = (ICustomDoc)this.WebBrowser.Document;
cDoc.SetUIHandler((IDocHostUIHandler)this);
this.WebBrowser.Navigate(@"res://HtmlUI.exe/Sample1.htm", ref flags, ref targetFrame, ref postData, ref headers);
}
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
public void InitializeComponent()
{
this.WebBrowser = new AxWebBrowser();
this.WebBrowser.BeginInit();
this.SuspendLayout();
this.Text = "HTML UI Demo";
this.Size = new Size(563, 474);
this.MinimumSize = new Size(563, 474);
this.Font = new Font("Tahoma", 8);
this.WebBrowser.Dock = DockStyle.Fill;
this.Controls.Add(this.WebBrowser);
this.ResumeLayout(false);
this.WebBrowser.EndInit();
}
[STAThread]
static void Main(string[] args)
{
Application.Run(new HtmlUIForm());
}
private void WebBrowser_DocumentComplete(object sender, AxSHDocVw.DWebBrowserEvents2_DocumentCompleteEvent e)
{
IHTMLDocument2 doc = (IHTMLDocument2)this.WebBrowser.Document;
HTMLButtonElement button = (HTMLButtonElement)doc.all.item("theButton", null);
((HTMLButtonElementEvents2_Event)button).onclick += new HTMLButtonElementEvents2_onclickEventHandler(this.Button_onclick);
}
private bool Button_onclick(IHTMLEventObj e)
{
MessageBox.Show("Alert from the app: Received theButton.onclick!");
return true;
}
// IDocHostUIHandler implementation
void IDocHostUIHandler.EnableModeless(int fEnable)
{
}
void IDocHostUIHandler.FilterDataObject(MsHtmHstInterop.IDataObject pDO, out MsHtmHstInterop.IDataObject ppDORet)
{
ppDORet = null;
}
void IDocHostUIHandler.GetDropTarget(IDropTarget pDropTarget, out IDropTarget ppDropTarget)
{
ppDropTarget = null;
}
void IDocHostUIHandler.GetExternal(out object ppDispatch)
{
ppDispatch = null;
}
void IDocHostUIHandler.GetHostInfo(ref _DOCHOSTUIINFO pInfo)
{
}
void IDocHostUIHandler.GetOptionKeyPath(out string pchKey, uint dw)
{
pchKey = null;
}
void IDocHostUIHandler.HideUI()
{
}
void IDocHostUIHandler.OnDocWindowActivate(int fActivate)
{
}
void IDocHostUIHandler.OnFrameWindowActivate(int fActivate)
{
}
void IDocHostUIHandler.ResizeBorder(ref MsHtmHstInterop.tagRECT prcBorder, IOleInPlaceUIWindow pUIWindow, int fRameWindow)
{
}
void IDocHostUIHandler.ShowContextMenu(uint dwID, ref MsHtmHstInterop.tagPOINT ppt, object pcmdtReserved, object pdispReserved)
{
}
void IDocHostUIHandler.ShowUI(uint dwID, IOleInPlaceActiveObject pActiveObject, IOleCommandTarget pCommandTarget, IOleInPlaceFrame pFrame, IOleInPlaceUIWindow pDoc)
{
}
void IDocHostUIHandler.TranslateAccelerator(ref tagMSG lpmsg, ref Guid pguidCmdGroup, uint nCmdID)
{
}
void IDocHostUIHandler.TranslateUrl(uint dwTranslate, ref ushort pchURLIn, IntPtr ppchURLOut)
{
}
void IDocHostUIHandler.UpdateUI()
{
}
}
}