Highlighted
Absent Member.
Absent Member.
553 views

[archive] IE Control / pDisp

[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
0 Likes
8 Replies
Highlighted
Absent Member.
Absent Member.

RE: [archive] IE Control / pDisp

It appears to me, when I look at the definition of the WebBrowser object, that you should tell what frame you want to use. E.g. the second parameter to Navigate. This of course depends that you know the name of the frame... Which you do, as this is the 4th parameter of the event.

Hence, change the geteventdata to:

CALL "C$GETEVENTDATA" USING EVENT-CONTROL-HANDLE,
               PDISP-HANDLE, WS-NEW-URL, dummy, WS-FRAME-NAME ...

Then change the navigate call to:

MODIFY PDISP-HANDLE @Navigate("[URL]http://google.com[/URL]", WS-FRAME-NAME)


Mind you, I haven't tried this, just guessing.
0 Likes
Highlighted
Absent Member.
Absent Member.

RE: [archive] IE Control / pDisp

Gisle,

Over the past few weeks as I've researched this, I thought the method you suggested would work as well, but I've learned it does not. Or at least I couldn't make it work. I think the TargetFrameName is only populated when there is actually target parameter on an html tag (such as ). In the cases that I'm dealing with framenames and target parameters are not being used. They could be iframes in the middle of a page or some other container like that. From what I could determine after my research, the best way to accomplish this is via the pDisp parameter.

Rob
0 Likes
Highlighted
Absent Member.
Absent Member.

RE: [archive] IE Control / pDisp

I thought this was a bit odd, so I had to test it :).

First, a few issues to address:

When inspecting the return values, I noticed that if I set the url to "http://yahoo.com", what was returned in event info url was "http:///" ...

Hence, the if test would fail. Changing the url to "http://www.yahoo.com", and the event info url was, just that, http://www.yahoo.com

Second, when dealing with COM, "if" tests like this:

if ws-new-url = "http://www.yahoo.com" won't work, because there might be low values suffixing the string, so you should use modify by reference:

if ws-new-url(1:20) = http://www.yahoo.com

Or you can use the INSPECT verb to search for substrings.

Now, that we got the if test working, the rest was fine. As a matter of fact, for me it worked either I used the PDISP-HANDLE or the browser id from the screen section.

Hope this helps

       IDENTIFICATION               DIVISION.
       PROGRAM-ID.                  TEMPLATE.
       ENVIRONMENT                  DIVISION.
       CONFIGURATION                SECTION.
       SPECIAL-NAMES.
           copy "ieframe.def".
           .
       WORKING-STORAGE SECTION.
       77  CNTL-FONT                USAGE HANDLE OF FONT SMALL-FONT.
       77  KEY-STATUS               IS SPECIAL-NAMES
           CRT STATUS               PIC 9(4) VALUE 0.
           88  EXIT-PRESSED         VALUE 27.
       01  EVENT-STATUS
           IS SPECIAL-NAMES EVENT STATUS.
           03  EVENT-TYPE           PIC X(4) COMP-X.
           03  EVENT-WINDOW-HANDLE  HANDLE OF WINDOW.
           03  EVENT-CONTROL-HANDLE HANDLE.
           03  EVENT-CONTROL-ID     PIC XX COMP-X.
           03  EVENT-DATA-1         SIGNED-SHORT.
           03  EVENT-DATA-2         SIGNED-LONG.
           03  EVENT-ACTION         PIC X COMP-X.
       01  PDISP-HANDLE             HANDLE OF @WEBBROWSER.
       78  MSG-AX-EVENT             VALUE 16436.
       77  WS-NEW-URL               PIC X(1024) VALUE
                                    "[URL]http://www.yahoo.com[/URL]".
       SCREEN      SECTION.
       01  TEMPLATE-SCREEN.
           03 url-entry ENTRY-FIELD
              LINE                  02
              COL                   02
              SIZE                  40
              USING                 WS-NEW-URL.
           03 PUSH-BUTTON
              LINE                  02
              COL                   44
              TITLE                 "Action"
              EVENT PROCEDURE       Do-Navigate.
           03 hBrowser              WebBrowser
              LINE                  04
              COL                   02
              SIZE                  77
              LINES                 34
              EVENT PROCEDURE       Redirect-Navigation.
           03      PUSH-BUTTON
                   LINE             39
                   COL              63
                   SIZE             14
                   TITLE            "E&xit"
                   SELF-ACT
                   EXCEPTION-VALUE  = 27.
       PROCEDURE DIVISION.
       MAIN-LOGIC.
           DISPLAY STANDARD         GRAPHICAL WINDOW
                   TITLE            "Template"
                   CONTROL          FONT CNTL-FONT
                   SIZE             80
                   LINES            40
                   BACKGROUND-LOW.
    PERFORM INITIALIZE-DATA.
           DISPLAY TEMPLATE-SCREEN.
           PERFORM WITH TEST AFTER  UNTIL EXIT-PRESSED
                   ACCEPT           TEMPLATE-SCREEN
           END-PERFORM.
           DESTROY TEMPLATE-SCREEN.
           STOP    RUN.
       INITIALIZE-DATA.
           INITIALIZE               KEY-STATUS.
           EXIT    PARAGRAPH.
       Redirect-Navigation.
           IF      EVENT-TYPE       = MSG-AX-EVENT
           AND     EVENT-DATA-2     = WebBrowserBeforeNavigate2
                   CALL "C$GETEVENTDATA" USING
                        EVENT-CONTROL-HANDLE
                        PDISP-HANDLE
                        WS-NEW-URL
                   IF   WS-NEW-URL(1:20)  = "[URL]http://www.yahoo.com[/URL]"
                        MOVE "[URL]http://www.google.com[/URL]" TO WS-NEW-URL
                        MODIFY PDISP-HANDLE Navigate(WS-NEW-URL)
                        DISPLAY URL-ENTRY
                   END-IF
           END-IF
           EXIT    PARAGRAPH.
       Do-Navigate.
           MODIFY  hBrowser         Navigate(WS-NEW-URL)
           EXIT    PARAGRAPH.
0 Likes
Highlighted
Absent Member.
Absent Member.

RE: [archive] IE Control / pDisp

Thanks for your help, Gisle. This works fine for me! However, when I tried to implement it into my application, it still fails. I spent the afternoon stripping down our program to where it was basically the same as yours and still had an issue. I finally found that it wouldn't work if "DISPLAY URL-ENTRY" wasn't in the Redirect-Navigation event procedure. Very strange... I attempted to do the same thing in my application and it still failed. But, I was hoping perhaps you could explain why the DISPLAY statement needs to be there?

Thanks,
Rob
0 Likes
Highlighted
Absent Member.
Absent Member.

RE: [archive] IE Control / pDisp

Without having looked at it, I think it might be because the IO with the interface (DISPLAY that is) will process messages for the ActiveX component. For the purpose of performance, when there is no interface IO we do by default not process messages during standard verb processing.
You may be familiar with this if you know of and possibly use the FILE-IO-PROCESS-MESSAGES config variable.
0 Likes
Highlighted
Absent Member.
Absent Member.

RE: [archive] IE Control / pDisp

Gisle,

If it were as simple as you say, then wouldn't the DISPLAY work in my application? Do you have any idea why this would be. Also, I tried to display other labels, entry fields, etc. and still couldn't make it work. The only way I could make it work was to DISPLAY URL-ENTRY from within the event procedure for the IE control (Redirect-Navigation). Thanks for your help.

Rob
0 Likes
Highlighted
Absent Member.
Absent Member.

RE: [archive] IE Control / pDisp

I could certainly find out, but doing that would be beyond the purpose of this forum. As the saying goes; "If it works, don't fix it" 🙂
0 Likes
Highlighted
Absent Member.
Absent Member.

RE: [archive] IE Control / pDisp

With the help of Acucorp, I was able to determine why this wasn't working. The pDisp handle needed to be defined as IWebBrowser instead of WebBrowser. Not sure if anyone really needs to know this, but since we solved the problem, I wanted to share it on the board.
0 Likes
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.