Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Using IWebBrowser2 and Navigate. Need help! Thanks!

Using IWebBrowser2 and Navigate. Need help! Thanks!

Scheduled Pinned Locked Moved C / C++ / MFC
tutorialc++help
15 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D David Crow

    univega_r304 wrote:

    Write now I call Browser.Navigate(myURL,NULL,NULL,NULL,NULL); to open a site. The 2nd NULL is supposed to be for the target name.

    So have you tried "_SELF" as the second parameter?


    "Money talks. When my money starts to talk, I get a bill to shut it up." - Frank

    "Judge not by the eye but by the heart." - Native American Proverb

    P Offline
    P Offline
    Paul Groetzner
    wrote on last edited by
    #3

    If it were only that easy... That's the very first thing I did... Here's what I got: error C2664: 'CExplorer::Navigate' : cannot convert parameter 3 from 'const char [6]' to 'VARIANT *'

    D 1 Reply Last reply
    0
    • P Paul Groetzner

      If it were only that easy... That's the very first thing I did... Here's what I got: error C2664: 'CExplorer::Navigate' : cannot convert parameter 3 from 'const char [6]' to 'VARIANT *'

      D Offline
      D Offline
      David Crow
      wrote on last edited by
      #4

      How about:

      VARIANT vTarget;
      vTarget.vt = VT_BYREF|VT_I1;
      vTarget.pcVal = ("_SELF");
      m_ctrlBrowser.Navigate(..., &vTarget, ...);


      "Money talks. When my money starts to talk, I get a bill to shut it up." - Frank

      "Judge not by the eye but by the heart." - Native American Proverb

      P 1 Reply Last reply
      0
      • D David Crow

        How about:

        VARIANT vTarget;
        vTarget.vt = VT_BYREF|VT_I1;
        vTarget.pcVal = ("_SELF");
        m_ctrlBrowser.Navigate(..., &vTarget, ...);


        "Money talks. When my money starts to talk, I get a bill to shut it up." - Frank

        "Judge not by the eye but by the heart." - Native American Proverb

        P Offline
        P Offline
        Paul Groetzner
        wrote on last edited by
        #5

        Ok, that compiled. However my original problem still exists. When I navigate to the page and click a link within, it still opens a new IE window. Something tells me I have to intercept it with NewWindow2(), but when I tried setting up that event, nothing happened. I do have OnNavigateComplete and OnBeforeNavigate2 working, but when I tried adding OnNewWindow2 to the list of events, nothing happens when it spawns a new window. Any other suggestions?? Much appreciated!

        D 1 Reply Last reply
        0
        • P Paul Groetzner

          Ok, that compiled. However my original problem still exists. When I navigate to the page and click a link within, it still opens a new IE window. Something tells me I have to intercept it with NewWindow2(), but when I tried setting up that event, nothing happened. I do have OnNavigateComplete and OnBeforeNavigate2 working, but when I tried adding OnNewWindow2 to the list of events, nothing happens when it spawns a new window. Any other suggestions?? Much appreciated!

          D Offline
          D Offline
          David Crow
          wrote on last edited by
          #6

          univega_r304 wrote:

          Something tells me I have to intercept it with NewWindow2(), but when I tried setting up that event, nothing happened.

          I got notified with:

          BEGIN_EVENTSINK_MAP(CMyDlg, CDialog)
          //{{AFX_EVENTSINK_MAP(CMyDlg)
          ON_EVENT(CMyDlg, IDC_EXPLORER, 251 /* NewWindow2 */, OnNewWindow, VTS_DISPATCH VTS_PBOOL)
          //}}AFX_EVENTSINK_MAP
          END_EVENTSINK_MAP()

          void CMyDlg::OnNewWindow(LPDISPATCH pDisp, BOOL FAR* URL)
          {
          TRACE("New window opening\n");
          }


          "Money talks. When my money starts to talk, I get a bill to shut it up." - Frank

          "Judge not by the eye but by the heart." - Native American Proverb

          P 1 Reply Last reply
          0
          • D David Crow

            univega_r304 wrote:

            Something tells me I have to intercept it with NewWindow2(), but when I tried setting up that event, nothing happened.

            I got notified with:

            BEGIN_EVENTSINK_MAP(CMyDlg, CDialog)
            //{{AFX_EVENTSINK_MAP(CMyDlg)
            ON_EVENT(CMyDlg, IDC_EXPLORER, 251 /* NewWindow2 */, OnNewWindow, VTS_DISPATCH VTS_PBOOL)
            //}}AFX_EVENTSINK_MAP
            END_EVENTSINK_MAP()

            void CMyDlg::OnNewWindow(LPDISPATCH pDisp, BOOL FAR* URL)
            {
            TRACE("New window opening\n");
            }


            "Money talks. When my money starts to talk, I get a bill to shut it up." - Frank

            "Judge not by the eye but by the heart." - Native American Proverb

            P Offline
            P Offline
            Paul Groetzner
            wrote on last edited by
            #7

            OK, I got that to work too... When I originally tried the event I used the number 254 vs 251 like you have. Being new to this, is there any documentation that shows how you came up with that number. Anyhow, so now I added a line to your code: void CMyDlg::OnNewWindow(LPDISPATCH pDisp, BOOL FAR* URL) { TRACE("New window no longer opening\n"); *URL = TRUE; } (that should probably have been named CANCEL but I stuck with what you had) That no longer spawns a new IE window, but it's also preventing it from opening up at all *sigh*. Now if I can only get the link to target my window I'll be set...

            D 1 Reply Last reply
            0
            • P Paul Groetzner

              OK, I got that to work too... When I originally tried the event I used the number 254 vs 251 like you have. Being new to this, is there any documentation that shows how you came up with that number. Anyhow, so now I added a line to your code: void CMyDlg::OnNewWindow(LPDISPATCH pDisp, BOOL FAR* URL) { TRACE("New window no longer opening\n"); *URL = TRUE; } (that should probably have been named CANCEL but I stuck with what you had) That no longer spawns a new IE window, but it's also preventing it from opening up at all *sigh*. Now if I can only get the link to target my window I'll be set...

              D Offline
              D Offline
              David Crow
              wrote on last edited by
              #8

              univega_r304 wrote:

              ...is there any documentation that shows how you came up with that number.

              Look in afxhtml.h.

              univega_r304 wrote:

              (that should probably have been named CANCEL but I stuck with what you had)

              The old copy-and-paste bug is to blame!


              "Money talks. When my money starts to talk, I get a bill to shut it up." - Frank

              "Judge not by the eye but by the heart." - Native American Proverb

              P 1 Reply Last reply
              0
              • D David Crow

                univega_r304 wrote:

                ...is there any documentation that shows how you came up with that number.

                Look in afxhtml.h.

                univega_r304 wrote:

                (that should probably have been named CANCEL but I stuck with what you had)

                The old copy-and-paste bug is to blame!


                "Money talks. When my money starts to talk, I get a bill to shut it up." - Frank

                "Judge not by the eye but by the heart." - Native American Proverb

                P Offline
                P Offline
                Paul Groetzner
                wrote on last edited by
                #9

                Thanks :D Just one more step and I'm done! Obviously now that I can cancel it from spawning a new window, I need to still be able to open it within the same window. get_locationURL isn't going to work obviously since it can't establish the new URL yet. Do you know how to extract the URL from the link you click on so I can call it in a new Navigate() command?

                D 1 Reply Last reply
                0
                • P Paul Groetzner

                  Thanks :D Just one more step and I'm done! Obviously now that I can cancel it from spawning a new window, I need to still be able to open it within the same window. get_locationURL isn't going to work obviously since it can't establish the new URL yet. Do you know how to extract the URL from the link you click on so I can call it in a new Navigate() command?

                  D Offline
                  D Offline
                  David Crow
                  wrote on last edited by
                  #10

                  univega_r304 wrote:

                  Do you know how to extract the URL from the link you click on...

                  Wouldn't that be the BeforeNavigate2 event?


                  "Money talks. When my money starts to talk, I get a bill to shut it up." - Frank

                  "Judge not by the eye but by the heart." - Native American Proverb

                  P 1 Reply Last reply
                  0
                  • D David Crow

                    univega_r304 wrote:

                    Do you know how to extract the URL from the link you click on...

                    Wouldn't that be the BeforeNavigate2 event?


                    "Money talks. When my money starts to talk, I get a bill to shut it up." - Frank

                    "Judge not by the eye but by the heart." - Native American Proverb

                    P Offline
                    P Offline
                    Paul Groetzner
                    wrote on last edited by
                    #11

                    If it is, I'm not able to get the URL the link is pointing to. It's probably something that would still be handled by NewWindow... My guess is there's a few more parameters available, one of which would contain the URL to the link. Then I could simply navigate to it after the *Cancel = TRUE; command is processed. I've been looking at KB Article Q185538 which is basically ideal for this situation, but the sample is in VB. I'm sure it must be related somehow but I haven't got it to work yet.

                    D 1 Reply Last reply
                    0
                    • P Paul Groetzner

                      If it is, I'm not able to get the URL the link is pointing to. It's probably something that would still be handled by NewWindow... My guess is there's a few more parameters available, one of which would contain the URL to the link. Then I could simply navigate to it after the *Cancel = TRUE; command is processed. I've been looking at KB Article Q185538 which is basically ideal for this situation, but the sample is in VB. I'm sure it must be related somehow but I haven't got it to work yet.

                      D Offline
                      D Offline
                      David Crow
                      wrote on last edited by
                      #12

                      univega_r304 wrote:

                      If it is, I'm not able to get the URL the link is pointing to. It's probably something that would still be handled by NewWindow... My guess is there's a few more parameters available, one of which would contain the URL to the link.

                      Do you have:

                      BEGIN_EVENTSINK_MAP(CMyDlg, CDialog)
                      //{{AFX_EVENTSINK_MAP(CBrianDlg)
                      ON_EVENT(CMyDlg, IDC_EXPLORER, 250 /* BeforeNavigate2 */, OnBeforeNavigate,
                      VTS_DISPATCH VTS_PVARIANT VTS_PVARIANT VTS_PVARIANT VTS_PVARIANT VTS_PVARIANT VTS_PBOOL)
                      //}}AFX_EVENTSINK_MAP
                      END_EVENTSINK_MAP()

                      void CMyDlg::OnBeforeNavigate(LPDISPATCH pDisp, VARIANT *URL, VARIANT *Flags, VARIANT *Target,
                      VARIANT *PostData, VARIANT *Headers, BOOL *Cancel )
                      {
                      ASSERT(V_VT(URL) == VT_BSTR);
                      TRACE("Before navigating to %S\n", V_BSTR(URL));
                      }


                      "Money talks. When my money starts to talk, I get a bill to shut it up." - Frank

                      "Judge not by the eye but by the heart." - Native American Proverb

                      P 2 Replies Last reply
                      0
                      • D David Crow

                        univega_r304 wrote:

                        If it is, I'm not able to get the URL the link is pointing to. It's probably something that would still be handled by NewWindow... My guess is there's a few more parameters available, one of which would contain the URL to the link.

                        Do you have:

                        BEGIN_EVENTSINK_MAP(CMyDlg, CDialog)
                        //{{AFX_EVENTSINK_MAP(CBrianDlg)
                        ON_EVENT(CMyDlg, IDC_EXPLORER, 250 /* BeforeNavigate2 */, OnBeforeNavigate,
                        VTS_DISPATCH VTS_PVARIANT VTS_PVARIANT VTS_PVARIANT VTS_PVARIANT VTS_PVARIANT VTS_PBOOL)
                        //}}AFX_EVENTSINK_MAP
                        END_EVENTSINK_MAP()

                        void CMyDlg::OnBeforeNavigate(LPDISPATCH pDisp, VARIANT *URL, VARIANT *Flags, VARIANT *Target,
                        VARIANT *PostData, VARIANT *Headers, BOOL *Cancel )
                        {
                        ASSERT(V_VT(URL) == VT_BSTR);
                        TRACE("Before navigating to %S\n", V_BSTR(URL));
                        }


                        "Money talks. When my money starts to talk, I get a bill to shut it up." - Frank

                        "Judge not by the eye but by the heart." - Native American Proverb

                        P Offline
                        P Offline
                        Paul Groetzner
                        wrote on last edited by
                        #13

                        If I put *Cancel = TRUE; in NewWindow to prevent it spawning a new window then BeforeNavigate never gets called. It works for anything that doesn't spawn, however. Any other ideas? I can't imagine why something like this would be so difficult. It'd make a useful article if we can get it working....

                        D 1 Reply Last reply
                        0
                        • D David Crow

                          univega_r304 wrote:

                          If it is, I'm not able to get the URL the link is pointing to. It's probably something that would still be handled by NewWindow... My guess is there's a few more parameters available, one of which would contain the URL to the link.

                          Do you have:

                          BEGIN_EVENTSINK_MAP(CMyDlg, CDialog)
                          //{{AFX_EVENTSINK_MAP(CBrianDlg)
                          ON_EVENT(CMyDlg, IDC_EXPLORER, 250 /* BeforeNavigate2 */, OnBeforeNavigate,
                          VTS_DISPATCH VTS_PVARIANT VTS_PVARIANT VTS_PVARIANT VTS_PVARIANT VTS_PVARIANT VTS_PBOOL)
                          //}}AFX_EVENTSINK_MAP
                          END_EVENTSINK_MAP()

                          void CMyDlg::OnBeforeNavigate(LPDISPATCH pDisp, VARIANT *URL, VARIANT *Flags, VARIANT *Target,
                          VARIANT *PostData, VARIANT *Headers, BOOL *Cancel )
                          {
                          ASSERT(V_VT(URL) == VT_BSTR);
                          TRACE("Before navigating to %S\n", V_BSTR(URL));
                          }


                          "Money talks. When my money starts to talk, I get a bill to shut it up." - Frank

                          "Judge not by the eye but by the heart." - Native American Proverb

                          P Offline
                          P Offline
                          Paul Groetzner
                          wrote on last edited by
                          #14

                          Take a look at http://msdn.microsoft.com/workshop/browser/webbrowser/reference/ifaces/dwebbrowserevents2/newwindow3.asp NewWindow3 may be the better way to go?

                          1 Reply Last reply
                          0
                          • P Paul Groetzner

                            If I put *Cancel = TRUE; in NewWindow to prevent it spawning a new window then BeforeNavigate never gets called. It works for anything that doesn't spawn, however. Any other ideas? I can't imagine why something like this would be so difficult. It'd make a useful article if we can get it working....

                            D Offline
                            D Offline
                            David Crow
                            wrote on last edited by
                            #15

                            univega_r304 wrote:

                            If I put *Cancel = TRUE; in NewWindow to prevent it spawning a new window then BeforeNavigate never gets called. It works for anything that doesn't spawn, however.

                            I would think that would be the case (i.e., BeforeNavigate() getting called) no matter what NewWindow() did to Cancel since BeforeNavigate() would not know about the new window.


                            "Money talks. When my money starts to talk, I get a bill to shut it up." - Frank

                            "Judge not by the eye but by the heart." - Native American Proverb

                            1 Reply Last reply
                            0
                            Reply
                            • Reply as topic
                            Log in to reply
                            • Oldest to Newest
                            • Newest to Oldest
                            • Most Votes


                            • Login

                            • Don't have an account? Register

                            • Login or register to search.
                            • First post
                              Last post
                            0
                            • Categories
                            • Recent
                            • Tags
                            • Popular
                            • World
                            • Users
                            • Groups