Toon posts:

[VB.Net 2003] Webbrowser control

Pagina: 1
Acties:

Verwijderd

Topicstarter
Ik heb een probleem met een project waar ik mee bezig ben.
Ik heb een venster en daarin een webbrowser-control en een adresbalk (en nog een paar andere dingen die nu niet echt belangrijk zijn) Nu wil ik voorkomen dat nieuwe vensters in IE openen.

Dit kan in Windows XP SP2 gemakkelijk met het New_window3 event. Deze bestaat echter niet in oudere versies van Windows.

Nu vond ik de volgende code op de MS website:
Visual Basic:
1
2
3
4
5
6
7
8
9
10
Private Sub WebBrowser1_NewWindow2(ppDisp As Object,
                                   Cancel As Boolean)
   Dim frmWB As Form1
   Set frmWB = New Form1

   frmWB.WebBrowser1.RegisterAsBrowser = TRUE

   Set ppDisp = frmWB.WebBrowser1.Object
   frmWB.Visible = True
End Sub


Echter is deze code voor VB5 / 6 en werkt niet goed onder .Net (heeft niet het gewenste effect), weet iemand hoe ik dit kan doen :?

  • phYzar
  • Registratie: November 2001
  • Laatst online: 10:25
Hier staat een mooie uitleg over bovenstaand stukje code maar dan in C# / .NET :)

Verwijderd

Topicstarter
Inderdaad C#.net, het werkt allemaal wel. Alleen lukt het mij dus niet om dit correct te conventeren naar VB.Net |:( .. Kan iemand me daarbij helpen? Of weet iemand iets wat makkelijk is en wat in VB.Net werkt?
edit:

Ik hoef alleen te weten hoe de URL / het document, in het 2e venster geopend wordt?

[code=c#]
//Include the following interface declaration just before your application's namespace
//declaration to add a reference to the Microsoft HTML (MSHTML) IOleCommandTarget interface
[StructLayout(LayoutKind.Sequential,CharSet=CharSet.Unicode)]
public struct OLECMDTEXT
{
public uint cmdtextf;
public uint cwActual;
public uint cwBuf;
[MarshalAs(UnmanagedType.ByValTStr,SizeConst=100)]public char rgwz;
}

[StructLayout(LayoutKind.Sequential)]
public struct OLECMD
{
public uint cmdID;
public uint cmdf;
}

// Interop definition for IOleCommandTarget.
[ComImport,
Guid("b722bccb-4e68-101b-a2bc-00aa00404770"),
InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
public interface IOleCommandTarget
{
//IMPORTANT: The order of the methods is critical here. You
//perform early binding in most cases, so the order of the methods
//here MUST match the order of their vtable layout (which is determined
//by their layout in IDL). The interop calls key off the vtable ordering,
//not the symbolic names. Therefore, if you switched these method declarations
//and tried to call the Exec method on an IOleCommandTarget interface from your
//application, it would translate into a call to the QueryStatus method instead.
void QueryStatus(ref Guid pguidCmdGroup, UInt32 cCmds,
[MarshalAs(UnmanagedType.LPArray, SizeParamIndex=1)] OLECMD[] prgCmds, ref OLECMDTEXT CmdText);
void Exec(ref Guid pguidCmdGroup, uint nCmdId, uint nCmdExecOpt, ref object pvaIn, ref object pvaOut);
}
[/code]

die code dus..

[ Voor 80% gewijzigd door Verwijderd op 08-02-2005 19:30 ]


Verwijderd

Topicstarter
Visual Basic .NET:
1
2
3
4
5
6
Private Sub wb_NewWindow2(ByVal sender As Object, ByVal e As AxSHDocVw.DWebBrowserEvents2_NewWindow2Event) Handles wb.NewWindow2
        Dim frUnite As New FrmUnite
        frUnite.wb.RegisterAsBrowser = True
        e.ppDisp = frUnite.wb.Application
        frUnite.Show()
End Sub

Dat is de oplossing die ik zelf gevonden heb :D
Hier kun je de uitwerking downloaden

[ Voor 11% gewijzigd door Verwijderd op 22-10-2005 09:13 ]


  • whoami
  • Registratie: December 2000
  • Laatst online: 09-05 01:02
C# moet je makkelijk kunnen omzetten naar VB.NET; gewoon een kwestie van een andere syntax, en that's all

https://fgheysels.github.io/