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
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. web browser control difficulty

web browser control difficulty

Scheduled Pinned Locked Moved C / C++ / MFC
c++questioncomhelptutorial
6 Posts 3 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 Offline
    D Offline
    doug25
    wrote on last edited by
    #1

    Hello, I'm trying to display a web page inside my own window. I found a c++ example by chris becke on the net which is huge. I ported the code into my application but I can only get the web page to display when I run the project in visual c++. Is there a more bare bone example that displays a web page inside a window ? or why does my program only work when I run it from visual c++ ? I'm not of a great state of intelligence to understand all the com code needed to display a web page but with a little help I think I might understand.. thanks,

    C K D 3 Replies Last reply
    0
    • D doug25

      Hello, I'm trying to display a web page inside my own window. I found a c++ example by chris becke on the net which is huge. I ported the code into my application but I can only get the web page to display when I run the project in visual c++. Is there a more bare bone example that displays a web page inside a window ? or why does my program only work when I run it from visual c++ ? I'm not of a great state of intelligence to understand all the com code needed to display a web page but with a little help I think I might understand.. thanks,

      C Offline
      C Offline
      CPallini
      wrote on last edited by
      #2

      If you are using MFC then you may have a look at "Using MFC to Host a WebBrowser Control"[^] at MSDN.

      If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
      This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
      [My articles]

      D 1 Reply Last reply
      0
      • D doug25

        Hello, I'm trying to display a web page inside my own window. I found a c++ example by chris becke on the net which is huge. I ported the code into my application but I can only get the web page to display when I run the project in visual c++. Is there a more bare bone example that displays a web page inside a window ? or why does my program only work when I run it from visual c++ ? I'm not of a great state of intelligence to understand all the com code needed to display a web page but with a little help I think I might understand.. thanks,

        K Offline
        K Offline
        krmed
        wrote on last edited by
        #3

        When you run an application from inside Visual Studio, the working directory is the directory containing the project files (.vcxproj, .sln). However when you run outside of VS, the working directory is the one containing the .exe file. So if you are opening an html file with just a file name (e.g. open "MyTest.html") then that file must exist in the working directory. You should use full path names to avoid this problem. (You can use GetModuleFileName to find out the directory containing your exe). Hope that helps.

        Karl - WK5M PP-ASEL-IA (N43CS) PGP Key: 0xDB02E193 PGP Key Fingerprint: 8F06 5A2E 2735 892B 821C 871A 0411 94EA DB02 E193

        D 1 Reply Last reply
        0
        • C CPallini

          If you are using MFC then you may have a look at "Using MFC to Host a WebBrowser Control"[^] at MSDN.

          If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
          This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
          [My articles]

          D Offline
          D Offline
          doug25
          wrote on last edited by
          #4

          Thanks, but i'm not using MFC

          1 Reply Last reply
          0
          • K krmed

            When you run an application from inside Visual Studio, the working directory is the directory containing the project files (.vcxproj, .sln). However when you run outside of VS, the working directory is the one containing the .exe file. So if you are opening an html file with just a file name (e.g. open "MyTest.html") then that file must exist in the working directory. You should use full path names to avoid this problem. (You can use GetModuleFileName to find out the directory containing your exe). Hope that helps.

            Karl - WK5M PP-ASEL-IA (N43CS) PGP Key: 0xDB02E193 PGP Key Fingerprint: 8F06 5A2E 2735 892B 821C 871A 0411 94EA DB02 E193

            D Offline
            D Offline
            doug25
            wrote on last edited by
            #5

            I understand this, I have been using the full path and file name. I need to convert the string to a BSTR, I'm assuming i'm doing it correctly because as I say, the program works but only shows a web page when I run it from visual studio. here's how:

            char url[MAX_PATH];
            // _getcwd(url, MAX_PATH);
            GetModuleFileName(InstanceHandle, url, MAX_PATH);
            std::string file = url;
            file = file.substr(0, file.find_last_of("\\"));
            file += "\\Help.html";
            //file = "Help.html";

            // show that the path is correct
            MessageBox(NULL, file.c_str(), NULL, NULL);

            OLECHAR* oleChar = NULL;
            oleChar = (OLECHAR*)calloc(file.length(), sizeof(OLECHAR));
            MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, file.c_str(), -1, oleChar, sizeof(WCHAR)*file.length());

            vURL.bstrVal = SysAllocString(oleChar);

            1 Reply Last reply
            0
            • D doug25

              Hello, I'm trying to display a web page inside my own window. I found a c++ example by chris becke on the net which is huge. I ported the code into my application but I can only get the web page to display when I run the project in visual c++. Is there a more bare bone example that displays a web page inside a window ? or why does my program only work when I run it from visual c++ ? I'm not of a great state of intelligence to understand all the com code needed to display a web page but with a little help I think I might understand.. thanks,

              D Offline
              D Offline
              doug25
              wrote on last edited by
              #6

              I've got the program to work :)! after some modifications. still not sure what the problem was but I think it had something to do with structure declarations I'd placed in a header file..

              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