Webbrowser Control - Handling pop-ups

Hello there everyone.

I've been dabbling with the WebBrowser control in VB6 and I am trying to control the popups.

Below is the code that handles the NewWindow2 event (the event that is triggered before a new window is opened via javascript or other means):

Private Sub WebBrowser1_NewWindow2(ppDisp As Object, Cancel As Boolean)
Dim Window1 As New CESSubWindower

Window1.WebBrowser1.RegisterAsBrowser = True
Set ppDisp = Window1.WebBrowser1.Object
Window1.Show
End Sub

This works fine as a start to keep the popups from opening in a new Internet Explorer browser and in my own browser, however I am having trouble with resizing both the form and the WebBrowser control to the correct size (it doesn't seem to automatically resize the WebBrowser control of the SubWindow form correctly, but it does resize it).

I have tried a few things with handling the WindowSetHeight and WindowSetWidth events, to no avail. I might be having an issue with scaling, but I've tried Pixel to Twips conversion of the Height and Width parameters of those two events, and got slightly closer, but still I am not reflecting the correct size.

Any ideas of things I can try?

[1222 byte] By [tigreye007] at [2007-12-16]
# 1

How about...
dim sz as new size(450,450) '//or whatever size (x,y) you want.
window1.size=sz
with window1
webbrowser1.top=0
webbrowser1.left=0
webbrowser1.width=window1.width
webbrowser1.height=window1.height
end with
Please let me know if it works to your satisfaction.

bud1024 at 2007-9-9 > top of Msdn Tech,Visual Basic,Visual Basic General...
# 2

The problem with that is that this does not reflect the size specified by the javascript window.open() call.

My code is now the following:

Private Sub Form_Resize()
WebBrowser1.Top = 0
WebBrowser1.Left = 0
WebBrowser1.Height = Me.Height - 100
WebBrowser1.Width = Me.Width - 100
End Sub

Private Sub WebBrowser1_NavigateComplete2(ByVal pDisp As Object, URL As Variant)
WebBrowser1.Left = 0
WebBrowser1.Top = 0
Form_Resize
End Sub

Private Sub WebBrowser1_WindowClosing(ByVal IsChildWindow As Boolean, Cancel As Boolean)
Unload Me
End Sub

Private Sub WebBrowser1_WindowSetHeight(ByVal Height As Long)
'Height parameter in Pixels
Me.Height = Height * Screen.TwipsPerPixelY + 470
Form_Resize
End Sub

Private Sub WebBrowser1_WindowSetWidth(ByVal Width As Long)
Me.Width = Width * Screen.TwipsPerPixelX + 180
Form_Resize
End Sub
I am handling the WindowSetHeight and WindowSetWidth events (which are triggered with the values set in the window.open()). Since the Height and Width parameters in these two event handlers are in pixels, I convert to twips and set the form height and width to the twips conversion PLUS some arbitrary number that I played with until it matched the IE popup size.

Doing that wasn't enough since for some reason the height and width of the actual WebBrowser control were being set in code outside of mine, so I had to add an event handler to the NavigateComplete2 event, so when it is all done processing, my form is the right size, but I have to resize the WebBrowser (again) to fit in the Form. This seems to work great, but I'm wondering why I need to add 180 and 470 for the width and height, respectively, to accurately match the size I want to portray. It just doesn't make any sense to me.

tigreye007 at 2007-9-9 > top of Msdn Tech,Visual Basic,Visual Basic General...