我自己派生了一个类, 现在是可以编译通过, 但是 class CHtmlEditCtrl: public CWnd, public CHtmlEditCtrlBase<CHtmlEditCtrl> { public: // Construct CHtmlEditCtrl(); // Create a new instance of the control. This will also call the // contained WebBrowser control's Navigate method to load a default // document into the WebBrowser control. virtual BOOL Create(LPCTSTR lpszWindowName, DWORD dwStyle, const RECT& rect, CWnd* pParentWnd, int nID, CCreateContext *pContext=NULL); // Retrieves the URL to a default document to load. virtual LPCTSTR GetStartDocument(); // Retrieves the IHTMLDocument2 interface on the contained WebBrowser control's // currently loaded document. BOOL GetDHtmlDocument(IHTMLDocument2 **ppDocument) const;// Implementation public: // Destruct virtual ~CHtmlEditCtrl();protected: DECLARE_EVENTSINK_MAP() void _OnNavigateComplete2(LPDISPATCH pDisp, VARIANT FAR* URL);};他只提供了这么几个方法, 我怎么做才能实现, 上面提到的功能呢?
error C2039: 'classCHtmlEditCtrl' : is not a member of 'CHtmlEditCtrl' 哎, 郁闷, 我编译的时候又发现这个问题, 跟踪发现错误出在,IMPLEMENT_DYNAMIC(CMyHtmlEditCtrl, CHtmlEditCtrl)我用的是VS2008, 难道我的VS, 莫非是我的VS 版本太低 不支持CHtmlEditCtrl?
和你的工程属性比对了一下, 发现你用的MFC动态库, 我用的是静态库, 用静态库的时候, 就会报错 error C2039: 'classCHtmlEditCtrl' : is not a member of 'CHtmlEditCtrl'还有几个疑惑, 麻烦解答一下,呵呵另外,编辑字体的属性,比如bold,insertImage, underline, 这些属性在哪定义的? MSDN上没有查找到,还有当用insertImage, 他自己就出现一个图片浏览对话框, 我想知道 怎么实现,插入表情图片呢? 就像QQ表情那样, 点击表情按钮,弹出一组表情图片,然后插入到文本框。
单独弄出来的话可以用webbroese,也可以用封装好了的CHtmlEditCtrl
比如说我要实现一个写日记的功能, 里面插入,图片, 格式化的文本, , 当第二次打开程序的时候, 直接显示上次编辑的文本,图片,那么我如何存储呢/, 存在数据库里? 你说的CHtmlEditCtrl控件能实现这个功能吗?
获取内容 IHTMLDocument2 *pDoc = NULL;
m_HtmlEditCtrl.GetDHtmlDocument(&pDoc);
if (NULL == pDoc)
{
return ;
}
HRESULT hr;
CComPtr <IHTMLElement> pBody;
hr = pDoc-> get_body(&pBody); CComBSTR bstrText;
pBody->get_innerHTML(&bstrText); CString csBody(bstrText);//csBody保存的就是html内容,把这个保存到文件读取跟保存差不多,就最后2句不同
pBody->put_innerHTML(bstrText);
要实现你贴得图的效果,我的做法是搞个对话框,按钮贴图,要动态改变字体,插入图片等,用execCommand,具体MSDN
class CHtmlEditCtrl:
public CWnd,
public CHtmlEditCtrlBase<CHtmlEditCtrl>
{
public:
// Construct
CHtmlEditCtrl(); // Create a new instance of the control. This will also call the
// contained WebBrowser control's Navigate method to load a default
// document into the WebBrowser control.
virtual BOOL Create(LPCTSTR lpszWindowName, DWORD dwStyle,
const RECT& rect, CWnd* pParentWnd, int nID, CCreateContext *pContext=NULL); // Retrieves the URL to a default document to load.
virtual LPCTSTR GetStartDocument(); // Retrieves the IHTMLDocument2 interface on the contained WebBrowser control's
// currently loaded document.
BOOL GetDHtmlDocument(IHTMLDocument2 **ppDocument) const;// Implementation
public:
// Destruct
virtual ~CHtmlEditCtrl();protected:
DECLARE_EVENTSINK_MAP()
void _OnNavigateComplete2(LPDISPATCH pDisp, VARIANT FAR* URL);};他只提供了这么几个方法, 我怎么做才能实现, 上面提到的功能呢?
{
int *pStyle = (int*)wParam;
CString *pStr = (CString*)lParam;
ASSERT(pStyle); BSTR strCommand;
VARIANT var;
var.vt = VT_BOOL;
var.boolVal = VARIANT_TRUE;
IHTMLDocument2 *pDoc = NULL;
m_HtmlEditCtrl.GetDHtmlDocument(&pDoc);
if (NULL == pDoc)
{
return 0;
}
switch (*pStyle)
{
case 1:
break;
case 2:
if (NULL == m_pDoc || NULL == pStr)
{
return 0 ;
}
m_HtmlEditCtrl.SetFontFace(*pStr);
break;
case 3:
if (NULL == m_pDoc || NULL == pStr)
{
return 0 ;
}
m_HtmlEditCtrl.SetFontSize((short)_ttoi(*pStr));
break; case 4:
strCommand = ::SysAllocString(_T("Bold") );
pDoc->execCommand(strCommand,var.boolVal,var,&var.boolVal);
::SysFreeString(strCommand);
break; case 5:
strCommand = ::SysAllocString(_T("Italic") );
pDoc->execCommand(strCommand,var.boolVal,var,&var.boolVal);
::SysFreeString(strCommand);
break; case 6:
strCommand = ::SysAllocString(_T("Underline") );
pDoc->execCommand(strCommand,var.boolVal,var,&var.boolVal);
::SysFreeString(strCommand);
break; case 7:
{
DWORD dwColcor = *(DWORD*)lParam;
m_HtmlEditCtrl.SetForeColor(dwColcor);
break;
}
case 8: //左对齐
strCommand = ::SysAllocString(_T("JustifyLeft") );
pDoc->execCommand(strCommand,var.boolVal,var,&var.boolVal);
::SysFreeString(strCommand);
break; case 9:
strCommand = ::SysAllocString(_T("JustifyCenter") );
pDoc->execCommand(strCommand,var.boolVal,var,&var.boolVal);
::SysFreeString(strCommand);
break; case 10:
strCommand = ::SysAllocString(_T("JustifyRight") );
pDoc->execCommand(strCommand,var.boolVal,var,&var.boolVal);
::SysFreeString(strCommand);
break; case 11:
strCommand = ::SysAllocString(_T("Outdent") );
pDoc->execCommand(strCommand,var.boolVal,var,&var.boolVal);
::SysFreeString(strCommand);
break; case 12:
strCommand = ::SysAllocString(_T("Indent") );
pDoc->execCommand(strCommand,var.boolVal,var,&var.boolVal);
::SysFreeString(strCommand);
break; case 13:
strCommand = ::SysAllocString(_T("InsertOrderedList") );
pDoc->execCommand(strCommand,var.boolVal,var,&var.boolVal);
::SysFreeString(strCommand);
break; case 14:
strCommand = ::SysAllocString(_T("InsertUnorderedList") );
pDoc->execCommand(strCommand,var.boolVal,var,&var.boolVal);
::SysFreeString(strCommand);
break; case 15:
{
if (IsTextSelected() )
{
strCommand = ::SysAllocString(_T("CreateLink") );
pDoc->execCommand(strCommand,var.boolVal,var,&var.boolVal);
::SysFreeString(strCommand);
}
else
{
BaseMessageBox msgBox(GetDesktopWindow() );
msgBox.DoModal(this->GetSafeHwnd(),this,_T("请先选择文本,然后才能对该文本进行超链接!"),3);
}
break;
} case 16:
strCommand = ::SysAllocString(_T("InsertImage") );
pDoc->execCommand(strCommand,var.boolVal,var,&var.boolVal);
::SysFreeString(strCommand);
break; default: break;
}
return 0;
}
我搞了10多个按钮,用了个switch区分对应按钮的功能
你是怎么用你派生的HtmlEditCtrl的?我从欧冠HtmlEditCtrl派生了类 CMyHtmlEditCtrl, 在对话框上面放了一个static的空间, 然后关联了一个控件变量,CStatic m_HtmlEditCtrl ;然在头文件中 用CMyHtmlEditCtrl 替换 CStatic ;
但是, 运行程序, 界面上没有出现想要的效果, 还是哪个灰色的static空间, 也不能输入文字
郁闷。
你是怎么用你派生的HtmlEditCtrl的?我从欧冠HtmlEditCtrl派生了类 CMyHtmlEditCtrl, 在对话框上面放了一个static的空间, 然后关联了一个控件变量,CStatic m_HtmlEditCtrl ;然在头文件中 用CMyHtmlEditCtrl 替换 CStatic ;
但是, 运行程序, 界面上没有出现想要的效果, 还是哪个灰色的static空间, 也不能输入文字
郁闷。
CStatic没啥用,就是控制下控件的位置,套用个ID,不需要这个cstatic
error C2039: 'classCHtmlEditCtrl' : is not a member of 'CHtmlEditCtrl'
哎, 郁闷, 我编译的时候又发现这个问题,
跟踪发现错误出在,IMPLEMENT_DYNAMIC(CMyHtmlEditCtrl, CHtmlEditCtrl)我用的是VS2008, 难道我的VS, 莫非是我的VS 版本太低 不支持CHtmlEditCtrl?
他那段代码用了个CStatic只是用来定位控件的,就是把CHtmlEditctrl放到CStatic的位置,然后把cstatic销毁掉,不销毁也可以,把cstatic的visiable属性设置成false。完全可以不用这个cstatic来定位。按照上面的步骤应该是没问题的,当初我也参考了这个,是在还不行你留个邮箱我用2005写个简单demo给你
“对话框中使用CHtmlEditCtrl ”那文章里面代码明显 有问题,呵呵, (4)、在对话框的OnInitDialog中增加下面的代码:
CRect rcIE;
GetDlgItem(IDC_STATIC)->GetWindowRect(&rcIE);
ScreenToClient( &rcIE ); BOOL bRet = Create(NULL,
NULL,
WS_VISIBLE|WS_CHILD|WS_VSCROLL|WS_HSCROLL,
rcIE,
this,
IDC_STATIC,
NULL);
GetDlgItem( IDC_STATIC)->DestroyWindow();
这里面创建的窗口, 也么有和CHtmlEditctrl进行关联嘛,
下面是我的派生类, 感觉没有错, 可急是编译报错.// CMyHtmlEditCtrl.h#pragma once
class CMyHtmlEditCtrl : public CHtmlEditCtrl
{
DECLARE_DYNAMIC(CMyHtmlEditCtrl)
public:
CMyHtmlEditCtrl(); // protected constructor used by dynamic creation
virtual ~CMyHtmlEditCtrl();public:
DECLARE_MESSAGE_MAP()
};// CMyHtmlEditCtrl.cpp
#include "stdafx.h"
#include "BeeTimer.h"
#include "MyHtmlEditCtrl.h"
// CMyHtmlEditCtrl
IMPLEMENT_DYNAMIC(CMyHtmlEditCtrl, CHtmlEditCtrl)
CMyHtmlEditCtrl::CMyHtmlEditCtrl()
{}CMyHtmlEditCtrl::~CMyHtmlEditCtrl()
{
}BEGIN_MESSAGE_MAP(CMyHtmlEditCtrl, CHtmlEditCtrl)
END_MESSAGE_MAP()
和你的工程属性比对了一下, 发现你用的MFC动态库, 我用的是静态库, 用静态库的时候, 就会报错 error C2039: 'classCHtmlEditCtrl' : is not a member of 'CHtmlEditCtrl'还有几个疑惑, 麻烦解答一下,呵呵另外,编辑字体的属性,比如bold,insertImage, underline, 这些属性在哪定义的? MSDN上没有查找到,还有当用insertImage, 他自己就出现一个图片浏览对话框, 我想知道 怎么实现,插入表情图片呢? 就像QQ表情那样, 点击表情按钮,弹出一组表情图片,然后插入到文本框。
插入图片会弹出个对话框,这个你可以不要,不过比较麻烦,就像你保存html内容到文件然后读文件,再显示出来一样,比如说插入图片,就先获取当前的HTML内容,再插入一段HTML(引入图片的路径),然后put_innerHTML来显示
点击表情按钮弹出一组表情图片,这个功能比较普通,笨一点的方法用个popup窗口显示各个表情,根据鼠标点的位置得出所点击的表情对应的路径
顺便鄙视下CSDN:您的回复正文中有非法词或词组!