Editor using Microsoft.mshtml assembly won't allow edit??

G

Guest

Hi,

I am attempting to create an html editor using vb.net 2003, the Web browser
control and the Microsoft.mshtml assembly. I have been unable to understand
why when I set designMode="on" after Documentcomplete event fires why the
document is not editable. I have found that if I do not setup any events in
my VB code the document is editable. As soon as I add a line like

Public Sub onkeydown(ByVal pEvtObj As mshtml.IHTMLEventObj) Implements
mshtml.HTMLDocumentEvents2.onkeydown

End Sub

or in fact any other event any keyboard input does not appear in the
document being edited. If I right mouse on the document the caret moves to
where the mouse is and the only key that functions is the Backspace key..no
keyboard input is accepted...

I found a Micosoft document at
http://support.microsoft.com/Default.aspx?kbid=311284 Titled How To Handle
Document Events in a Visual Basic .NET Application but this too has the same
problem...

You can create an app using the code in this article and then add the
following to the DocumentComplete Event after the existing code.

doc.designMode = "On"

This will place the document in Editable State. Or at least it should.. :(

BTW, in the code on this page I was having a problem with the following line
of code

Dim guid As Guid = System.Type.GetType("mshtml.HTMLDocumentEvents2").GUID

I replaced it with

Dim guid As Guid = New Guid("{3050F613-98B5-11CF-BB82-00AA00BDCE0B}")

so no errors were produced...

I would very much appreciate your help...Since Microsoft have decided to
stop supporting the DHTMLEdit control I am trying to move on and create my
own editor. When I can get this to work I would also like to implement the
IHTMLEditService Interface to build custom dialogs...I cannot find any
documentation on how to do this in VB...Can you help with some code there??

Thanks
Jason
 
P

Peter Huang [MSFT]

Hi

Now I am researching the issue and I will update you with new information
ASAP.

Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
 
P

Peter Huang [MSFT]

Hi Jason,

Now I can reproduce the problem.
Based on my test with a VB6 project, it seems to work well.
I guess maybe the problem is related with the Wrap for the IE or mshtml, I
am still under researching.
But so far you may have a try to make a vb6 control with IE and host the
vb6 control in the winform to see if that will help to resovle the problem.



Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
 
P

Peter Huang [MSFT]

Hi Jason,

Based on my further research, we can use the approach below to attach event
with Advise but not the AddHandle.
Please copy/paste to replace your code with it.


Imports System
Imports System.Drawing
Imports System.Collections
Imports System.ComponentModel
Imports System.Windows.Forms
Imports System.Data
Imports System.Reflection
Imports System.Runtime.InteropServices
Imports System.Threading
Imports System.Diagnostics

Public Class Form1
Inherits System.Windows.Forms.Form

#Region " Windows Form Designer generated code "

Public Sub New()
MyBase.New()

'This call is required by the Windows Form Designer.
InitializeComponent()

'Add any initialization after the InitializeComponent() call

End Sub

'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub

'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer

'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
Friend WithEvents Button1 As System.Windows.Forms.Button
Friend WithEvents ListBox1 As System.Windows.Forms.ListBox
Friend WithEvents AxWebBrowser1 As AxSHDocVw.AxWebBrowser
<System.Diagnostics.DebuggerStepThrough()> Private Sub
InitializeComponent()
Dim resources As System.Resources.ResourceManager = New
System.Resources.ResourceManager(GetType(Form1))
Me.Button1 = New System.Windows.Forms.Button
Me.ListBox1 = New System.Windows.Forms.ListBox
Me.AxWebBrowser1 = New AxSHDocVw.AxWebBrowser
CType(Me.AxWebBrowser1,
System.ComponentModel.ISupportInitialize).BeginInit()
Me.SuspendLayout()
'
'Button1
'
Me.Button1.Location = New System.Drawing.Point(392, 352)
Me.Button1.Name = "Button1"
Me.Button1.TabIndex = 1
Me.Button1.Text = "Button1"
'
'ListBox1
'
Me.ListBox1.Location = New System.Drawing.Point(368, 0)
Me.ListBox1.Name = "ListBox1"
Me.ListBox1.Size = New System.Drawing.Size(128, 342)
Me.ListBox1.TabIndex = 2
'
'AxWebBrowser1
'
Me.AxWebBrowser1.Enabled = True
Me.AxWebBrowser1.Location = New System.Drawing.Point(0, 0)
Me.AxWebBrowser1.OcxState =
CType(resources.GetObject("AxWebBrowser1.OcxState"),
System.Windows.Forms.AxHost.State)
Me.AxWebBrowser1.Size = New System.Drawing.Size(360, 376)
Me.AxWebBrowser1.TabIndex = 3
'
'Form1
'
Me.AcceptButton = Me.Button1
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(504, 390)
Me.Controls.Add(Me.AxWebBrowser1)
Me.Controls.Add(Me.ListBox1)
Me.Controls.Add(Me.Button1)
Me.Name = "Form1"
Me.Text = "Form1"
CType(Me.AxWebBrowser1,
System.ComponentModel.ISupportInitialize).EndInit()
Me.ResumeLayout(False)

End Sub

#End Region
Public Shared dwCookie2 As Integer
Public Sub add_list(ByVal a As Object)
ListBox1.Items.Insert(0, a)
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Dim x As IEEvents = New IEEvents(AxWebBrowser1)
x.fm = Me
End Sub

End Class
#Region "Events"

Public Class IEHTMLDocumentEvents
Implements mshtml.HTMLDocumentEvents2
Public Sub onactivate(ByVal pEvtObj As mshtml.IHTMLEventObj) Implements
mshtml.HTMLDocumentEvents2.onactivate

End Sub

Public Sub onafterupdate(ByVal pEvtObj As mshtml.IHTMLEventObj)
Implements mshtml.HTMLDocumentEvents2.onafterupdate

End Sub

Public Function onbeforeactivate(ByVal pEvtObj As mshtml.IHTMLEventObj)
As Boolean Implements mshtml.HTMLDocumentEvents2.onbeforeactivate
Return True
End Function

Public Function onbeforedeactivate(ByVal pEvtObj As
mshtml.IHTMLEventObj) As Boolean Implements
mshtml.HTMLDocumentEvents2.onbeforedeactivate
Return True
End Function

Public Sub onbeforeeditfocus(ByVal pEvtObj As mshtml.IHTMLEventObj)
Implements mshtml.HTMLDocumentEvents2.onbeforeeditfocus

End Sub

Public Function onbeforeupdate(ByVal pEvtObj As mshtml.IHTMLEventObj)
As Boolean Implements mshtml.HTMLDocumentEvents2.onbeforeupdate
Return True
End Function

Public Sub oncellchange(ByVal pEvtObj As mshtml.IHTMLEventObj)
Implements mshtml.HTMLDocumentEvents2.oncellchange

End Sub

Public Function onclick(ByVal pEvtObj As mshtml.IHTMLEventObj) As
Boolean Implements mshtml.HTMLDocumentEvents2.onclick
Return True
End Function

Public Function oncontextmenu(ByVal pEvtObj As mshtml.IHTMLEventObj) As
Boolean Implements mshtml.HTMLDocumentEvents2.oncontextmenu
Return True
End Function

Public Function oncontrolselect(ByVal pEvtObj As mshtml.IHTMLEventObj)
As Boolean Implements mshtml.HTMLDocumentEvents2.oncontrolselect
Return True
End Function

Public Sub ondataavailable(ByVal pEvtObj As mshtml.IHTMLEventObj)
Implements mshtml.HTMLDocumentEvents2.ondataavailable

End Sub

Public Sub ondatasetchanged(ByVal pEvtObj As mshtml.IHTMLEventObj)
Implements mshtml.HTMLDocumentEvents2.ondatasetchanged

End Sub

Public Sub ondatasetcomplete(ByVal pEvtObj As mshtml.IHTMLEventObj)
Implements mshtml.HTMLDocumentEvents2.ondatasetcomplete

End Sub

Public Function ondblclick(ByVal pEvtObj As mshtml.IHTMLEventObj) As
Boolean Implements mshtml.HTMLDocumentEvents2.ondblclick
Return True
End Function

Public Sub ondeactivate(ByVal pEvtObj As mshtml.IHTMLEventObj)
Implements mshtml.HTMLDocumentEvents2.ondeactivate

End Sub

Public Function ondragstart(ByVal pEvtObj As mshtml.IHTMLEventObj) As
Boolean Implements mshtml.HTMLDocumentEvents2.ondragstart
Return True
End Function

Public Function onerrorupdate(ByVal pEvtObj As mshtml.IHTMLEventObj) As
Boolean Implements mshtml.HTMLDocumentEvents2.onerrorupdate
Return True
End Function

Public Sub onfocusin(ByVal pEvtObj As mshtml.IHTMLEventObj) Implements
mshtml.HTMLDocumentEvents2.onfocusin

End Sub

Public Sub onfocusout(ByVal pEvtObj As mshtml.IHTMLEventObj) Implements
mshtml.HTMLDocumentEvents2.onfocusout

End Sub

Public Function onhelp(ByVal pEvtObj As mshtml.IHTMLEventObj) As
Boolean Implements mshtml.HTMLDocumentEvents2.onhelp
Return True
End Function

Public Sub onkeydown(ByVal pEvtObj As mshtml.IHTMLEventObj) Implements
mshtml.HTMLDocumentEvents2.onkeydown
MsgBox("KeyDown")
End Sub

Public Function onkeypress(ByVal pEvtObj As mshtml.IHTMLEventObj) As
Boolean Implements mshtml.HTMLDocumentEvents2.onkeypress
Return True
End Function

Public Sub onkeyup(ByVal pEvtObj As mshtml.IHTMLEventObj) Implements
mshtml.HTMLDocumentEvents2.onkeyup

End Sub

Public Sub onmousedown(ByVal pEvtObj As mshtml.IHTMLEventObj)
Implements mshtml.HTMLDocumentEvents2.onmousedown

End Sub

Public Sub onmousemove(ByVal pEvtObj As mshtml.IHTMLEventObj)
Implements mshtml.HTMLDocumentEvents2.onmousemove

End Sub

Public Sub onmouseout(ByVal pEvtObj As mshtml.IHTMLEventObj) Implements
mshtml.HTMLDocumentEvents2.onmouseout

End Sub

Public Sub onmouseover(ByVal pEvtObj As mshtml.IHTMLEventObj)
Implements mshtml.HTMLDocumentEvents2.onmouseover

End Sub

Public Sub onmouseup(ByVal pEvtObj As mshtml.IHTMLEventObj) Implements
mshtml.HTMLDocumentEvents2.onmouseup

End Sub

Public Function onmousewheel(ByVal pEvtObj As mshtml.IHTMLEventObj) As
Boolean Implements mshtml.HTMLDocumentEvents2.onmousewheel
Return True
End Function

Public Sub onpropertychange(ByVal pEvtObj As mshtml.IHTMLEventObj)
Implements mshtml.HTMLDocumentEvents2.onpropertychange

End Sub

Public Sub onreadystatechange(ByVal pEvtObj As mshtml.IHTMLEventObj)
Implements mshtml.HTMLDocumentEvents2.onreadystatechange

End Sub

Public Sub onrowenter(ByVal pEvtObj As mshtml.IHTMLEventObj) Implements
mshtml.HTMLDocumentEvents2.onrowenter

End Sub

Public Function onrowexit(ByVal pEvtObj As mshtml.IHTMLEventObj) As
Boolean Implements mshtml.HTMLDocumentEvents2.onrowexit
Return True
End Function

Public Sub onrowsdelete(ByVal pEvtObj As mshtml.IHTMLEventObj)
Implements mshtml.HTMLDocumentEvents2.onrowsdelete

End Sub

Public Sub onrowsinserted(ByVal pEvtObj As mshtml.IHTMLEventObj)
Implements mshtml.HTMLDocumentEvents2.onrowsinserted

End Sub

Public Sub onselectionchange(ByVal pEvtObj As mshtml.IHTMLEventObj)
Implements mshtml.HTMLDocumentEvents2.onselectionchange

End Sub

Public Function onselectstart(ByVal pEvtObj As mshtml.IHTMLEventObj) As
Boolean Implements mshtml.HTMLDocumentEvents2.onselectstart
Return True
End Function

Public Function onstop(ByVal pEvtObj As mshtml.IHTMLEventObj) As
Boolean Implements mshtml.HTMLDocumentEvents2.onstop
Return True
End Function
End Class

Public Class IEEvents
Implements SHDocVw.DWebBrowserEvents2
Public fm As Form1
Private icp As System.Runtime.InteropServices.UCOMIConnectionPoint
Private cookie As Integer = -1
Private m_ie As AxSHDocVw.AxWebBrowser

Public Sub New(ByRef ie As AxSHDocVw.AxWebBrowser)
' Call QueryInterface for IConnectionPointContainer
m_ie = ie
Dim icpc As
System.Runtime.InteropServices.UCOMIConnectionPointContainer =
CType(ie.GetOcx(),
System.Runtime.InteropServices.UCOMIConnectionPointContainer)
' Find the connection point for the
' DWebBrowserEvents2 source interface
Dim g As Guid = GetType(SHDocVw.DWebBrowserEvents2).GUID
icpc.FindConnectionPoint(g, icp)

'Pass a pointer to the host to the connection point
icp.Advise(Me, cookie)

' Show the browser
ie.Visible = True
Dim oURL As Object = "http://www.google.com"
Dim oEmpty As Object = ""
ie.Navigate2(oURL, oEmpty, oEmpty, oEmpty, oEmpty)

End Sub


Public Sub BeforeNavigate2(ByVal pDisp As Object, ByRef URL As Object,
ByRef Flags As Object, ByRef TargetFrameName As Object, ByRef PostData As
Object, ByRef Headers As Object, ByRef Cancel As Boolean) Implements
SHDocVw.DWebBrowserEvents2.BeforeNavigate2

End Sub

Public Sub ClientToHostWindow(ByRef CX As Integer, ByRef CY As Integer)
Implements SHDocVw.DWebBrowserEvents2.ClientToHostWindow

End Sub

Public Sub CommandStateChange(ByVal Command As Integer, ByVal Enable As
Boolean) Implements SHDocVw.DWebBrowserEvents2.CommandStateChange

End Sub

Public Sub DocumentComplete(ByVal pDisp As Object, ByRef URL As Object)
Implements SHDocVw.DWebBrowserEvents2.DocumentComplete
Try
Dim doc As mshtml.HTMLDocument = CType(CType(pDisp,
SHDocVw.IWebBrowser2).Document, mshtml.HTMLDocument)
doc.designMode = "on"

Dim pConPtCon As
System.Runtime.InteropServices.UCOMIConnectionPointContainer = CType(doc,
System.Runtime.InteropServices.UCOMIConnectionPointContainer)
Dim guid As Guid = GetType(mshtml.HTMLDocumentEvents2).GUID
Dim pConPt As
System.Runtime.InteropServices.UCOMIConnectionPoint
pConPtCon.FindConnectionPoint(guid, pConPt)
Dim d As IEHTMLDocumentEvents = New IEHTMLDocumentEvents
pConPt.Advise(d, Form1.dwCookie2)
Catch ex As Exception
MsgBox(ex.ToString())
End Try
End Sub
Private Function ClickEventHandler(ByVal e As mshtml.IHTMLEventObj) As
Boolean
fm.add_list(e.type + ":" + e.srcElement.tagName)
Return True
End Function
Private Sub MouseOverEventHandler(ByVal e As mshtml.IHTMLEventObj)
fm.add_list(e.type + ":" + e.srcElement.tagName)
End Sub
Public Sub DownloadBegin() Implements
SHDocVw.DWebBrowserEvents2.DownloadBegin

End Sub

Public Sub DownloadComplete() Implements
SHDocVw.DWebBrowserEvents2.DownloadComplete

End Sub

Public Sub FileDownload(ByRef Cancel As Boolean) Implements
SHDocVw.DWebBrowserEvents2.FileDownload

End Sub

Public Sub NavigateComplete2(ByVal pDisp As Object, ByRef URL As
Object) Implements SHDocVw.DWebBrowserEvents2.NavigateComplete2

End Sub

Public Sub NavigateError(ByVal pDisp As Object, ByRef URL As Object,
ByRef Frame As Object, ByRef StatusCode As Object, ByRef Cancel As Boolean)
Implements SHDocVw.DWebBrowserEvents2.NavigateError

End Sub

Public Sub NewWindow2(ByRef ppDisp As Object, ByRef Cancel As Boolean)
Implements SHDocVw.DWebBrowserEvents2.NewWindow2

End Sub
Public Sub NewWindow3(ByRef ppDisp As Object, ByRef Cancel As Boolean,
ByVal dwFlags As System.UInt32, ByVal bstrUrlContext As String, ByVal
bstrUrl As String) Implements SHDocVw.DWebBrowserEvents2.NewWindow3

End Sub
Public Sub OnFullScreen(ByVal FullScreen As Boolean) Implements
SHDocVw.DWebBrowserEvents2.OnFullScreen

End Sub

Public Sub OnMenuBar(ByVal MenuBar As Boolean) Implements
SHDocVw.DWebBrowserEvents2.OnMenuBar

End Sub

Public Sub OnQuit() Implements SHDocVw.DWebBrowserEvents2.OnQuit

End Sub

Public Sub OnStatusBar(ByVal StatusBar As Boolean) Implements
SHDocVw.DWebBrowserEvents2.OnStatusBar

End Sub

Public Sub OnTheaterMode(ByVal TheaterMode As Boolean) Implements
SHDocVw.DWebBrowserEvents2.OnTheaterMode

End Sub

Public Sub OnToolBar(ByVal ToolBar As Boolean) Implements
SHDocVw.DWebBrowserEvents2.OnToolBar

End Sub

Public Sub OnVisible(ByVal Visible As Boolean) Implements
SHDocVw.DWebBrowserEvents2.OnVisible

End Sub

Public Sub PrintTemplateInstantiation(ByVal pDisp As Object) Implements
SHDocVw.DWebBrowserEvents2.PrintTemplateInstantiation

End Sub

Public Sub PrintTemplateTeardown(ByVal pDisp As Object) Implements
SHDocVw.DWebBrowserEvents2.PrintTemplateTeardown

End Sub

Public Sub PrivacyImpactedStateChange(ByVal bImpacted As Boolean)
Implements SHDocVw.DWebBrowserEvents2.PrivacyImpactedStateChange

End Sub

Public Sub ProgressChange(ByVal Progress As Integer, ByVal ProgressMax
As Integer) Implements SHDocVw.DWebBrowserEvents2.ProgressChange

End Sub

Public Sub PropertyChange(ByVal szProperty As String) Implements
SHDocVw.DWebBrowserEvents2.PropertyChange

End Sub

Public Sub SetSecureLockIcon(ByVal SecureLockIcon As Integer)
Implements SHDocVw.DWebBrowserEvents2.SetSecureLockIcon

End Sub

Public Sub StatusTextChange(ByVal Text As String) Implements
SHDocVw.DWebBrowserEvents2.StatusTextChange

End Sub

Public Sub TitleChange(ByVal Text As String) Implements
SHDocVw.DWebBrowserEvents2.TitleChange

End Sub

Public Sub UpdatePageStatus(ByVal pDisp As Object, ByRef nPage As
Object, ByRef fDone As Object) Implements
SHDocVw.DWebBrowserEvents2.UpdatePageStatus

End Sub

Public Sub WindowClosing(ByVal IsChildWindow As Boolean, ByRef Cancel
As Boolean) Implements SHDocVw.DWebBrowserEvents2.WindowClosing

End Sub

Public Sub WindowSetHeight(ByVal Height As Integer) Implements
SHDocVw.DWebBrowserEvents2.WindowSetHeight

End Sub

Public Sub WindowSetLeft(ByVal Left As Integer) Implements
SHDocVw.DWebBrowserEvents2.WindowSetLeft

End Sub

Public Sub WindowSetResizable(ByVal Resizable As Boolean) Implements
SHDocVw.DWebBrowserEvents2.WindowSetResizable

End Sub

Public Sub WindowSetTop(ByVal Top As Integer) Implements
SHDocVw.DWebBrowserEvents2.WindowSetTop

End Sub

Public Sub WindowSetWidth(ByVal Width As Integer) Implements
SHDocVw.DWebBrowserEvents2.WindowSetWidth

End Sub
End Class
#End Region

Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top