⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 chtmleditor.h

📁 用visual c++写的一个超文本编辑器
💻 H
📖 第 1 页 / 共 2 页
字号:

// ************************************************************************
// Internet Explorer HTML Access class written by Elm黃oft for Code Project
//                          www.elmue.de.vu
//                          kickme.to/elmue
// ************************************************************************

#if !defined(HTML_EDITOR_H__AF3E29B6_2B28_46D0_9D37_74D6C9E41B4A__INCLUDED_)
#define HTML_EDITOR_H__AF3E29B6_2B28_46D0_9D37_74D6C9E41B4A__INCLUDED_

#pragma once

#include <atlbase.h>          // CComPtr
#include <afxhtml.h>          // CHtmlView
#include "VS7/mshtml_VS7.h"   // IHTMLDomNode etc..
#include "VS7/MsHtmcid_VS7.h" // IDM_JUSTIFYLEFT etc..

#define WM_IDLEUPDATECMDUI  0x0363

#define _HKLM  HKEY_LOCAL_MACHINE
#define _HKCU  HKEY_CURRENT_USER
#define _HKCR  HKEY_CLASSES_ROOT

#if _MSC_VER > 1200 // > Visual Studio 6.0
#error "This code is written for Visual Studio 6. Download the version for Visual Studio 7 instead from CodeProject.com!"
#endif

#define HTMLEDIT_INIT_DONE   5000
#define HTMLEDIT_UPDATE_UI   5001
#define HTMLEDIT_KILLFOCUS   5002
#define HTMLEDIT_SETDEFAULT  5003
#define HTMLEDIT_NAVIGATED   5004
#define IDM_FONTSIZE_STYLE   5005
#define ID_TIMER_WAIT_BUSY   5006

class CHtmlEditor : public CHtmlView
{
public:

	// Forward declarations of embedded classes
	class cHtmlStyle;
	class cHtmlStyleSheet;
	class cHtmlDomNode;
	class cHtmlElement;
	class cHtmlTableCell;
	class cHtmlTableRow;
	class cHtmlTable;
	class cHtmlHR;
	class cHtmlImg;
	class cHtmlDocument;

	class CUniRichEdit;
	class cMisc;
	class CMsieWnd;
	class cStreamReader;

	// ####################################################

	class cMisc
	{
	public:
		static CString DecodeMime(CString s_Text);
		static CString EncodeHtml(BSTR bs_Html);
		static void    EncodeHtml(const WCHAR *u16_In, UINT *pu32_WcharToCopy, char *s8_Out, UINT *pu32_OutSize);
		static CString VarToStr(CComVariant &v_Variant);
		static CString RemoveTag(CString s_Html, CString s_Tag);
		static CString CutString(CString s_In, CString s_Cut, BOOL b_End);
		static void    RegWriteString(HKEY h_Class, CString s_Path, CString s_Key, CString s_Value);
		static void    RegWriteDword (HKEY h_Class, CString s_Path, CString s_Key, DWORD u32_Value);
	};

	// ####################################################

	// These definitions must have the same order as enum eProp !
	// C2059: syntax error : 'string' is caused by a
	// Compiler bug: Don't put a space behind "\" here !!!!!!!!!!
	#define __StyleNames { _T("background-color:"), \
	                       _T("color:"),            \
	                       _T("border:"),           \
	                       _T("border-width:"),     \
	                       _T("border-style:"),     \
	                       _T("font-size:"),        \
	                       _T("font-family:"),      \
	                       _T("width:"),            \
	                       _T("height:"),           \
	                       _T("text-decoration:") }

	class cHtmlStyle : public cMisc
	{
	public:
		enum eProp
		{
			E_BackgColor = 0,
			E_ForeColor,   // text color
			E_Border,
			E_BorderWidth,
			E_BorderStyle,
			E_FontSize,
			E_FontFamily,
			E_Width,
			E_Height,
			E_Decoration,
			// to be expanded here.. (update also __StyleNames !!)
		};

		cHtmlStyle(CComPtr<IHTMLStyle>     i_Style);
		cHtmlStyle(CComPtr<IHTMLRuleStyle> i_RuleStyle);

		virtual BOOL Valid();
		CString GetProperty(eProp e_Prop);
		BOOL SetProperty(eProp e_Prop, CString s_Value);

	protected:
		CComPtr<IHTMLStyle>     mi_Style;
		CComPtr<IHTMLRuleStyle> mi_RuleStyle;
	};


	// ####################################################

	class cHtmlStyleSheet : public cMisc
	{
	public:
		cHtmlStyleSheet(CComPtr<IHTMLStyleSheet> i_Sheet);

		virtual BOOL Valid();
		cHtmlStyle GetRule(CString s_Selector);
		BOOL SetProperty(CString s_Selector, cHtmlStyle::eProp e_Prop, CString s_Value);

	protected:
		BOOL AddRule(CString s_Selector, cHtmlStyle::eProp e_Prop, CString s_Value);

		CComPtr<IHTMLStyleSheet>                mi_Sheet;
		CComPtr<IHTMLStyleSheetRulesCollection> mi_Collect;
	};


	// ####################################################

	class cHtmlDomNode : public cMisc
	{
	public:
		cHtmlDomNode(CComPtr<IHTMLDOMNode> i_Dom);

		virtual BOOL Valid();
		cHtmlElement NextSibling();
		cHtmlElement PreviousSibling();
		BOOL Remove();
		BOOL Strip();
		cHtmlElement AppendChild(cHtmlElement i_NewChild);

	protected:
		CComQIPtr<IHTMLDOMNode, &IID_IHTMLDOMNode> mi_Dom;
	};


	// ####################################################

	class cHtmlElement : public cHtmlDomNode
	{
	public:
		cHtmlElement(CComPtr<IHTMLElement> i_Elem);
		const cHtmlElement& operator=(const cHtmlElement& El);
		operator CComPtr<IHTMLElement>();

		virtual BOOL Valid();
		CString GetTagName();
		CString GetClassName();
		cHtmlElement GetParent();
		UINT GetChildCollection(CComQIPtr<IHTMLElementCollection> &i_Collect);
		cHtmlElement FindParent(CString s_Tag);
		cHtmlElement SkipParents(CString s_Tags);
		CString GetAttribute(CString s_AttrName);
		BOOL SetAttribute(CString s_AttrName, CString s_Value);
		BOOL RemoveAttribute(CString s_AttrName);
		CString GetInnerText();
		BOOL SetInnerHtml(CString s_Html);
		BOOL IsEmpty();
		CString GetInnerHtml();
		CString GetOuterHtml();
		BOOL InsertHtml(CString s_Html, BOOL b_AtBegin, BOOL b_Inside);
		cHtmlStyle GetStyle();
		cHtmlElement AppendNewChild(CString s_Tag);

		static cHtmlElement GetElementFromCollection(UINT u32_Index, CComQIPtr<IHTMLElementCollection> &i_Collect);

	protected:
		CComQIPtr<IHTMLElement, &IID_IHTMLElement> mi_Elem;
	};

	// ####################################################

	class cHtmlTableCell : public cHtmlElement
	{
	public:
		cHtmlTableCell(CComPtr<IHTMLElement> i_Elem);

		virtual BOOL Valid();
		cHtmlTableRow GetParentRow();
		cHtmlTable    GetParentTable();
		BOOL SetColSpan(UINT Span);
		UINT GetCellIndex();
		UINT GetColIndex();
		UINT GetRowIndex();
		UINT GetColSpan();
		UINT GetRowSpan();
		BOOL Combine();
		void Split();
		BOOL SetInnerHtml(CString s_Html);
		void    SetBgColor(CString s_Color);
		CString GetBgColor();

	protected:
		CComQIPtr<IHTMLTableCell, &IID_IHTMLTableCell> mi_Cell;
	};

	// ####################################################

	class cHtmlTableRow : public cHtmlElement
	{
	public:
		cHtmlTableRow(CComPtr<IHTMLElement> i_Elem);

		virtual BOOL Valid();
		UINT GetCellCount();
		UINT GetRowIndex();
		BOOL DeleteCell(UINT Index);
		BOOL DeleteColumn(UINT Index);
		cHtmlTableCell InsertColumn(UINT Index);
		cHtmlTableCell GetCell     (UINT Index);
		cHtmlTableCell GetColumn   (UINT Index, BOOL b_ReturnPrevious =FALSE);
		cHtmlTableCell InsertCell  (UINT Index);
		cHtmlTable GetParentTable();

	protected:
		CComQIPtr<IHTMLTableRow, &IID_IHTMLTableRow> mi_Row;
	};

	// ####################################################

	class cHtmlTable : public cHtmlElement
	{
	public:
		enum eRules // Table border
		{
			E_RulesAll  = 0,  // Horizontal lines, vertical lines and box
			E_RulesHor  = 1,  // Horizontal lines and box
			E_RulesVert = 2,  // Vertikal   lines and box
			E_RulesBox  = 3   // Only Box (border around)
		};
		cHtmlTable(CComPtr<IHTMLElement> i_Elem);

		virtual BOOL Valid();
		CString GetBgColor();
		void SetBgColor(CString s_Color);
		BOOL DeleteRow(UINT Index);
		BOOL DeleteColumn(UINT Index);
		cHtmlTableRow GetRow   (UINT Index);
		cHtmlTableRow InsertRow(UINT Index, int CellCount);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -