WEBBROWSER 技巧.docx
《WEBBROWSER 技巧.docx》由会员分享,可在线阅读,更多相关《WEBBROWSER 技巧.docx(22页珍藏版)》请在冰豆网上搜索。
![WEBBROWSER 技巧.docx](https://file1.bdocx.com/fileroot1/2023-2/6/0d1c4c7f-8d4e-4aaf-8ac6-e768889a423c/0d1c4c7f-8d4e-4aaf-8ac6-e768889a423c1.gif)
WEBBROWSER技巧
看到很多关于WebBrowser控件禁止右键的提问,回复的方法很多,其中有提到使用微软提供的Webbrowser扩展COM服务器对象(WBCustomizer.dll),但是该方法在我们想使用Webbrowser编辑网页(Webbrowser1.Document.execCommand"editMode")的时候有很多弊端,比如不能显示选中的文本等。
另有些方法也就不用一一列举了。
这儿我想提到的是关于MSHTML.HTMLDocument
引用MicrosoftHTMLOBjectLibrary
Rem#窗体代码#
DimWithEventsM_DomAsMSHTML.HTMLDocument
PrivateFunctionM_Dom_oncontextmenu()AsBoolean
M_Dom_oncontextmenu=False
EndFunction
PrivateSubWebbrowser1_DownloadComplete()
SetM_Dom=Webbrowser1.Document
EndSub
Rem好了,右键菜单没有了
===============================================================================
控件调用和获得收藏夹里面
基本上用specialfolder(6)就可以得到收藏夹的路径,然后你可以用dir去循环读入每个目录,然后dir里面的file,file的名字就是你要的收藏的名字,路径可以自己根据从上面得到的路径去得到.
如果你不用dir也可以用vb的dir控件.
PrivateTypeSHITEMID
cbAsLong
abIDAsByte
EndType
PublicTypeITEMIDLIST
mkidAsSHITEMID
EndType
PublicFunctionSpecialFolder(ByRefCSIDLAsLong)AsString
'locatethefavoritesfolder
DimRAsLong
DimsPathAsString
DimIDLAsITEMIDLIST
ConstNOERROR=0
ConstMAX_LENGTH=260
R=SHGetSpecialFolderLocation(MDIMain.hwnd,CSIDL,IDL)
IfR=NOERRORThen
sPath=Space$(MAX_LENGTH)
R=SHGetPathFromIDList(ByValIDL.mkid.cb,ByValsPath)
IfRThen
SpecialFolder=Left$(sPath,InStr(sPath,vbNullChar)-1)
EndIf
EndIf
EndFunction
===================================================================================================
全屏
是的,webbrowser本生是一个控件,你要它全屏,就是要它所在的窗体全屏,可以用setwindowlong取消窗体的title,用CallShowWindow(FindWindow("Shell_traywnd",""),0)隐藏tray,就是下边那个包含开始那一行.用CallShowWindow(FindWindow("Shell_traywnd",""),9)恢复.够详细了吧.
然后在form1.windowstate=2就可以了.
==============================================================================================================
选择网页上的内容。
PrivateSubCommand1_Click()
'请先选中一些内容
Me.WebBrowser1.ExecWBOLECMDID_COPY,OLECMDEXECOPT_DODEFAULT
MsgBoxClipboard.GetText
EndSub
==============================================================================================================
用IE来下载文件
PrivateDeclareFunctionDoFileDownloadLib"shdocvw.dll"(ByVallpszFileAsString)AsLong
PrivateSubCommand1_Click()
DimsDownloadAsString
sDownload=StrConv(Text1.Text,vbUnicode)
CallDoFileDownload(sDownload)
EndSub
PrivateSubForm_Load()
Text1.Text="http:
//www.chat.ru/~softdaily/fo-ag162.zip"
Form1.Caption="Audiograbber1.62Full"
Text2.Text="
EndSub
================================================================================================================
我要动态加载和删除WebBrowser控件应该怎么做?
PrivateSubCommand1_Click()
Form1.Controls.Add"shell.explorer.2","NewWeb",Form1
WithForm1!
NewWeb
.Visible=True
.Width=10000
.Height=10000
.Left=0
.Top=0
.Navigate2""
EndWith
EndSub
PrivateSubCommand2_Click()
Controls.RemoveForm1!
newweb
EndSub
Form1.Controls.Add"shell.explorer.2",newweb(newweb.Count),Form1
WithForm1!
newweb(newweb.Count)
.Visible=True
.Width=1000
.Height=1000
.Left=newweb(newweb.Count-1).Left+newweb(newweb.Count-1).Width
.Top=0
'.Navigate2""
EndWith
为什么他说我
Form1.Controls.Add"shell.explorer.2",newweb(newweb.Count),Form1
这一行错误13类型不匹配?
ps:
我在form中已经有了一个newweb(0)控件
先为一个WebBrowser
DimiAsInteger
PrivateSubAddWeb_Click()
Fori=1To10
LoadNewWeb(i)
NewWeb(i).Top=i*100
NewWeb(i).Left=i*100
NewWeb(i).Visible=True
Nexti
EndSub
PrivateSubDelWeb_Click()
Fori=1To10
UnloadNewWeb(i)
Nexti
EndSub
=============================================================================================================
一个把页面保存为MHT(即MHTML)文件
1、
谢谢楼上几位大侠!
我现在将pcwak(书剑狂生[MSMVP])大侠提供的资料贴出来,以供大家参考:
我终于找到一个把页面保存为MHT(即MHTML)文件的方法了!
首先,在工程中必须要引用一个库:
LibraryCDO
D:
\WINNT\System32\cdosys.dll
MicrosoftCDOforWindows2000Library
其次,需要Stream对应的接口的支持,如果你一时找不到就使用支持这个的较新的ADO就行了,如
LibraryADODB
D:
\ProgramFiles\CommonFiles\system\ado\msado15.dll
MicrosoftActiveXDataObjects2.5Library
代码如下,十分简单(同时由于流的特点,显示在实际应用中没必要象本例中那样把文件保存到磁盘上就可直接转换为字符串或字节数组什么的处理的。
另,对于MicrosoftCDOforWindows2000Library这个库,在WIN98中要怎么使用还没试过,感兴趣的朋友可以试试并跟帖,以丰富完善其内容:
)
PrivateSubCommand1_Click()
'ReferencetoMicrosoftActiveXDataObjects2.5Library
'ReferencetoMicrosoftCDOforWindows2000Library
DimiMsgAsNewCDO.Message
DimiConfAsNewCDO.Configuration
DimobjStreamAsADODB.Stream
WithiMsg
.CreateMHTMLBody",_
"domain\username",_
"password"
SetobjStream=.GetStream
CallobjStream.SaveToFile("f:
\test.mht",adSaveCreateOverWrite)
EndWith
EndSub
2、
'首先加入对ADODB和CDO(MicrosoftCDOforWindows2000Library,对应文件名为CDOSYS.dll)的引用
PrivateSubCommand1_Click()
DimmessageAsNewCDO.message
DimOutstreamAsADODB.Stream
OnErrorGoTomyerr1
Callmessage.CreateMHTMLBody("",CDO.CdoMHTMLFlags.cdoSuppressNone,"","")
SetOutstream=message.GetStream
CallOutstream.SaveToFile("c:
\test.mht",ADODB.SaveOptionsEnum.adSaveCreateOverWrite)
MsgBox"完成"
ExitSub
myerr1:
Setmessage=Nothing
SetOutstream=Nothing
EndSub
=================================================================================================================
请问高手们怎样在WebBrowser控件调用收藏夹和在收藏夹里添加收藏
OptionExplicit
PrivateSubCommand1_Click()
DimObjSUHAsNewShellUIHelper
ObjSUH.AddFavorite"","CSDN"
SetObjSUH=Nothing
EndSub
取得网页中特定的链接
PrivateSubCommand1_Click()
WebBrowser1.Navigate"
EndSub
PrivateSubWebBrowser1_NavigateComplete2(ByValpDispAsObject,URLAsVariant)
Dima
ForEachaInWebBrowser1.Document.All
Ifa.tagname="A"Then
Ifa.href="Then
a.Click
EndIf
EndIf
Next
EndSub
OptionExplicit
Privatem_bDoneAsBoolean
PrivateSubCommand1_Click()
Ifm_bDoneThen
DimdocAsIHTMLDocument2
Setdoc=WebBrowser1.Document
DimaLinkAsHTMLLinkElement
SetaLink=doc.links(0)
aLink.Click
EndIf
EndSub
PrivateSubForm_Load()
WebBrowser1.Navigate"
EndSub
PrivateSubWebBrowser1_DocumentComplete(ByValpDispAsObject,URLAsVariant)
m_bDone=True
EndSub
==================================================
Thefollowingcodecanbeusedtoqueryanddeletefilesintheinternetcache(includingcookies).Ademonstrationroutinecanbefoundatthebottomofthispost.Note,theenumeratedtypeeCacheTypeisnotsupportedinExcel97,butcanbechangedtoalistofPublicConstantseg.PublicConsteNormal=&H1&.
OptionExplicit
'--------------------------Types,constsandstructures
PrivateConstERROR_CACHE_FIND_FAILAsLong=0
PrivateConstERROR_CACHE_FIND_SUCCESSAsLong=1
PrivateConstERROR_FILE_NOT_FOUNDAsLong=2
PrivateConstERROR_ACCESS_DENIEDAsLong=5
PrivateConstERROR_INSUFFICIENT_BUFFERAsLong=122
PrivateConstMAX_CACHE_ENTRY_INFO_SIZEAsLong=4096
PrivateConstLMEM_FIXEDAsLong=&H0
PrivateConstLMEM_ZEROINITAsLong=&H40
PublicEnumeCacheType
eNormal=&H1&
eEdited=&H8&
eTrackOffline=&H10&
eTrackOnline=&H20&
eSticky=&H40&
eSparse=&H10000
eCookie=&H100000
eURLHistory=&H200000
eURLFindDefaultFilter=0&
EndEnum
PrivateTypeFILETIME
dwLowDateTimeAsLong
dwHighDateTimeAsLong
EndType
PrivateTypeINTERNET_CACHE_ENTRY_INFO
dwStructSizeAsLong
lpszSourceUrlNameAsLong
lpszLocalFileNameAsLong
CacheEntryType AsLong 'Typeofentryreturned
dwUseCountAsLong
dwHitRateAsLong
dwSizeLowAsLong
dwSizeHighAsLong
LastModifiedTimeAsFILETIME
ExpireTimeAsFILETIME
LastAccessTimeAsFILETIME
LastSyncTimeAsFILETIME
lpHeaderInfoAsLong
dwHeaderInfoSizeAsLong
lpszFileExtensionAsLong
dwExemptDelta AsLong
EndType
'--------------------------InternetCacheAPI
PrivateDeclareFunctionFindFirstUrlCacheEntryLib"Wininet.dll"Alias"FindFirstUrlCacheEntryA"(ByVallpszUrlSearchPatternAsString,lpFirstCacheEntryInfoAsAny,lpdwFirstCacheEntryInfoBufferSizeAsLong)AsLong
PrivateDeclareFunctionFindNextUrlCacheEntryLib"Wininet.dll"Alias"FindNextUrlCacheEntryA"(ByValhEnumHandleAsLong,lpNextCacheEntryInfoAsAny,lpdwNextCacheEntryInfoBufferSizeAsLong)AsLong
PrivateDeclareFunctionFindCloseUrlCacheLib"Wininet.dll"(ByValhEnumHandleAsLong)AsLong
PrivateDeclareFunctionDeleteUrlCacheEntryLib"Wininet.dll"Alias"DeleteUrlCacheEntryA"(ByVallpszUrlNameAsString)AsLong
'--------------------------MemoryAPI
PrivateDeclareFunctionLocalAllocLib"kernel32"(ByValuFlagsAsLong,ByValuBytesAsLong)AsLong
PrivateDeclareFunctionLocalFreeLib"kernel32"(ByValhMemAsLong)AsLong
PrivateDeclareSubCopyMemoryLib"kernel32"Alias"RtlMoveMemory"(pDestAsAny,pSourceAsAny,ByValdwLengthAsLong)
PrivateDeclareFunctionlstrcpyALib"kernel32"(ByValRetValAsString,ByValPtrAsLong)AsLong
PrivateDeclareFunctionlstrlenALib"kernel32"(ByValPtrAsAny)AsLong
'Purpose :
Deletesthespecifiedinternetcachefile
'Inputs :
sCacheFile Thenameofthecachefile
'Outputs :
ReturnsTrueonsuccess.
'Author :
AndrewBaker
'Date :
03/08/200019:
14
'Notes :
'Revisions :
FunctionInternetDeleteCache(sCacheFileAsString)AsBoolean
InternetDeleteCache=CBool(Delete