在网页看到过纯理论的文章,在摸索了N久之后,终于用VB6实现。
1、找一个olelib.tlb的文件,网上有下。
2、新建VB工程,加入webbrowser控件,引用上面的文件。
3、FORM1上加上WebBrowser1。切换至代码。
4、窗体代码(PS:代码我一律不解释。)
Option Explicit
Implements IDocHostUIHandler
Dim mshow As Boolean
Dim mICustomDoc As ICustomDoc
Private oTest As cTest
Private Sub Form_Load()
WebBrowser1.Navigate2 App.Path & "/test.html"
End Sub
Private Sub IDocHostUIHandler_EnableModeless(ByVal fEnable As olelib.BOOL)
'IDocHostUIHandler.EnableModeless fEnable
End Sub
Private Function IDocHostUIHandler_FilterDataObject(ByVal pDO As olelib.IDataObject) As olelib.IDataObject
'Set IDocHostUIHandler_FilterDataObject = IDocHostUIHandler.FilterDataObject(pDO)
End Function
Private Function IDocHostUIHandler_GetDropTarget(ByVal pDropTarget As olelib.IDropTarget) As olelib.IDropTarget
'Set IDocHostUIHandler_GetDropTarget = IDocHostUIHandler.GetDropTarget(pDropTarget)
End Function
Private Function IDocHostUIHandler_GetExternal() As Object
Set oTest = New cTest
Set IDocHostUIHandler_GetExternal = oTest ' IDocHostUIHandler.GetExternal
End Function
Private Sub IDocHostUIHandler_GetHostInfo(pInfo As olelib.DOCHOSTUIINFO)
'IDocHostUIHandler.GetHostInfo pInfo
End Sub
Private Sub IDocHostUIHandler_GetOptionKeyPath(pOLESTRchKey As Long,ByVal dw As Long)
'IDocHostUIHandler.GetOptionKeyPath pOLESTRchKey,dw
End Sub
Private Sub IDocHostUIHandler_HideUI()
'IDocHostUIHandler.HideUI
End Sub
Private Sub IDocHostUIHandler_OnDocWindowActivate(ByVal fActivate As olelib.BOOL)
'IDocHostUIHandler.OnDocWindowActivate fActivate
End Sub
Private Sub IDocHostUIHandler_OnFrameWindowActivate(ByVal fActivate As olelib.BOOL)
'IDocHostUIHandler.OnFrameWindowActivate fActivate
End Sub
Private Sub IDocHostUIHandler_ResizeBorder(prcBorder As olelib.RECT,ByVal pUIWindow As olelib.IOleInPlaceUIWindow,ByVal fRameWindow As olelib.BOOL)
'IDocHostUIHandler.ResizeBorder prcBorder,pUIWindow,fRameWindow
End Sub
Private Sub IDocHostUIHandler_ShowContextMenu(ByVal dwContext As olelib.ContextMenuTarget,pPOINT As olelib.Point,ByVal pCommandTarget As olelib.IOleCommandTarget,ByVal HTMLTagElement As Object)
'IDocHostUIHandler.ShowContextMenu dwContext,pPOINT,pCommandTarget,HTMLTagElement
End Sub
Private Sub IDocHostUIHandler_ShowUI(ByVal dwID As Long,ByVal pActiveObject As olelib.IOleInPlaceActiveObject,ByVal pFrame As olelib.IOleInPlaceFrame,ByVal pDoc As olelib.IOleInPlaceUIWindow)
'IDocHostUIHandler.ShowUI dwID,pActiveObject,pFrame,pDoc
End Sub
Private Sub IDocHostUIHandler_TranslateAccelerator(lpMsg As olelib.MSG,pguidCmdGroup As olelib.UUID,ByVal nCmdID As Long)
'IDocHostUIHandler.TranslateAccelerator lpmsg,pguidCmdGroup,nCmdID
End Sub
Private Function IDocHostUIHandler_TranslateUrl(ByVal dwTranslate As Long,ByVal pchURLIn As Long) As Long
' IDocHostUIHandler_TranslateUrl = IDocHostUIHandler.TranslateUrl(dwTranslate,pchURLIn)
End Function
Private Sub IDocHostUIHandler_UpdateUI()
'IDocHostUIHandler.UpdateUI
End Sub
Private Sub Form_Resize()
On Error Resume Next
WebBrowser1.Top = 0
WebBrowser1.Left = 0
WebBrowser1.Width = Me.ScaleWidth
WebBrowser1.Height = Me.ScaleHeight
End Sub
Private Sub Webbrowser1_DownloadComplete()
Set mICustomDoc = Me.WebBrowser1.Document
mICustomDoc.SetUIHandler Me
End Sub
5、加一类,cTest
Option Explicit
Public Function HelloWorld()
MsgBox "Hello World. ",vbInformation,"Message"
End Function
6、同目录一个HTML文件,test.html
Vansoftfunction Test()
{
external.HelloWorld();
}
this is test function
OK了,窗体打开时显示网页,单击test,弹出hello world对话框。
仅仅是最简单的示例。
这样做的好处有几个,网上的那篇理论文章也说了,有兴趣的自己去搜索吧。
总结
以上是编程之家为你收集整理的VB6实现界面与功能代码分离全部内容,希望文章能够帮你解决VB6实现界面与功能代码分离所遇到的程序开发问题。
如果觉得编程之家网站内容还不错,欢迎将编程之家网站推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
小编个人微信号 jb51ccc
喜欢与人分享编程技术与工作经验,欢迎加入编程之家官方交流群!