我是在一个多媒体日记的软件中,看到的这样的功能,  、
如图,   可以实现文字的编辑, 字体设置,  插入图片,表情,。打印,  保存, 另存为,,,等功能,请问,这是怎么实现的,   是加载的什么控件吗?

解决方案 »

  1.   

    webbrowse控件可以实现,就像foxmail下面那个“编辑框”一样
      

  2.   

    在MSDN(我用的2005版)中搜索HTMLEdit,下载实例。
    单独弄出来的话可以用webbroese,也可以用封装好了的CHtmlEditCtrl
      

  3.   


    比如说我要实现一个写日记的功能, 里面插入,图片, 格式化的文本,  ,  当第二次打开程序的时候, 直接显示上次编辑的文本,图片,那么我如何存储呢/,  存在数据库里?  你说的CHtmlEditCtrl控件能实现这个功能吗?
      

  4.   

    CHtmlEditCtrl可以实现,这点数据量不用存放到数据库,随便搞个什么ini配置文件就可以,比如你插入图片,格式化文本后可以查看HTML代码,只要把这个HTML代码保存起来就可以,图片什么的最好也保存下,不然图片路径有变动的话下次打开时,图片就会显示一把X
      

  5.   

    以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);
      

  6.   

    CRichEdit这个控件也可以实现类似大部分功能
      

  7.   

    CHtmlEditCtrl 这个在对话框中怎么使用, ?  怎么我从CHtmlEditCtrl派生了一个类, 然后关联到一个static控件上,  编译不了, 好像是CHtmlEditCtrl的构造函数被声明为protect的了,,,,
      

  8.   

    这是个BUG,自己从CHtmlEditCtrl派生个
      

  9.   

    http://blog.csdn.net/tingya/article/details/2028172
    要实现你贴得图的效果,我的做法是搞个对话框,按钮贴图,要动态改变字体,插入图片等,用execCommand,具体MSDN
      

  10.   

    我自己派生了一个类, 现在是可以编译通过,  但是
    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);};他只提供了这么几个方法,    我怎么做才能实现, 上面提到的功能呢?
      

  11.   

    LRESULT SendEmailDlg::UpdatePen(WPARAM wParam, LPARAM lParam)
    {
    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区分对应按钮的功能
      

  12.   

    谢谢,  
    你是怎么用你派生的HtmlEditCtrl的?我从欧冠HtmlEditCtrl派生了类 CMyHtmlEditCtrl, 在对话框上面放了一个static的空间,  然后关联了一个控件变量,CStatic m_HtmlEditCtrl ;然在头文件中 用CMyHtmlEditCtrl 替换 CStatic ;
    但是, 运行程序,  界面上没有出现想要的效果, 还是哪个灰色的static空间,  也不能输入文字
    郁闷。
      

  13.   

    谢谢,  
    你是怎么用你派生的HtmlEditCtrl的?我从欧冠HtmlEditCtrl派生了类 CMyHtmlEditCtrl, 在对话框上面放了一个static的空间,  然后关联了一个控件变量,CStatic m_HtmlEditCtrl ;然在头文件中 用CMyHtmlEditCtrl 替换 CStatic ;
    但是, 运行程序,  界面上没有出现想要的效果, 还是哪个灰色的static空间,  也不能输入文字
    郁闷。
      

  14.   

    m_HtmlEditCtrl.Create(NULL,WS_VISIBLE|WS_CHILD|WS_VSCROLL|WS_TABSTOP, CRect( ),this,IDC_EDIT_TALKWRITEEDIT,NULL); 
    CStatic没啥用,就是控制下控件的位置,套用个ID,不需要这个cstatic
      

  15.   


     error C2039: 'classCHtmlEditCtrl' : is not a member of 'CHtmlEditCtrl'
    哎, 郁闷, 我编译的时候又发现这个问题, 
     跟踪发现错误出在,IMPLEMENT_DYNAMIC(CMyHtmlEditCtrl, CHtmlEditCtrl)我用的是VS2008, 难道我的VS, 莫非是我的VS 版本太低 不支持CHtmlEditCtrl?
      

  16.   

    我用的VS2005,你就按照“对话框中使用CHtmlEditCtrl ”上面的步骤就是了,
    他那段代码用了个CStatic只是用来定位控件的,就是把CHtmlEditctrl放到CStatic的位置,然后把cstatic销毁掉,不销毁也可以,把cstatic的visiable属性设置成false。完全可以不用这个cstatic来定位。按照上面的步骤应该是没问题的,当初我也参考了这个,是在还不行你留个邮箱我用2005写个简单demo给你
      

  17.   


    “对话框中使用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()
      

  18.   

    不行把你的demo给我发一下, 我比对一下吧, [email protected]谢谢了.
      

  19.   

    代码已发送,估计你是没#include<afxhtml.h>
      

  20.   


    和你的工程属性比对了一下, 发现你用的MFC动态库, 我用的是静态库,  用静态库的时候, 就会报错 error C2039: 'classCHtmlEditCtrl' : is not a member of 'CHtmlEditCtrl'还有几个疑惑, 麻烦解答一下,呵呵另外,编辑字体的属性,比如bold,insertImage, underline, 这些属性在哪定义的? MSDN上没有查找到,还有当用insertImage, 他自己就出现一个图片浏览对话框, 我想知道 怎么实现,插入表情图片呢? 就像QQ表情那样, 点击表情按钮,弹出一组表情图片,然后插入到文本框。
      

  21.   

    MSDN :execCommand,有个Command Identifiers,就有这些属性
    插入图片会弹出个对话框,这个你可以不要,不过比较麻烦,就像你保存html内容到文件然后读文件,再显示出来一样,比如说插入图片,就先获取当前的HTML内容,再插入一段HTML(引入图片的路径),然后put_innerHTML来显示
    点击表情按钮弹出一组表情图片,这个功能比较普通,笨一点的方法用个popup窗口显示各个表情,根据鼠标点的位置得出所点击的表情对应的路径
      

  22.   

    插入图片什么的,这些功能可以通过execCommand弹对话框,选择插入图片来实现,也可以通过自己写html代 码来控制。
    顺便鄙视下CSDN:您的回复正文中有非法词或词组!
      

  23.   

    不知道我说清了没,举个例子,就像一开始说的保存功能,第二次打开能看到上次编译的内容,假如我插入一张图片,保存,第二次打开可以看到上次编辑的内容(包括插入的图片),但是这里是纯粹通过html代码来控制的
      

  24.   

    我记得ActiveX有一个类似的控件