Internet options ...

mentalhard

Well-known member
Joined
Aug 7, 2006
Messages
123
Programming Experience
Beginner
Internet options ... [RESOLVED]

VB.NET:
Imports System
Imports System.Runtime.InteropServices
Public Class Form1
    <StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Unicode)> _
        Public Structure OLECMDTEXT
        Public cmdtextf As UInteger
        Public cwActual As UInteger
        Public cwBuf As UInteger
        <MarshalAs(UnmanagedType.ByValTStr, SizeConst:=100)> _
        Public rgwz As Char
    End Structure

    <StructLayout(LayoutKind.Sequential)> _
    Public Structure OLECMD
        Public cmdID As UInteger
        Public cmdf As UInteger
    End Structure


    <ComImport(), Guid("b722bccb-4e68-101b-a2bc-00aa00404770"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown)> _
    Public Interface IOleCommandTarget
        Sub QueryStatus(ByRef pguidCmdGroup As Guid, ByVal cCmds As UInt32, <MarshalAs(UnmanagedType.LPArray, SizeParamIndex:=1)> _
        ByVal prgCmds As OLECMD(), ByRef CmdText As OLECMDTEXT)
        Sub Exec(ByRef pguidCmdGroup As Guid, ByVal nCmdId As UInteger, ByVal nCmdExecOpt As UInteger, ByRef pvaIn As Object, ByRef pvaOut As Object)
    End Interface



    Private cmdGuid As New Guid("ED016940-BD5B-11CF-BA4E-00C04FD70816")
    Private Enum MiscCommandTarget
        Find = 1
        ViewSource = 2
        Options = 3
    End Enum

    Private Function GetDocument() As mshtml.HTMLDocument
        Try
            Dim htm As mshtml.HTMLDocument = DirectCast(WebBrowser1.Document, mshtml.HTMLDocument)
            Return htm
        Catch
            Throw (New Exception("Cannot retrieve document from WebBrowser Control"))
        End Try
    End Function

    Public Sub WebBrowserInternetOptions()
        Dim cmdt As IOleCommandTarget
        Dim o As New Object()
        Try
            cmdt = DirectCast(GetDocument(), IOleCommandTarget)
            cmdt.Exec(cmdGuid, CInt(MiscCommandTarget.Options), CInt(SHDocVw.OLECMDEXECOPT.OLECMDEXECOPT_DODEFAULT), o, o)
        Catch
        End Try
    End Sub


    Private _ActiveWebBrowser As SHDocVw.WebBrowser
    Private Sub ExecCommandID(ByVal _OLECMDID As SHDocVw.OLECMDID)
        Dim response As Integer = CInt(_ActiveWebBrowser.QueryStatusWB(_OLECMDID))
        Dim IsOK As Boolean = IIf((response And CInt(SHDocVw.OLECMDF.OLECMDF_ENABLED)) <> 0, True, False)
        If IsOK = False Then
            Return
        End If
        Dim o As Object = Nothing
        _ActiveWebBrowser.ExecWB(_OLECMDID, SHDocVw.OLECMDEXECOPT.OLECMDEXECOPT_DODEFAULT, o, o)
    End Sub

'the code that i guess should appear the options window but from some reason it doesn't
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        WebBrowserInternetOptions()
    End Sub
End Class

I want to invoke Internet options dialog for the WebBrowser object which is embedded in the WinForm (VB.NET 2005).

I followed this article http://support.microsoft.com/kb/329014 which is in C# so it must ne that i have not converted something as needed.

Also i took the code sample from this article http://www.codeproject.com/csharp/multitabwebbrowser.asp?df=100&forumid=145092&exp=0&select=1318255 and also it seems to works just fine.

Thanks :)

EDIT: if there is already working VB.NET sample i am very interested to check that. Link, advice whatever is welcome.
 
Last edited:
Why not this simple?
VB.NET:
Public Sub ShowInternetOptions()
        Shell("rundll32.exe shell32.dll,Control_RunDLL inetcpl.cpl,,0", vbNormalFocus)
End Sub

Thanks for reading :D
 
Back
Top