我有一个旧的,遗留的VB6应用程序,它使用DHTML编辑控件作为HTML编辑器.Microsoft DHTML编辑控件,又名DHTMLEd,可能只是一个内部使用IE自己的本机编辑功能的IE控件.
我想修改应用程序以实现像Word这样的智能引号.具体来说,"替换为"或"和'被替换为'或',因为它是键入的;如果用户在替换后立即按下Ctrl + Z,它将返回到直引号.
有人有代码那样做吗?
如果你没有DHTML/VB6的代码,但确实有一个可以在带有contentEditable区域的浏览器中运行的JavaScript代码,我也可以使用它
这是VB6版本:
Private Sub DHTMLEdit1_onkeypress() Dim e As Object Set e = DHTMLEdit1.DOM.parentWindow.event 'Perform smart-quote replacement' Select Case e.keyCode Case 34: 'Double-Quote' e.keyCode = 0 If IsAtWordEnd Then InsertDoubleUndo ChrW$(8221), ChrW$(34) Else InsertDoubleUndo ChrW$(8220), ChrW$(34) End If Case 39: 'Single-Quote' e.keyCode = 0 If IsAtWordEnd Then InsertDoubleUndo ChrW$(8217), ChrW$(39) Else InsertDoubleUndo ChrW$(8216), ChrW$(39) End If End Select End Sub Private Function IsLetter(ByVal character As String) As Boolean IsLetter = UCase$(character) <> LCase$(character) End Function Private Sub InsertDoubleUndo(VisibleText As String, HiddenText As String) Dim selection As Object Set selection = DHTMLEdit1.DOM.selection.createRange() selection.Text = HiddenText selection.moveStart "character", -Len(HiddenText) selection.Text = VisibleText End Sub Private Function IsAtWordEnd() As Boolean Dim ch As String ch = PreviousChar IsAtWordEnd = (ch <> " ") And (ch <> "") End Function Private Function PreviousChar() As String Dim selection As Object Set selection = m_dom.selection.createRange() selection.moveStart "character", -1 PreviousChar = selection.Text End Function
注意:此解决方案在撤消链中插入另一个级别.例如,键入"This is a test"会给出一个"This is a test"链接 - >"这是一个测试" - > "这是一个测试 - >" - >"(粗体的额外级别).要删除这个额外级别,您必须实现某种PostMessage+subclassing
不涉及取消本机按键的解决方案
编辑:如果您的目标是Windows Vista,请不要忘记包含DHTML编辑控件可再发行组件.