CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7
  1. #1
    Join Date
    Aug 2011
    Posts
    6

    Component WebBrowser or script on form

    Hello, I very need to start script on aplication form, but I can do it only if my script is location in anower file (for example, i set up url=C:\script.html). I want to place this script in my program and when send to it (to script) some digits, how i can do it?
    P.S. Sory for my english

  2. #2
    Join Date
    Aug 2011
    Posts
    6

    Re: Component WebBrowser or script on form

    I watched the example in msdn, it good work, but for my html I have some errors, maby visual studio fink about html code as c++ code, this is my sorce:


    public ref class Form1 : public System::Windows::Forms::Form
    {
    public:
    Form1(void)
    {
    InitializeComponent();
    //
    //TODO: Add the constructor code here
    //
    this->webBrowser2->DocumentText="<!DOCTYPE html>"+
    "<html>"+
    "<head>"+
    "<meta name="viewport" content="initial-scale=1.0, user-scalable=no"/>"+
    "<style type="text/css">"+
    "html { height: 100% }"+
    "body { height: 100%; margin: 0; padding: 0 }"+
    "#map_canvas { height: 100% }"+
    "</style>"+
    "<script type="text/javascript""+
    "src="http://maps.googleapis.com/maps/api/js?sensor=true">"+
    "</script>"+
    "<script type="text/javascript">"+
    "function initialize() {"+
    "var latlng = new google.maps.LatLng(-34.397, 150.644);"+
    "var myOptions = {"+
    "zoom: 8,"+
    "center: latlng,"+
    "mapTypeId: google.maps.MapTypeId.ROADMAP"+
    "};"+
    "var map = new google.maps.Map(document.getElementById("map_canvas"),myOptions);"+
    "}"+
    "</script>"+
    "</head>"+
    "<body onload="initialize()">"+
    "<div id="map_canvas" style="width:100%; height:100%"></div>"+
    "</body>"+
    "</html>";
    }

  3. #3
    Join Date
    Sep 2004
    Location
    Holland (land of the dope)
    Posts
    4,123

    Re: Component WebBrowser or script on form

    You are using managed code, not C++. Try posting your question here.

  4. #4
    Join Date
    Jun 2010
    Location
    Germany
    Posts
    2,675

    Re: Component WebBrowser or script on form

    Aside from Skizmo's point who is right about you having posted that in the wrong forum section, actually your problem here happens to be common to both managed and unmanaged C++.

    Of course a string literal that starts with a double quote (") ends for the compiler as soon as it sees the next double quote. If you want double quotes as part of a string literal (and you have lots of them here) you need to escape them by preceding them with a backslash (\).

    Also, but that's not part of the reason for the errors you get, I'd recommend to remove the + sign at the end of each line of your HTML code literal. With that sign, the compiler stores each line of the HTML snippet as a single string literal and your program will later need to add them together to a single string by making callls to methods of the String class. And it would need to do that each time that piece of code is executed which is inefficient. Without the + sign, the compiler would store the entire HTML code as a single string literal that then would simply get assigned in a single step.

    Last but not least, I'd recommend to add the sequence /r/n to the end of each literal line of HTML code. This would add a standard Windows line ending to the lines. Without it, the HTML code would end up being a single long line. It doesn't matter with regard to the validity of the HTML code, but it may be quite helpful when viewing the code later, e.g. when debugging.

    After applying these three changes, your code would look like this:

    Code:
    this->webBrowser2->DocumentText="<!DOCTYPE html>\r\n"
    "<html>\r\n"
    "<head>\r\n"
    "<meta name=\"viewport\" content=\"initial-scale=1.0, user-scalable=no\"/>\r\n"
    "<style type=\"text/css\">\r\n"
    "html { height: 100&#37; }\r\n"
    "body { height: 100%; margin: 0; padding: 0 }\r\n"
    "#map_canvas { height: 100% }\r\n"
    "</style>\r\n"
    "<script type=\"text/javascript\"\r\n"
    "src=\"http://maps.googleapis.com/maps/api/js?sensor=true\">\r\n" 
    "</script>\r\n"
    "<script type=\"text/javascript\">\r\n"
    "function initialize() {\r\n"
    "var latlng = new google.maps.LatLng(-34.397, 150.644);\r\n"
    "var myOptions = {\r\n"
    "zoom: 8,\r\n"
    "center: latlng,\r\n"
    "mapTypeId: google.maps.MapTypeId.ROADMAP\r\n"
    "};\r\n"
    "var map = new google.maps.Map(document.getElementById(\"map_canvas\"),myOptions);\r\n"
    "}\r\n"
    "</script>\r\n"
    "</head>\r\n"
    "<body onload=\"initialize()\">\r\n"
    "<div id=\"map_canvas\" style=\"width:100%; height:100%\"></div>\r\n"
    "</body>\r\n"
    "</html>";
    Give it a try and let's see whether it takes you further.

    Please use code tags when posting code.

    Ah, and... Welcome to CodeGuru!
    I was thrown out of college for cheating on the metaphysics exam; I looked into the soul of the boy sitting next to me.

    This is a snakeskin jacket! And for me it's a symbol of my individuality, and my belief... in personal freedom.

  5. #5
    Join Date
    Aug 2011
    Posts
    6

    Resolved Re: Component WebBrowser or script on form

    Thanks, its really work! I as also haven't assumed that that in such code is necessary backslash

  6. #6
    Join Date
    Aug 2011
    Posts
    6

    Re: Component WebBrowser or script on form

    Probably my questions on this component haven't ended, now I need to pull out variables from my script though, yesterday I thought that only in this script I will send data, that I do now successfully. The variant with a clipboard hasn't approached me, as I can copy only one variable, and it is necessary to me a little, tried to dodge with document title (there a script to enter all that is necessary, and then to receive studio), but it too doesn't approach, because the browser obediently to deduce all in the form, yes it is wrong so. certainly, I can change my script. In general, again I ask your council
    Last edited by BigED; August 29th, 2011 at 12:11 PM.

  7. #7
    Join Date
    Jun 2010
    Location
    Germany
    Posts
    2,675

    Re: Component WebBrowser or script on form

    Skizmo has already given you the link to where to post further questions about C++/CLI, yet this seems to be more of a JavaScript question. I'd say the bet place (at least on GodeGuru) to ask about that is the Client Side Scripting section.
    I was thrown out of college for cheating on the metaphysics exam; I looked into the soul of the boy sitting next to me.

    This is a snakeskin jacket! And for me it's a symbol of my individuality, and my belief... in personal freedom.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured