2 Email : <lmathieson@optusnet.com.au>
4 This is prelimanary stuff - the controls need extra methods and events etc,
5 feel free to email with suggestions &/or patches.
7 Tested with wxWindows 2.3.2.
8 Built with MS Visual C++ 6.0 & DevStudio
9 Minor use of templates and STL
11 -----------------------------------------------------------
12 This sample illustrates using wxActiveX and wxIEHtmlWin too:
13 1. Host an arbitrary ActiveX control
14 2. Specifically host the MSHTML Control
19 wxActiveX is used to host and siplay any activeX control, all the wxWindows developer
20 needs to know is either the ProgID or CLSID of the control in question.
33 - EVT_ACTIVEX(id, eventName, handler) (handler = void OnActiveX(wxActiveXEvent& event))
34 class wxActiveXEvent : public wxNotifyEvent
35 int ParamCount() const;
36 wxVariant operator[] (int idx) const; // parameter by index
37 wxVariant& operator[] (int idx);
38 wxVariant operator[] (wxString name) const; // named parameters
39 wxVariant& operator[] (wxString name);
44 wxActiveX::wxActiveX(wxWindow * parent, REFCLSID clsid, wxWindowID id = -1);
45 - Creates a activeX control identified by clsid
47 wxFrame *frame = new wxFrame(this, -1, "test");
48 wxActiveX *X = new wxActiveX(frame, CLSID_WebBrowser);
50 wxActiveX::wxActiveX(wxWindow * parent, wxString progId, wxWindowID id = -1);
51 - Creates a activeX control identified by progId
53 wxFrame *frame = new wxFrame(this, -1, "test");
54 wxActiveX *X = new wxActiveX(frame, "MSCAL.Calendar");
57 wxActiveX::~wxActiveX();
58 - Destroys the control
59 - disconnects all connection points
61 HRESULT wxActiveX::ConnectAdvise(REFIID riid, IUnknown *eventSink);
62 - Connects a event sink. Connections are automaticlly diconnected in the destructor
64 FS_DWebBrowserEvents2 *events = new FS_DWebBrowserEvents2(iecontrol);
65 hret = iecontrol->ConnectAdvise(DIID_DWebBrowserEvents2, events);
66 if (! SUCCEEDED(hret))
72 EVT_ACTIVEX(ID_MSHTML, "BeforeNavigate2", OnMSHTMLBeforeNavigate2X)
74 void wxIEFrame::OnMSHTMLBeforeNavigate2X(wxActiveXEvent& event)
76 wxString url = event["Url"];
78 int rc = wxMessageBox(url, "Allow open url ?", wxYES_NO);
81 event["Cancel"] = true;
87 wxIEHtmlWin is a specialisation of the wxActiveX control for hosting the MSHTML control.
97 - EVT_MSHTML_BEFORENAVIGATE2
99 * event.Veto() to cancel
100 Generated before an attempt to browse a new url
102 - EVT_MSHTML_NEWWINDOW2
103 * event.Veto() to cancel
104 Generated when the control is asked create a new window (e.g a popup)
106 - EVT_MSHTML_DOCUMENTCOMPLETE
107 * url = event.m_text1
108 Generated after the document has finished loading
110 - EVT_MSHTML_PROGRESSCHANGE
111 * event.m_long1 = progress so far
112 * event.m_long2 = max range of progress
114 - EVT_MSHTML_STATUSTEXTCHANGE
115 * status = event.m_text1
117 - EVT_MSHTML_TITLECHANGE
118 * title = event.m_text1
122 wxIEHtmlWin::wxIEHtmlWin(wxWindow * parent, wxWindowID id = -1);
123 - Constructs and initialises the MSHTML control
124 - LoadUrl("about:blank") is called
126 wxIEHtmlWin::~wxIEHtmlWin();
127 - destroys the control
129 void wxIEHtmlWin::LoadUrl(const wxString&);
130 - Attempts to browse to the url, the control uses its internal (MS)
133 bool wxIEHtmlWin::LoadString(wxString html);
134 - Load the passed HTML string
136 bool wxIEHtmlWin::LoadStream(istream *strm);
137 - load the passed HTML stream. The control takes ownership of
138 the pointer, deleting when finished.
140 void wxIEHtmlWin::SetCharset(wxString charset);
141 - Sets the charset of the loaded document
143 void wxIEHtmlWin::SetEditMode(bool seton);
145 NOTE: This does work, but is bare bones - we need more events exposed before
146 this is usable as an HTML editor.
148 bool wxIEHtmlWin::GetEditMode();
149 - Returns the edit mode setting
151 wxString wxIEHtmlWin::GetStringSelection(bool asHTML = false);
152 - Returns the currently selected text (plain or HTML text)
154 wxString GetText(bool asHTML = false);
155 - Returns the body text (plain or HTML text)
158 Email : <lmathieson@optusnet.com.au>