用VB写的IE工具栏源码

 

1.API 函数      SetParent

  设一个对象的父对象?参数是控件(对象)的句柄。。这招够绝!!

         SetParent  .hwnd, m_lToolWnd
         这样就可以把VB窗体上的控件放到IE工具栏上去 !! API的作用真大!!!!

 

2.BHO 调用     

主要实现下面这么多接口,郁闷O..红色是真正BHO的接口啦!!不过其它的好像也挺有用.具体每一个有什么用,暂时还没有研究到..呵呵!!!

Implements olelib.IOleWindow
Implements olelib.IDeskBand
Implements olelib.IObjectWithSite
Implements olelib.IInputObject
Implements olelib.IPersist
Implements olelib.IOleControlSite
Implements olelib2.IPersistStream
把实现IObjectWithSIte 接口的两个过程的源码贴上吧!

Implements olelib.IObjectWithSite '定义接口

 

Private m_oSite As olelib.IUnknown           'Band site object
Private m_oIOS As olelib.IInputObjectSite
Private WithEvents m_oIE As InternetExplorer 'IE Object

 

''实现接口

Private Sub IObjectWithSite_GetSite(riid As olelib.UUID, ppvSite As stdole.IUnknown)
Dim lErr As Long

' Get the requested interface
lErr = m_oSite.QueryInterface(riid, ppvSite)

If lErr Then Err.Raise lErr

End Sub

Private Sub IObjectWithSite_SetSite(ByVal pUnkSite As stdole.IUnknown)
Dim oSiteOW As IOleWindow

On Error Resume Next

' Store the new site object
Set m_oSite = pUnkSite
Set m_oIOS = pUnkSite
     
If Not m_oSite Is Nothing Then

   'Get the IE instance
   Set m_oIE = FindIESite(m_oSite)
   'initialize the form providing the controls etc
   Call frmToolbar.Init(m_oIE, Me)
   'Create the toolbar
   CreateToolbar
        
Else
   Set m_oIE = Nothing
End If

End Sub

 

3.VB工程中的(隐藏)属性。

用Notepad 打开 clsToolbar.cls

 
 

VERSION 1.0 CLASS
BEGIN
  MultiUse = -1  'True
  Persistable = 0  'NotPersistable
  DataBindingBehavior = 0  'vbNone
  DataSourceBehavior  = 0  'vbNone
  MTSTransactionMode  = 0  'NotAnMTSObject
END
Attribute VB_Name = "CToolbar"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = True
Attribute VB_Description = "Klemen's Sample bar"

这行代码使我每次编译出的DLL文件都被注册成:“Klemen's Sample bar”,还好被我发现己经修改了!!!

 
 

其实:VB_Description 这个属性是VB工程序的一个属性,用NOTEPAD 打开工程文件也可以看到这个属性,但是为什么在类模块.cls中加入这个属性也可以呢??看来VB中有很多地方我们还不知道啊!!!


4.关于如何增加一个按钮:

两种方法:

A。使用我在最前面提到过的  SetParent  .hwnd, m_lToolWnd,

不过种加的是VB的按钮,不好看。

B。看代码吧:

 
 

Private Sub AddToolbarButtons()   ''创建工具栏按钮
'create the toolbar buttons
Const PROC_NAME = "AddToolbarButtons"
Log "Entered", MODULE_NAME, PROC_NAME

Const strButtonFile = "&LinkPal IE Bar 1.0"
Const strButtonSearch = "常用网站[&U]"

ReDim m_Buttons(0 To 3)

'kind of 'File' menu
m_Buttons(0).idCommand = ID_FILE
m_Buttons(0).iString = StrPtr(strButtonFile)
m_Buttons(0).fsStyle = CTBDropDown Or CTBAutoSize
'm_Buttons(0).fsStyle = TBSTYLE_BUTTON + TBSTYLE_AUTOSIZE
m_Buttons(0).fsState = TBSTATE_ENABLED
m_Buttons(0).iBitmap = 1

'width of the separator controls width of the combobox
m_Buttons(1).fsStyle = BTNS_SEP
m_Buttons(1).iBitmap = 160

'drop down menu providing the web sites
m_Buttons(2).idCommand = ID_SEARCH
m_Buttons(2).iString = StrPtr(strButtonSearch)
m_Buttons(2).fsStyle = CTBDropDown Or CTBAutoSize
m_Buttons(2).fsState = TBSTATE_ENABLED
m_Buttons(2).iBitmap = 0

 

m_Buttons(3).idCommand = ID_CMD
m_Buttons(3).iString = StrPtr("MyBlog")
m_Buttons(3).fsStyle = CTBAutoSize
m_Buttons(3).fsState = TBSTATE_ENABLED
m_Buttons(3).iBitmap = 0

SendMessage m_lToolWnd, TB_ADDBUTTONSW, 4, m_Buttons(0)

End Sub

其中红色地方是我按上面代码增加上去的,他可以方便地加入一个IE 工具栏的标准按钮
 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值