轉載
看到很多關于WebBrowser控件禁止右鍵的提問,回復的方法很多,其中有提到使用微軟提供的Webbrowser擴展COM服務器對象(WBCustomizer.dll),但是該方法在我們想使用Webbrowser編輯網頁(Webbrowser1.Document.execCommand "editMode")的時候有很多弊端,比如不能顯示選中的文本等。另有些方法也就不用一一列舉了。
這兒我想提到的是關于MSHTML.HTMLDocument
引用Microsoft HTML OBject Library
Rem #窗體代碼#
Dim WithEvents M_Dom As MSHTML.HTMLDocument
Private Function M_Dom_oncontextmenu() As Boolean
M_Dom_oncontextmenu = False
End Function
Private Sub Webbrowser1_DownloadComplete()
Set M_Dom = Webbrowser1.Document
End Sub
Rem 好了,右鍵菜單沒有了
===============================================================================
控件調用和獲得收藏夾里面
基本上用 specialfolder(6 ) 就可以得到收藏夾的路徑, 然后你可以用dir去循環讀入每個目錄,然后dir里面的file, file的名字就是你要的收藏的名字, 路徑可以自己根據從上面得到的路徑去得到.
如果你不用dir也可以用vb的dir控件.
Private Type SHITEMID
cb As Long
abID As Byte
End Type
Public Type ITEMIDLIST
mkid As SHITEMID
End Type
Public Function SpecialFolder(ByRef CSIDL As Long) As String
´locate the favorites folder
Dim R As Long
Dim sPath As String
Dim IDL As ITEMIDLIST
Const NOERROR = 0
Const MAX_LENGTH = 260
R = SHGetSpecialFolderLocation(MDIMain.hwnd, CSIDL, IDL)
If R = NOERROR Then
sPath = Space$(MAX_LENGTH)
R = SHGetPathFromIDList(ByVal IDL.mkid.cb, ByVal sPath)
If R Then
SpecialFolder = Left$(sPath, InStr(sPath, vbNullChar) - 1)
End If
End If
End Function
===================================================================================================
全屏
是的,webbrowser本生是一個控件, 你要它全屏,就是要它所在的窗體全屏, 可以用setwindowlong取消窗體的 title, 用Call ShowWindow(FindWindow("Shell_traywnd", ""), 0) 隱藏tray,就是下邊那個包含開始那一行. 用Call ShowWindow(FindWindow("Shell_traywnd", ""), 9) 恢復. 夠詳細了吧.
然后在form1.windowstate = 2 就可以了.
==============================================================================================================
選擇網頁上的內容。
Private Sub Command1_Click()
´請先選中一些內容
Me.WebBrowser1.ExecWB OLECMDID_COPY, OLECMDEXECOPT_DODEFAULT
MsgBox Clipboard.GetText
End Sub
==============================================================================================================
用IE來下載文件
Private Declare Function DoFileDownload Lib "shdocvw.dll" (ByVal lpszFile As String) As Long
Private Sub Command1_Click()
Dim sDownload As String
sDownload = StrConv(Text1.Text, vbUnicode)
Call DoFileDownload(sDownload)
End Sub
Private Sub Form_Load()
Text1.Text = ""
Form1.Caption = "Audiograbber 1.62 Full"
Text2.Text = ""
End Sub
================================================================================================================
我要動態加載和刪除WebBrowser控件應該怎么做?
Private Sub Command1_Click()
Form1.Controls.Add "shell.explorer.2", "NewWeb", Form1
With Form1!NewWeb
.Visible = True
.Width = 10000
.Height = 10000
.Left = 0
.Top = 0
.Navigate2 ""
End With
End Sub
Private Sub Command2_Click()
Controls.Remove Form1!newweb
End Sub
Form1.Controls.Add "shell.explorer.2", newweb(newweb.Count), Form1
With Form1!newweb(newweb.Count)
.Visible = True
.Width = 1000
.Height = 1000
.Left = newweb(newweb.Count - 1).Left + newweb(newweb.Count - 1).Width
.Top = 0
´.Navigate2 ""
End With
為什么他說我
Form1.Controls.Add "shell.explorer.2", newweb(newweb.Count), Form1
這一行錯誤13 類型不匹配?
ps:我在form中已經有了一個newweb(0)控件
先為一個WebBrowser
Dim i As Integer
Private Sub AddWeb_Click()
For i = 1 To 10
Load NewWeb(i)
NewWeb(i).Top = i * 100
NewWeb(i).Left = i * 100
NewWeb(i).Visible = True
Next i
End Sub
Private Sub DelWeb_Click()
For i = 1 To 10
Unload NewWeb(i)
Next i
End Sub
=============================================================================================================
一個把頁面保存為MHT(即MHTML)文件
1、
謝謝樓上幾位大俠!我現在將 pcwak(書劍狂生[MS MVP]) 大俠提供的資料貼出來,以供大家參考:
我終于找到一個把頁面保存為MHT(即MHTML)文件的方法了!
首先,在工程中必須要引用一個庫:
Library CDO
D:\WINNT\System32\cdosys.dll
Microsoft CDO for Windows 2000 Library
其次,需要Stream對應的接口的支持,如果你一時找不到就使用支持這個的較新的ADO就行了,如
Library ADODB
D:\Program Files\Common Files\system\ado\msado15.dll
Microsoft ActiveX Data Objects 2.5 Library
代碼如下,十分簡單(同時由于流的特點,顯示在實際應用中沒必要象本例中那樣把文件保存到磁盤上就可直接轉換為字符串或字節數組什么的處理的。
另,對于Microsoft CDO for Windows 2000 Library這個庫,在WIN98中要怎么使用還沒試過,感興趣的朋友可以試試并跟帖,以豐富完善其內容:)
Private Sub Command1_Click()
´ Reference to Microsoft ActiveX Data Objects 2.5 Library
´ Reference to Microsoft CDO for Windows 2000 Library
Dim iMsg As New CDO.Message
Dim iConf As New CDO.Configuration
Dim objStream As ADODB.Stream
With iMsg
.CreateMHTMLBody "";, , _
"domain\username", _
"password"
Set objStream = .GetStream
Call objStream.SaveToFile("f:\test.mht", adSaveCreateOverWrite)
End With
End Sub
2、
´首先加入對ADODB和CDO(Microsoft CDO for Windows 2000 Library,對應文件名為CDOSYS.dll)的引用
Private Sub Command1_Click()
Dim message As New CDO.message
Dim Outstream As ADODB.Stream
On Error GoTo myerr1
Call message.CreateMHTMLBody("", CDO.CdoMHTMLFlags.cdoSuppressNone, "", "")
Set Outstream = message.GetStream
Call Outstream.SaveToFile("c:\test.mht", ADODB.SaveOptionsEnum.adSaveCreateOverWrite)
MsgBox "完成"
Exit Sub
myerr1:
Set message = Nothing
Set Outstream = Nothing
End Sub
=================================================================================================================
請問高手們怎樣在WebBrowser控件調用收藏夾和在收藏夾里添加收藏
Option Explicit
Private Sub Command1_Click()
Dim ObjSUH As New ShellUIHelper
ObjSUH.AddFavorite "", "CSDN"
Set ObjSUH = Nothing
End Sub
=================================================================================================================
原文轉自:http://www.anti-gravitydesign.com