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. A site for mshtml interface

A site for mshtml interface

Scheduled Pinned Locked Moved C / C++ / MFC
13 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.
  • U Offline
    U Offline
    User 527726
    wrote on last edited by
    #1

    Can anybody tell me a site that explains mshtml interface(IHtmlTxtRange,IHtmlBodyElement). THanx lokesh

    A 1 Reply Last reply
    0
    • U User 527726

      Can anybody tell me a site that explains mshtml interface(IHtmlTxtRange,IHtmlBodyElement). THanx lokesh

      A Offline
      A Offline
      Andrew Quinn AUS
      wrote on last edited by
      #2

      First step should always be MSDN IHtmlTxtRange IHtmlBodyElement If you need help in using these from within C++ I'd be happy to help Hope this helps, Andy

      U 1 Reply Last reply
      0
      • A Andrew Quinn AUS

        First step should always be MSDN IHtmlTxtRange IHtmlBodyElement If you need help in using these from within C++ I'd be happy to help Hope this helps, Andy

        U Offline
        U Offline
        User 527726
        wrote on last edited by
        #3

        Thank you Andy, Iam virtually new to vc++ . I got a DHTMLED sample from msdn and wanted to set background sound using IHTMLBGsound and i tried but could't get it. lokesh

        A 1 Reply Last reply
        0
        • U User 527726

          Thank you Andy, Iam virtually new to vc++ . I got a DHTMLED sample from msdn and wanted to set background sound using IHTMLBGsound and i tried but could't get it. lokesh

          A Offline
          A Offline
          Andrew Quinn AUS
          wrote on last edited by
          #4

          Hi, Are the HTML pages yours (or public sites)? If they are yours then the easiest thing to do is the following: In your pages include the tag (with the src attr empty) and an ID, e.g.

          <html>
          ...
          <bgsound src='' id='idSound1'>
          ...
          </html>

          Then in your OnDocumentComplete event in VC++ you can run the following code:

          MSHTML::IHTMLDocument2Ptr spDoc(m\_ctlWeb1.GetDocument());
          if (spDoc)
          {
          	// Find the BGSOUND tag...
          	MSHTML::IHTMLDocument3Ptr spDoc3 = spDoc;
          	if (spDoc3)
          	{
          		// you could also use getElementByTagName but for simplicity...
          		MSHTML::IHTMLElementPtr spElem2 = spDoc3->getElementById(\_bstr\_t("idSound1"));
          		if (spElem2)
          		{
          			MSHTML::IHTMLBGsoundPtr spBG = spElem2;
          			if (spBG)
          			{
          				CString strURL = \_T("http://server/eg/alert.wav");
          				spBG->put\_src(\_bstr\_t(strURL));
          			}
          		}
          	}
          }
          

          If they are public sites and you are trying to inject a into them - this will be a little bit more work... Firstly, we need to get DOM to create us an element, and then insert it into the document. As before, we do this in the OnDocumentComplete event...

          MSHTML::IHTMLElementPtr spElem = spDoc->createElement(\_T("BGSOUND"));
          if (spElem)
          {
          	MSHTML::IHTMLBGsoundPtr spBG = spElem;
          	if (spBG)
          	{
          		CString strURL = \_T("http://server/eg/alert.wav");
          		spBG->put\_src((bstr\_t)strURL);
          
          		// get the DOMNode interface for the BODY...
          		MSHTML::IHTMLDOMNodePtr spBody = spDoc->body;
          		// get the DOMNode interface for the element we wish to add...
          		MSHTML::IHTMLDOMNodePtr spNode2Add = spBG;
          
          		if (spBody != NULL && spNode2Add != NULL)
          		{
          			// append new element to BODY
          			spBody->appendChild(spNode2Add);
          		}
          	}
          }
          

          And that's it :) Hope this helps, Andy

          U 1 Reply Last reply
          0
          • A Andrew Quinn AUS

            Hi, Are the HTML pages yours (or public sites)? If they are yours then the easiest thing to do is the following: In your pages include the tag (with the src attr empty) and an ID, e.g.

            <html>
            ...
            <bgsound src='' id='idSound1'>
            ...
            </html>

            Then in your OnDocumentComplete event in VC++ you can run the following code:

            MSHTML::IHTMLDocument2Ptr spDoc(m\_ctlWeb1.GetDocument());
            if (spDoc)
            {
            	// Find the BGSOUND tag...
            	MSHTML::IHTMLDocument3Ptr spDoc3 = spDoc;
            	if (spDoc3)
            	{
            		// you could also use getElementByTagName but for simplicity...
            		MSHTML::IHTMLElementPtr spElem2 = spDoc3->getElementById(\_bstr\_t("idSound1"));
            		if (spElem2)
            		{
            			MSHTML::IHTMLBGsoundPtr spBG = spElem2;
            			if (spBG)
            			{
            				CString strURL = \_T("http://server/eg/alert.wav");
            				spBG->put\_src(\_bstr\_t(strURL));
            			}
            		}
            	}
            }
            

            If they are public sites and you are trying to inject a into them - this will be a little bit more work... Firstly, we need to get DOM to create us an element, and then insert it into the document. As before, we do this in the OnDocumentComplete event...

            MSHTML::IHTMLElementPtr spElem = spDoc->createElement(\_T("BGSOUND"));
            if (spElem)
            {
            	MSHTML::IHTMLBGsoundPtr spBG = spElem;
            	if (spBG)
            	{
            		CString strURL = \_T("http://server/eg/alert.wav");
            		spBG->put\_src((bstr\_t)strURL);
            
            		// get the DOMNode interface for the BODY...
            		MSHTML::IHTMLDOMNodePtr spBody = spDoc->body;
            		// get the DOMNode interface for the element we wish to add...
            		MSHTML::IHTMLDOMNodePtr spNode2Add = spBG;
            
            		if (spBody != NULL && spNode2Add != NULL)
            		{
            			// append new element to BODY
            			spBody->appendChild(spNode2Add);
            		}
            	}
            }
            

            And that's it :) Hope this helps, Andy

            U Offline
            U Offline
            User 527726
            wrote on last edited by
            #5

            Thank you Andy,but My view is not derived from CHTMLView my view is derived from CView,IOleInPlaceFrame and IOleCommandTarget and iam using my own html pages.I think IHTMLBGsound is not supported in it ( I tried to paste it using pasteHTML). lokesh

            A 1 Reply Last reply
            0
            • U User 527726

              Thank you Andy,but My view is not derived from CHTMLView my view is derived from CView,IOleInPlaceFrame and IOleCommandTarget and iam using my own html pages.I think IHTMLBGsound is not supported in it ( I tried to paste it using pasteHTML). lokesh

              A Offline
              A Offline
              Andrew Quinn AUS
              wrote on last edited by
              #6

              Hi again, Neither was my test app. I created a test app and inserted the WebBrowser ActiveX Control into the dialog. Then used the Event sinking (through class wizard) to handle the DocumentComplete event, e.g.

              BEGIN_EVENTSINK_MAP(CWebTest1Dlg, CDialog)
              //{{AFX_EVENTSINK_MAP(CWebTest1Dlg)
              ON_EVENT(CWebTest1Dlg, IDC_EXPLORER1, 259 /* DocumentComplete */, OnDocumentCompleteExplorer1, VTS_DISPATCH VTS_PVARIANT)
              //}}AFX_EVENTSINK_MAP
              END_EVENTSINK_MAP()

              The BGSOUND element was available from IE3, and available in script from IE4 so I can't see that it's not supported. How are you using the Web Control in your app? Cheers, Andy

              U 2 Replies Last reply
              0
              • A Andrew Quinn AUS

                Hi again, Neither was my test app. I created a test app and inserted the WebBrowser ActiveX Control into the dialog. Then used the Event sinking (through class wizard) to handle the DocumentComplete event, e.g.

                BEGIN_EVENTSINK_MAP(CWebTest1Dlg, CDialog)
                //{{AFX_EVENTSINK_MAP(CWebTest1Dlg)
                ON_EVENT(CWebTest1Dlg, IDC_EXPLORER1, 259 /* DocumentComplete */, OnDocumentCompleteExplorer1, VTS_DISPATCH VTS_PVARIANT)
                //}}AFX_EVENTSINK_MAP
                END_EVENTSINK_MAP()

                The BGSOUND element was available from IE3, and available in script from IE4 so I can't see that it's not supported. How are you using the Web Control in your app? Cheers, Andy

                U Offline
                U Offline
                User 527726
                wrote on last edited by
                #7

                I got a DHTMLED sample from msdn (just enter DHTMLED in search).Run the exe and You will find a folder sample/Edit/. I want IhtmlBGsound implemented in it. Thank you for following it up. lokesh

                1 Reply Last reply
                0
                • A Andrew Quinn AUS

                  Hi again, Neither was my test app. I created a test app and inserted the WebBrowser ActiveX Control into the dialog. Then used the Event sinking (through class wizard) to handle the DocumentComplete event, e.g.

                  BEGIN_EVENTSINK_MAP(CWebTest1Dlg, CDialog)
                  //{{AFX_EVENTSINK_MAP(CWebTest1Dlg)
                  ON_EVENT(CWebTest1Dlg, IDC_EXPLORER1, 259 /* DocumentComplete */, OnDocumentCompleteExplorer1, VTS_DISPATCH VTS_PVARIANT)
                  //}}AFX_EVENTSINK_MAP
                  END_EVENTSINK_MAP()

                  The BGSOUND element was available from IE3, and available in script from IE4 so I can't see that it's not supported. How are you using the Web Control in your app? Cheers, Andy

                  U Offline
                  U Offline
                  User 527726
                  wrote on last edited by
                  #8

                  I got a DHTMLED sample from msdn (just enter DHTMLED in search in MSDN).Run the exe and You will find a folder sample/Edit/. I want IhtmlBGsound implemented in it. Thank you for following it up. lokesh

                  A 1 Reply Last reply
                  0
                  • U User 527726

                    I got a DHTMLED sample from msdn (just enter DHTMLED in search in MSDN).Run the exe and You will find a folder sample/Edit/. I want IhtmlBGsound implemented in it. Thank you for following it up. lokesh

                    A Offline
                    A Offline
                    Andrew Quinn AUS
                    wrote on last edited by
                    #9

                    Hi lokesh, I've had no luck finding this sample project. Do you have a link to it? I tried online MSDN as well as the MSDN Library Disks (Jan 2003) Cheers, Andy

                    U 1 Reply Last reply
                    0
                    • A Andrew Quinn AUS

                      Hi lokesh, I've had no luck finding this sample project. Do you have a link to it? I tried online MSDN as well as the MSDN Library Disks (Jan 2003) Cheers, Andy

                      U Offline
                      U Offline
                      User 527726
                      wrote on last edited by
                      #10

                      The site is . or just type "DHTMLED" in google and click the first one. lokesh

                      U A 2 Replies Last reply
                      0
                      • U User 527726

                        The site is . or just type "DHTMLED" in google and click the first one. lokesh

                        U Offline
                        U Offline
                        User 527726
                        wrote on last edited by
                        #11

                        http://msdn.microsoft.com/downloads/samples/internet/default.asp?url=/downloads/samples/internet/browser/editcntrl/default.asp lokesh

                        1 Reply Last reply
                        0
                        • U User 527726

                          The site is . or just type "DHTMLED" in google and click the first one. lokesh

                          A Offline
                          A Offline
                          Andrew Quinn AUS
                          wrote on last edited by
                          #12

                          Hi lokesh, Right I found the project you are on about. Just to clarify - it was the CEdit project was it not? Anyway I've had a look and have got it to insert the BGSOUND element. This project must have been written way way back and is a very verbose way of doing things. Anyway I digress. This is what I did: Firstly, we what to inject the element on the Document Complete event but because this is an old application we have to do it the old way. Events from the HTMLDOMDocument are handled by the CImpIDispatch class in DOCEVENT.cpp, we can tell this because in the crtview.cpp you see the following line:

                          hr = m_pConnectionPoint->Advise( m_pDocEvents, &m_dwConnectCookie );

                          So we are setting the object for the DOMDocument to call us back on. Then in the CImpIDispatch class, we need to look for the ::Invoke method, this is what will get called whenever any events take place - dispIdMember parameter will hold what event it actually is (see MSDN for all the events) The event we are interested in is: DISPID_HTMLDOCUMENTEVENTS_ONREADYSTATECHANGE readyState is a property of the document that tells you what the state of it is - we want to wait for it to be "complete" So here is the code I used in the ::Invoke method:

                          USES\_CONVERSION;
                          
                          if ( dispIdMember == DISPID\_HTMLDOCUMENTEVENTS\_ONREADYSTATECHANGE )
                          {
                          	MSHTML::IHTMLDocument2Ptr spDoc(m\_pView->m\_pSite->GetObjectUnknown());
                          	if (spDoc)
                          	{
                          		CString strState = OLE2T(spDoc->readyState);
                          		if (strState == \_T("complete"))
                          		{
                          			MSHTML::IHTMLElementPtr spElem = spDoc->createElement(\_T("BGSOUND"));
                          			if (spElem)
                          			{
                          				MSHTML::IHTMLBGsoundPtr spBG = spElem;
                          				if (spBG)
                          				{
                          					CString strURL = \_T("http://www.htmlcodetutorial.com/sounds/hazy\_shade\_of\_winter.mid");
                          					spBG->put\_src(T2OLE(strURL));
                          
                          					// get the BODY element
                          					MSHTML::IHTMLDOMNodePtr spBody = spDoc->body;
                          					// and the IHTMLDOMNode interface of the new element
                          					MSHTML::IHTMLDOMNodePtr spNode2Add = spBG;
                          					// append new element to BODY
                          					spBody->appendChild(spNode2Add);
                          				}
                          
                          			}
                          		}
                          	}
                          }
                          

                          Now you may notice that above I'm using the smart pointer implementation for COM calling - I did start doing in the traditional way but I got so bored with doing QueryInterface all the time. So add the following to the top of the cpp file:

                          #import "C:\Windows\system32\mshtml.tlb" no_auto_exclude

                          Actually there is another reason - the mshtml.h file that i

                          U 1 Reply Last reply
                          0
                          • A Andrew Quinn AUS

                            Hi lokesh, Right I found the project you are on about. Just to clarify - it was the CEdit project was it not? Anyway I've had a look and have got it to insert the BGSOUND element. This project must have been written way way back and is a very verbose way of doing things. Anyway I digress. This is what I did: Firstly, we what to inject the element on the Document Complete event but because this is an old application we have to do it the old way. Events from the HTMLDOMDocument are handled by the CImpIDispatch class in DOCEVENT.cpp, we can tell this because in the crtview.cpp you see the following line:

                            hr = m_pConnectionPoint->Advise( m_pDocEvents, &m_dwConnectCookie );

                            So we are setting the object for the DOMDocument to call us back on. Then in the CImpIDispatch class, we need to look for the ::Invoke method, this is what will get called whenever any events take place - dispIdMember parameter will hold what event it actually is (see MSDN for all the events) The event we are interested in is: DISPID_HTMLDOCUMENTEVENTS_ONREADYSTATECHANGE readyState is a property of the document that tells you what the state of it is - we want to wait for it to be "complete" So here is the code I used in the ::Invoke method:

                            USES\_CONVERSION;
                            
                            if ( dispIdMember == DISPID\_HTMLDOCUMENTEVENTS\_ONREADYSTATECHANGE )
                            {
                            	MSHTML::IHTMLDocument2Ptr spDoc(m\_pView->m\_pSite->GetObjectUnknown());
                            	if (spDoc)
                            	{
                            		CString strState = OLE2T(spDoc->readyState);
                            		if (strState == \_T("complete"))
                            		{
                            			MSHTML::IHTMLElementPtr spElem = spDoc->createElement(\_T("BGSOUND"));
                            			if (spElem)
                            			{
                            				MSHTML::IHTMLBGsoundPtr spBG = spElem;
                            				if (spBG)
                            				{
                            					CString strURL = \_T("http://www.htmlcodetutorial.com/sounds/hazy\_shade\_of\_winter.mid");
                            					spBG->put\_src(T2OLE(strURL));
                            
                            					// get the BODY element
                            					MSHTML::IHTMLDOMNodePtr spBody = spDoc->body;
                            					// and the IHTMLDOMNode interface of the new element
                            					MSHTML::IHTMLDOMNodePtr spNode2Add = spBG;
                            					// append new element to BODY
                            					spBody->appendChild(spNode2Add);
                            				}
                            
                            			}
                            		}
                            	}
                            }
                            

                            Now you may notice that above I'm using the smart pointer implementation for COM calling - I did start doing in the traditional way but I got so bored with doing QueryInterface all the time. So add the following to the top of the cpp file:

                            #import "C:\Windows\system32\mshtml.tlb" no_auto_exclude

                            Actually there is another reason - the mshtml.h file that i

                            U Offline
                            U Offline
                            User 527726
                            wrote on last edited by
                            #13

                            Super!Super! U GOT IT RIGHT MAN... ITS WORKING.... THANKYOU VERY MUCH. Iam just new to vc++ especially to com. I would be pleased if u guide me or teach me this thing from basics( Even some material would do).My email id is itslokeshk@yahoo.co.in and would be pleased to yours too. Thank you very much...once again. bye..:-D lokesh

                            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