The author's words: Use the DHTMLEDIT control to display HTML in the application to a simple but not very effective way, which can be used for browser programming. This dialog uses the DHTMledit control included with IE5.
Header file // {{AFX_INCLUDES () # include "dhtmledit / dhtmledit.h" //}} AFX_INCLUDES # if! Defined (AFX_PARAMDLG_H__0655C0B1_BEAD_4F17_AAAC_506C1D07D073__INCLUDED _) # define AFX_PARAMDLG_H__0655C0B1_BEAD_4F17_AAAC_506C1D07D073__INCLUDED_ #if _MSC_VER> 1000 # pragma once # endif // _MSC_VER> 1000 // ParamDlg.h: header file // class CHtmlparam: public CObject {public: CString m_strAlt; COleVariant m_varVal;}; # define HTML_TAG_INPUT _T ( "INPUT") # define HTML_TAG_SELECT _T ( "SELECT") # define HTML_ATTRIB_NAME _T ( "NAME" ) #define HTML_ATTRIB_VALUE _T ( "VALUE") # define HTML_ATTRIB_CHECKED _T ( "checked") # define HTML_ATTRIB_TYPE _T ( "TYPE") # define HTML_ATTRIB_ALT _T ( "ALT") # define HTML_TYPE_CHECKBOX _T ( "checkbox") /// CParamDlg dialogCString HTMLElement_GetValueAttributeName (CHTMLElement * pel); CString HTMLElement_GetToolTipAttributeName (CHTMLElement * pel); CString HTMLElement_GetIDOrName (CHTMLElement * pel); BOOL HTMLElement_IsInputElement (CHTMLElement * pel); BOOL HTMLElement_IsInputCheckBoxElement (CHTM LElement * pel); class CParamDlg: public CDialog {// Constructionpublic: CParamDlg (CWnd * pParent = NULL); // standard constructor ~ CParamDlg (); // Dialog Data // {{AFX_DATA (CParamDlg) enum {IDD = IDD_PARAM_DLG }; CDHTMLEdit m_wndDhtmlEdit; //}} AFX_DATA CString m_strFilePath; CString m_strFileURL; COleVariant GetValue (CString strName); void GetValue (CString strName, int & iVal); void GetValue (CString strName, long & lVal); void GetValue (CString strName, CString & Strval); void setValue (CSTRING STRNAME, COLEVARIANT VARVAL, LPCTSTR LPSZALT = NULL);
// displayed as tooltip void SetValue (CString strName, int iVal, LPCTSTR lpszAlt = NULL); // displayed as tooltip void SetValueBool (CString strName, BOOL bVal, LPCTSTR lpszAlt = NULL); // displayed as tooltip // Overrides // ClassWizard generated virtual function overrides // {{AFX_VIRTUAL (CParamDlg) protected: virtual void DoDataExchange (CDataExchange * pDX); // DDX / DDV support //}} AFX_VIRTUAL // Implementationprotected: CMapStringToOb m_mapNameToParam; BOOL LoadValues (); BOOL SaveValues ( ); // Generated message map functions // {{aFX_MSG (CParamDlg) virtual BOOL OnInitDialog (); afx_msg void OnDocumentCompleteDhtmledit1 (); virtual void OnOK (); DECLARE_EVENTSINK_MAP () //}} aFX_MSG DECLARE_MESSAGE_MAP ()}; // { {AFX_INSERT_LOCATION}} // Microsoft Visual C Will Insert Additional Declarations Immediate Line. #ENDIF / / /! Defined (AFX_PARAMDLG_H__0655C0B1_BEAD_4F17_AAAC_506C 1D07D073__INCLUDED_) implementation file // ParamDlg.cpp: implementation file // #include "stdafx.h" #include
m_mapNameToParam.RemoveAll ();} CParamDlg :: ~ CParamDlg () {POSITION pos = m_mapNameToParam.GetStartPosition (); CString strKey; CObject * pOb; while (pos) {m_mapNameToParam.GetNextAssoc (pos, strKey, pOb); delete pOb; }} void CParamDlg :: DoDataExchange (CDataExchange * pDX) {CDialog :: DoDataExchange (pDX); // {{AFX_DATA_MAP (CParamDlg) DDX_Control (pDX, IDC_DHTMLEDIT1, m_wndDhtmlEdit); //}} AFX_DATA_MAP} BEGIN_MESSAGE_MAP (CParamDlg, CDialog) // {{AFX_MSG_MAP (CParamDlg) //}} AFX_MSG_MAPEND_MESSAGE_MAP () /// CParamDlg message handlers BOOL CParamDlg :: OnInitDialog () {CDialog :: OnInitDialog (); // TODO: Add extra initialization here COleVariant varFile, varPrompt; varPrompt .vt = VT_BOOL; varPrompt.boolVal = FALSE; if (m_strFileURL.IsEmpty ()!) varFile = m_strFileURL; else varFile = m_strFilePath; TRY {m_wndDhtmlEdit.LoadDocument (& varFile, & varPrompt);} CATCH (COleDispatchException, pEx) {CGlobal: : Processoled ispatchException (pEx); return FALSE;} AND_CATCH (CException, pEx) {CGlobal :: ProcessException (pEx); return FALSE;} END_CATCH return TRUE; // return TRUE unless you set the focus to a control // EXCEPTION: OCX Property Pages should return FALSE} BEGIN_EVENTSINK_MAP (CParamDlg, CDialog) // {{AFX_EVENTSINK_MAP (CParamDlg) ON_EVENT (CParamDlg, IDC_DHTMLEDIT1, 1 / * DocumentComplete * /, OnDocumentCompleteDhtmledit1, VTS_NONE) //}} AFX_EVENTSINK_MAPEND_EVENTSINK_MAP () void CParamDlg :: OnDocumentCompleteDhtmledit1 () {Getdlgitem (IDOK) -> EnableWindow (TRUE); // read value from data loadingValues ();
} Void CParamDlg :: OnOK () {// TODO: Add extra validation here if (SaveValues ()!) Return; CDialog :: OnOK ();} BOOL CParamDlg :: LoadValues () {TRY {CHTMLElementCollection ecAll = m_wndDhtmlEdit.GetDom () .GetAll (); long lecLength = ecAll.GetLength (); COleVariant varIndex, varTemp; // var2 is not used because accessing index, not name varIndex.vt = VT_I4; CString strElementID, strTemp; CHtmlparam * pHtmlparam; CObject * Pob; for (int i = 0; i
CHtmlparam * pHtmlparam; CObject * pOb; for (int i = 0; i
lVal = var.lVal;} void CParamDlg :: GetValue (CString strName, CString & strVal) {COleVariant var = GetValue (strName); var.ChangeType (VT_BSTR); strVal = var.bstrVal;} void CParamDlg :: SetValue (CString strName , COleVariant varVal, LPCTSTR lpszAlt / * = NULL * /) // displayed as tooltip {COleVariant varRet; CHtmlparam * pHtmlparam; CObject * pOb; if (m_mapNameToParam.Lookup (strName, pOb)) {// found pHtmlparam = (CHtmlparam * ) pOb;} else {pHtmlparam = new CHtmlparam; m_mapNameToParam.SetAt (strName, pHtmlparam);} pHtmlparam-> m_varVal = varVal; if (lpszAlt) pHtmlparam-> m_strAlt = lpszAlt;} void CParamDlg :: SetValue (CString strName, int iVal, LPCTSTR lpszAlt / * = NULL * /) // displayed as tooltip {COleVariant var; var.vt = VT_I4; var.iVal = iVal; SetValue (strName, var, lpszAlt);} void CParamDlg :: SetValueBool (CString strName , BOOL BVAL, LPCTSTR LPSZZALT / * = NULL * /) // Displayed as tooltip {setvalue (Strname, COleVariant ((long) bVal, VT_BOOL), lpszAlt);} CString HTMLElement_GetValueAttributeName (CHTMLElement * pel) {CString strValAttribName; CString strTagName = pel-> GetTagName (); if (strTagName.CompareNoCase (HTML_TAG_INPUT!) || strTagName.CompareNoCase! (HTML_TAG_SELECT)) {strValAttribName = HTML_ATTRIB_VALUE;} if (HTMLElement_IsInputCheckBoxElement (pel)) strValAttribName = HTML_ATTRIB_CHECKED; // to be continued return strValAttribName;} CString HTMLElement_GetToolTipAttributeName (CHTMLElement * pel) {CString strTipAttribName; CString strTagName = pel-> getTagName () ;
if strTipAttribName = HTML_ATTRIB_ALT (strTagName.CompareNoCase (HTML_TAG_INPUT)!); // to be continued return strTipAttribName;} CString HTMLElement_GetIDOrName (CHTMLElement * pel) {COleVariant varTemp; CString strElementID = pel-> GetId (); if (strElementID.IsEmpty ( )) {varTemp = pel-> getAttribute (HTML_ATTRIB_NAME, 0); varTemp.ChangeType (VT_BSTR); strElementID = varTemp.bstrVal;} return strElementID;} BOOL HTMLElement_IsInputElement (CHTMLElement * pel) {CString strTagName = pel-> getTagName () ; return (strTagName.CompareNoCase (HTML_TAG_INPUT)!);} BOOL HTMLElement_IsInputCheckBoxElement (CHTMLElement * pel) {BOOL bRet = FALSE; if (HTMLElement_IsInputElement (pel)) {COleVariant varTemp = pel-> getAttribute (HTML_ATTRIB_TYPE, 0); varTemp.ChangeType (Vt_bstr); cstring straTemp = VARTEMP.BSTRVAL; if (! Strtemp.comparenocase) Bret = true;} return bret;} * pob; for INT i = 0; i
} END_CATCH return TRUE;} BOOL CParamDlg :: SaveValues () {TRY {CHTMLElementCollection ecAll = m_wndDhtmlEdit.GetDom () GetAll ();. Long lecLength = ecAll.GetLength (); COleVariant varIndex, varTemp; // var2 is not used because accessing index, not name varIndex.vt = VT_I4; CString strElementID, strTemp; CHtmlparam * pHtmlparam; CObject * pOb; for (int i = 0; i
} Void CParamDlg :: GetValue (CString strName, CString & strVal) {COleVariant var = GetValue (strName); var.ChangeType (VT_BSTR); strVal = var.bstrVal;} void CParamDlg :: SetValue (CString strName, COleVariant varVal, LPCTSTR lpszAlt / * = NULL * /) // displayed as tooltip {COleVariant varRet; CHtmlparam * pHtmlparam; CObject * pOb; if (m_mapNameToParam.Lookup (strName, pOb)) {// found pHtmlparam = (CHtmlparam *) pOb;} else { pHtmlparam = new CHtmlparam; m_mapNameToParam.SetAt (strName, pHtmlparam);} pHtmlparam-> m_varVal = varVal; if (lpszAlt) pHtmlparam-> m_strAlt = lpszAlt;} void CParamDlg :: SetValue (CString strName, int iVal, LPCTSTR lpszAlt / * = NULL * /) // displayed as tooltip {COleVariant var; var.vt = VT_I4; var.iVal = iVal; SetValue (strName, var, lpszAlt);} void CParamDlg :: SetValueBool (CString strName, BOOL bVal, LPCTSTR lpszAlt / * = NULL * /) // displayed as tooltip {SetValue (strName, COleVariant ((long) bVal, VT_BOOL), lpszAlt);} CString HTMLElement_GetValueAttributeName (CHTMLElement * pel) {CString strValAttribName; CString strTagNa me = pel-> GetTagName (); if {strValAttribName = HTML_ATTRIB_VALUE;} (strTagName.CompareNoCase (HTML_TAG_INPUT) || strTagName.CompareNoCase (HTML_TAG_SELECT)!!) if (HTMLElement_IsInputCheckBoxElement (pel)) strValAttribName = HTML_ATTRIB_CHECKED; // to be continued return strValAttribName;} CString HTMLElement_GetToolTipAttributeName (CHTMLElement * pel) {CString strTipAttribName; CString strTagName = pel-> getTagName (); (! strTagName.CompareNoCase (HTML_TAG_INPUT)) if strTipAttribName = HTML_ATTRIB_ALT; // to be continued return strTipAttribName;} CString HTMLElement_GetIDOrName (Chtmlelement * pel) {Colevariant Vartemp; cstract streelementid = PEL-> getId ();