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. ATL & DHTML

ATL & DHTML

Scheduled Pinned Locked Moved C / C++ / MFC
c++htmlhelp
6 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.
  • L Offline
    L Offline
    Leesen
    wrote on last edited by
    #1

    I write an ATL control to implement the onunload event of the html. I set the onunload handle through IHTMLBodyElement. But it did not work. Source code as follow: //definition of IDHTMLTest2 in IDL interface IDHTMLTest2 : IDispatch { [id(1), helpstring("method ShowMsg")] HRESULT ShowMsg(); }; //selection of the source code CComPtrspIE; m_spClientSite->GetContainer(&spIE); CComQIPtrspDoc(spIE); if (spDoc){ CComPtr spElement; spDoc->get_body(&spElement); CComQIPtr spBody(spElement); IDispatch* pShowMsg; QueryInterface(IID_IDHTMLTest2,(void**)&pShowMsg); VARIANT v; v.vt=VT_DISPATCH; v.pdispVal=pShowMsg; //this event can't be invoke ,when close the ie-window spBody->put_onunload(v); //this invoke works well ((IDHTMLTest2*)pShowMsg)->ShowMsg(); //code below can works well // v.vt=VT_BSTR; // v.bstrVal = L"#DA70D6"; // spBody->put_bgColor(v); } Thank you for your advanced help. Regards.

    P 1 Reply Last reply
    0
    • L Leesen

      I write an ATL control to implement the onunload event of the html. I set the onunload handle through IHTMLBodyElement. But it did not work. Source code as follow: //definition of IDHTMLTest2 in IDL interface IDHTMLTest2 : IDispatch { [id(1), helpstring("method ShowMsg")] HRESULT ShowMsg(); }; //selection of the source code CComPtrspIE; m_spClientSite->GetContainer(&spIE); CComQIPtrspDoc(spIE); if (spDoc){ CComPtr spElement; spDoc->get_body(&spElement); CComQIPtr spBody(spElement); IDispatch* pShowMsg; QueryInterface(IID_IDHTMLTest2,(void**)&pShowMsg); VARIANT v; v.vt=VT_DISPATCH; v.pdispVal=pShowMsg; //this event can't be invoke ,when close the ie-window spBody->put_onunload(v); //this invoke works well ((IDHTMLTest2*)pShowMsg)->ShowMsg(); //code below can works well // v.vt=VT_BSTR; // v.bstrVal = L"#DA70D6"; // spBody->put_bgColor(v); } Thank you for your advanced help. Regards.

      P Offline
      P Offline
      Peter Molnar
      wrote on last edited by
      #2

      If I were to decide, this code should work. Some remarks: 1.Shouldn't you write

      CComQIPtr<IID_IHTMLBodyElement> spBody(spElement); //CComQIPtr spBody(spElement);

      Otherwise how does QI know wich interface to query for? Same with spDoc. 2.I would reccomend you to use smart dispatch pointer: IDispatchPtr. This way you don't have the trouble with QI and releasing it. 3.Since

      spBody->put_bgColor(v); //and
      ((IDHTMLTest2*)pShowMsg)->ShowMsg();

      seem to work, the problem should be with "v" or put_onunload. Maybe 2. will solve the issue? Eventuelly you could try a CComVariant on "v". 4.What if setting with spElement's setAttribute onunload=ExitFunction, additionally inserting the ExitFunction with an alert? Peter Molnar

      L 1 Reply Last reply
      0
      • P Peter Molnar

        If I were to decide, this code should work. Some remarks: 1.Shouldn't you write

        CComQIPtr<IID_IHTMLBodyElement> spBody(spElement); //CComQIPtr spBody(spElement);

        Otherwise how does QI know wich interface to query for? Same with spDoc. 2.I would reccomend you to use smart dispatch pointer: IDispatchPtr. This way you don't have the trouble with QI and releasing it. 3.Since

        spBody->put_bgColor(v); //and
        ((IDHTMLTest2*)pShowMsg)->ShowMsg();

        seem to work, the problem should be with "v" or put_onunload. Maybe 2. will solve the issue? Eventuelly you could try a CComVariant on "v". 4.What if setting with spElement's setAttribute onunload=ExitFunction, additionally inserting the ExitFunction with an alert? Peter Molnar

        L Offline
        L Offline
        Leesen
        wrote on last edited by
        #3

        I have tried by your advice. But it sitll not work. And I set the default method. [id(0), helpstring("method Prompt")] HRESULT ShowMsg(); The DHTML will invoke the default method with DISPID=0; It still not work. Have you any source code which can run smoothly .Could you send me for reference ? Thank You. Email: fengrux@hotmail.com

        P 1 Reply Last reply
        0
        • L Leesen

          I have tried by your advice. But it sitll not work. And I set the default method. [id(0), helpstring("method Prompt")] HRESULT ShowMsg(); The DHTML will invoke the default method with DISPID=0; It still not work. Have you any source code which can run smoothly .Could you send me for reference ? Thank You. Email: fengrux@hotmail.com

          P Offline
          P Offline
          Peter Molnar
          wrote on last edited by
          #4

          The last resort I see is to implement 4./ For this you will have to insert another attribute into the body tag with the name onunload. you have two choices:

          <body onunload="alert('This is my onunload message!')">

          or

          <script language=javascript>
          function ExitFunction()
          {
          alert('This my ExitFunction message');
          }
          </script>
          <body onunload=ExitFunction()>

          Your code:

          spElement->setAttribute(CComBSTR("onunload"),CComVariant("\"alert('This is my onunload message!')\""),0);

          or

          spElement->insertAdjacentHTML(CComBSTR("beforeBegin"),CComBSTR("...the entire script tag..."));
          spElement->setAttribute(CComBSTR("onunload"),CComVariant("ExitFunction()"),0);

          Peter Molnar

          L 1 Reply Last reply
          0
          • P Peter Molnar

            The last resort I see is to implement 4./ For this you will have to insert another attribute into the body tag with the name onunload. you have two choices:

            <body onunload="alert('This is my onunload message!')">

            or

            <script language=javascript>
            function ExitFunction()
            {
            alert('This my ExitFunction message');
            }
            </script>
            <body onunload=ExitFunction()>

            Your code:

            spElement->setAttribute(CComBSTR("onunload"),CComVariant("\"alert('This is my onunload message!')\""),0);

            or

            spElement->insertAdjacentHTML(CComBSTR("beforeBegin"),CComBSTR("...the entire script tag..."));
            spElement->setAttribute(CComBSTR("onunload"),CComVariant("ExitFunction()"),0);

            Peter Molnar

            L Offline
            L Offline
            Leesen
            wrote on last edited by
            #5

            You mean insert code in the HTML ?? My intention is to fire the Event in the ActiveX control . Thus , web designer without konwing about the Activex can simply using "" tag to deploy the ActiveX.

            P 1 Reply Last reply
            0
            • L Leesen

              You mean insert code in the HTML ?? My intention is to fire the Event in the ActiveX control . Thus , web designer without konwing about the Activex can simply using "" tag to deploy the ActiveX.

              P Offline
              P Offline
              Peter Molnar
              wrote on last edited by
              #6

              Yes, you should definitly insert code into the HTML. Of course this is not the HTML the user of your ActiveX creates but the HTML your ActiveX "perceives" of the user's HTML code or "thinks" the user wrote. All this has the aim to fire the onunload event. You know: the aim justifies the means... Peter Molnar

              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