Click here to Skip to main content
15,916,378 members
Home / Discussions / Web Development
   

Web Development

 
Generalhtml / possible Java script question. Pin
ztner14-Jul-04 9:10
ztner14-Jul-04 9:10 
GeneralRe: html / possible Java script question. Pin
Javier Lozano18-Jul-04 17:15
Javier Lozano18-Jul-04 17:15 
GeneralExcecute commandline Pin
pork chop14-Jul-04 5:26
pork chop14-Jul-04 5:26 
GeneralError message Cannot update database or object read only Pin
Mekong River13-Jul-04 3:26
Mekong River13-Jul-04 3:26 
GeneralDHTML and MFC Pin
CodeBrain13-Jul-04 0:43
CodeBrain13-Jul-04 0:43 
GeneralRe: DHTML and MFC Pin
Andrew Quinn AUS13-Jul-04 22:26
Andrew Quinn AUS13-Jul-04 22:26 
GeneralRe: DHTML and MFC Pin
CodeBrain14-Jul-04 4:08
CodeBrain14-Jul-04 4:08 
GeneralRe: DHTML and MFC Pin
Andrew Quinn AUS14-Jul-04 5:22
Andrew Quinn AUS14-Jul-04 5:22 
Hi,

Yes indeed IHTMLDocumentPtr is the starting point into the DOM.

One thing that will help in the long run is to import the HTML type library - thus getting Visual Studio to generate wrappers around the numerous interfaces and methods. It wraps using smart pointers - so no QueryInterface/Releases to take care of.

e.g. insert the following into either your header/implementation file
#import "C:\Windows\system32\mshtml.tlb" no_auto_exclude


This will generate two files, mshtml.tlh and mshtml.tli, in your project directory. The first is a header file, the next the implementation. With this done, here is a simple DHTML process from within MFC to get an element from the page...

void CWebDlg::OnDocumentCompleteExplorer1(LPDISPATCH pDisp, VARIANT FAR* URL) 
{
	USES_CONVERSION;

	MSHTML::IHTMLDocument2Ptr spDoc(m_ctlWeb1.GetDocument()); // This is the WebBrowser control
	if (spDoc)
	{
		MSHTML::IHTMLDocument3Ptr spDoc3 = spDoc;
		if (spDoc3)
		{
			MSHTML::IHTMLElementPtr spElem2 = spDoc3->getElementById(_bstr_t("idSpan1"));
			if (spElem2)
			{
				CString strText = W2T(spElem2->innerText);
				spElem2->innerText = _bstr_t("Hello There");
			}
		}

	}
}


See how we can easily get the different interfaces of the object. The wrapper is doing the QI under the covers when we do a simple assignment. Plus the smart pointer will release that reference once the object goes out of scope.

You can also easily create elements at will, e.g. here we create a BGSOUND element and append it to the DOM document.
MSHTML::IHTMLDocument2Ptr spDoc(m_ctlWeb1.GetDocument());
if (spDoc)
{
	MSHTML::IHTMLElementPtr spElem = spDoc->createElement(_T("BGSOUND"));
	if (spElem)
	{
		MSHTML::IHTMLBGsoundPtr spBG = spElem;
		if (spBG)
		{
			CString strURL = _T("http://xyzxyz/snd/newalert.wav");
			spBG->put_src((bstr_t)strURL);

			MSHTML::IHTMLDOMNodePtr spBody = spDoc->body;
			MSHTML::IHTMLDOMNodePtr spNode2Add = spBG;

			// append new element to BODY
			spBody->appendChild(spNode2Add);
		}
	}
}


To answer your question about inserting an image - I not too sure, something at the back of my mind does ring a bell about embedding IMG data in an HTML page. I'll see if I can find out. But for now I would think about saving the image to the file-system and then referencing the IMG src tag to the location.

If you have any questions about DHTML or using MFC to generate DHTML I'll be happy to answer them.

Hope this helps,
Andy
GeneralRe: DHTML and MFC Pin
CodeBrain15-Jul-04 4:00
CodeBrain15-Jul-04 4:00 
GeneralRe: DHTML and MFC Pin
Andrew Quinn AUS15-Jul-04 4:25
Andrew Quinn AUS15-Jul-04 4:25 
GeneralRe: DHTML and MFC Pin
CodeBrain15-Jul-04 7:15
CodeBrain15-Jul-04 7:15 
Generaljava/tomcat 5.0 Pin
zedic12-Jul-04 23:40
zedic12-Jul-04 23:40 
Generalcrystal reports problem Pin
Member 120813911-Jul-04 22:27
Member 120813911-Jul-04 22:27 
GeneralE-mail address around the world Pin
Mekong River10-Jul-04 6:34
Mekong River10-Jul-04 6:34 
GeneralRe: E-mail address around the world Pin
Colin Angus Mackay - Guarding his email address10-Jul-04 6:58
sussColin Angus Mackay - Guarding his email address10-Jul-04 6:58 
GeneralRe: E-mail address around the world Pin
Mekong River10-Jul-04 23:32
Mekong River10-Jul-04 23:32 
GeneralRe: E-mail address around the world Pin
Colin Angus Mackay - Not quite convinced14-Jul-04 20:39
sussColin Angus Mackay - Not quite convinced14-Jul-04 20:39 
GeneralRe: E-mail address around the world Pin
Mekong River17-Jul-04 4:14
Mekong River17-Jul-04 4:14 
GeneralRe: E-mail address around the world Pin
alex.barylski10-Jul-04 17:24
alex.barylski10-Jul-04 17:24 
GeneralRe: E-mail address around the world Pin
betoalvo8-Aug-04 4:47
betoalvo8-Aug-04 4:47 
GeneralNo Horizontal bar in html Pin
Anonymous9-Jul-04 7:25
Anonymous9-Jul-04 7:25 
GeneralRe: No Horizontal bar in html Pin
palbano9-Jul-04 7:42
palbano9-Jul-04 7:42 
GeneralSending Mail through HTML Pin
Anonymous9-Jul-04 7:04
Anonymous9-Jul-04 7:04 
GeneralRe: Sending Mail through HTML Pin
palbano9-Jul-04 7:41
palbano9-Jul-04 7:41 
GeneralRe: Sending Mail through HTML Pin
Scit12-Jul-04 21:51
Scit12-Jul-04 21:51 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.