[Migrated content. Thread originally posted on 02 February 2009]
I am trying to write a COBOL program that uses the IE browser control and intercepts certain navigations and "redirects" them to another. On the surface, this sounds really simple, but I also want to make sure that the navigations occur in the proper frame, etc.I have been able to make this work in a simple VB program, but have been unsuccessful in getting it to work in AcuCobol (version 8.1). Hopefully someone can help!
To accomplish this, I'm using the IE browser control as an ActiveX control (Acucorp's browser control doesn't give me enough of what I need). At the BeforeNavigate2 event, I am capturing pDisp, which is an IDispatch type. This is the frame or window that is doing the navigation. Then, I want to cancel the navigation and instead perform my own navigation. But instead of using the main WebBrowser control, I want to use the pDisp so it will be done in the proper frame.
Here's some VB code that does this:
Private Sub WebBrowser1_BeforeNavigate2(ByVal pDisp As Object, URL As Variant, Flags As Variant, TargetFrameName As Variant, PostData As Variant, Headers As Variant, Cancel As Boolean)
If URL = "http://yahoo.com" Then
Cancel = True
pDisp.Navigate "http://google.com"
End If
End Sub
Here is the COBOL code that I'm trying to use as an equivalent:
The "def" file shows:
EVENT, 250, @WebBrowserBeforeNavigate2
* 7 Parameters
* "IDispatch* pDisp"
* "VARIANT* URL"
* "VARIANT* Flags"
* "VARIANT* TargetFrameName"
* "VARIANT* PostData"
* "VARIANT* Headers"
* "boolean* Cancel"
My pDisp variable is defined as:
01 PDISP-HANDLE HANDLE OF @WEBBROWSER VALUE NULL.
And my event procedure code is:
EVALUATE EVENT-TYPE
WHEN MSG-AX-EVENT
EVALUATE EVENT-DATA-2
WHEN WebBrowserBeforeNavigate2
CALL "C$GETEVENTDATA" USING EVENT-CONTROL-HANDLE,
PDISP-HANDLE, WS-NEW-URL
IF WS-NEW-URL = "http://yahoo.com"
CALL "C$SETEVENTDATA" USING EVENT-CONTROL-HANDLE,
0,0,0,0,0,0,1
MODIFY PDISP-HANDLE @Navigate("http://google.com")
END-IF
END-EVALUATE
END-EVALUATE.
I was wondering if I needed to specify "AS VT-DISPATCH" in some way, but couldn't get it to complie or if my PDISP-HANLDE wasn't defined correctly? I'm not getting any errors and a pDisp value is getting set via the event procedure. It just doesn't navigate to anything. Navigating using the Web Browser main handle works fine, but it navigates using the entire browser instead of the frame that it is in.Thanks in advance for any help!
Rob



