- 日時: 2007/09/12 14:00
- 名前: 花ちゃん
- ***********************************************************************************
* カテゴリー:[インターネット][][] * * キーワード:サイズ,HTML,プロティ,,, * ***********************************************************************************
元質問:WebBrowserで表示中のHTMLのプロパティ - こくらうまれ 2006/03/23-11:34 No.3415
WebBrowserでHTMLを表示し、右クリックー>プロパテイで表示される「サイズ」情報を 取得したいのですが、方法はないでしょうか?
----------------------------------------------------------------------------------- Re: WebBrowserで表示中のHTMLの.. - 魔界の仮面弁士 2006/03/23-16:09 No.3421 ----------------------------------------------------------------------------------- > 全体のサイズを求めるプロパティの記述がわかるといいのですが。 Option Strict Off / エラー処理なしの手抜きサンプル。
Private Sub AxWebBrowser1_DocumentComplete(ByVal sender As Object, _ ByVal e As AxSHDocVw.DWebBrowserEvents2_DocumentCompleteEvent _ ) Handles AxWebBrowser1.DocumentComplete Dim Doc As Object = e.pDisp.Document Dim PF As System.Runtime.InteropServices.UCOMIPersistFile Dim FileName As String = "C:\A.HTML" PF = Doc PF.Save(FileName, False) System.Runtime.InteropServices.Marshal.ReleaseComObject(Doc) Dim Message As String Message = CStr(e.uRL) & vbCrLf & CStr(FileLen(FileName)) System.IO.File.Delete(FileName) MessageBox.Show(Message) End Sub
============================================================================= ついでに、一時ファイルを使わないサンプル。 Option Strict Off Imports System.Runtime.InteropServices を宣言して、ADOを参照設定しておいてください。
<ComImport(), Guid("0000010c-0000-0000-C000-000000000046"), _ InterfaceType(ComInterfaceType.InterfaceIsIUnknown)> _ Interface UCOMIPersist Sub GetClassID(ByRef pClassId As Guid) End Interface
<ComImport(), Guid("7FD52380-4E07-101B-AE2D-08002B2EC713"), _ InterfaceType(ComInterfaceType.InterfaceIsIUnknown)> _ Interface UCOMIPersistStreamInit Inherits UCOMIPersist Shadows Sub GetClassID(<Out()> ByRef pClassId As Guid) <PreserveSig()> Function IsDirty() As <MarshalAs(UnmanagedType.U4)> Boolean Sub Load(<[In]()> ByVal pStm As UCOMIStream) Sub Save(<[In]()> ByVal pStm As UCOMIStream, _ <[In](), MarshalAs(UnmanagedType.Bool)> ByVal fClearDirty As Boolean) Sub GetMaxSize(<Out(), MarshalAs(UnmanagedType.LPArray)> ByRef pCbSize As Long) Sub InitNew() End Interface
Private Sub AxWebBrowser1_DocumentComplete(ByVal sender As Object, _ ByVal e As AxSHDocVw.DWebBrowserEvents2_DocumentCompleteEvent _ ) Handles AxWebBrowser1.DocumentComplete Dim ADOStream As New ADODB.StreamClass ADOStream.Open() ADOStream.Type = ADODB.StreamTypeEnum.adTypeBinary Dim UnmanagedStream As UCOMIPersistStreamInit UnmanagedStream = DirectCast(AxWebBrowser1.Document, UCOMIPersistStreamInit) UnmanagedStream.Save(ADOStream, False) System.Runtime.InteropServices.Marshal.ReleaseComObject(UnmanagedStream) Dim Message As String = CStr(e.uRL) & vbCrLf & CStr(ADOStream.Size) System.Runtime.InteropServices.Marshal.ReleaseComObject(ADOStream) MessageBox.Show(Message) End Sub
=============================================================================
さらについでに、.NET 2.0 の System.Windows.Forms.WebBrowser の場合。
Private Sub WebBrowser1_DocumentCompleted(ByVal sender As Object, _ ByVal e As WebBrowserDocumentCompletedEventArgs _ ) Handles WebBrowser1.DocumentCompleted
Dim Message As String = e.Url.ToString() & vbCrLf Message &= CStr(WebBrowser1.DocumentStream.Length)
MessageBox.Show(Message)
End Sub
COM 版に比べると、非常にシンプルに書けますね。(^^;
|