• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 557
  • Last Modified:

How to Edit text in CHtmlView ?

Dear Experts,

I have used CHtmlView to load and display some local HTML pages, but after that, I do want to allow editing some texts in these pages, say,
- using keyboard to modify some text
- changing font, color and size
- save back to a new page

I know that there is some sample code using IHtmlEditHost or something similar, but the code used ATL and I don;t know how to apply to an existing CHtmlView derived class

Any help would be very appreciated

Thank you very much

Hung
0
hung2k
Asked:
hung2k
  • 5
  • 4
1 Solution
 
migelCommented:
Hi!
you can switch CHTMLView to the design mode
here is example how to :

//class CMfcieView is derived from CHTMLView

void CMfcieView::OnDesign()
{
     static bool bDesign = false;
     bDesign = !bDesign;
     if (m_pBrowserApp != NULL)
          {
          IHTMLDocument2* lpTarget = NULL;
          LPDISPATCH lpDisp = GetHtmlDocument();

          if (lpDisp != NULL)
               {
               // the control will handle all printing UI
               if (SUCCEEDED(lpDisp->QueryInterface(IID_IHTMLDocument2,
                         (LPVOID*) &lpTarget)))
                    {
                    lpTarget->put_designMode(bDesign ? L"On" : L"Off");
                    lpTarget->Release();
                    }
               lpDisp->Release();
               }
          }
}
0
 
hung2kAuthor Commented:
Thanks migel,

I can allow edit the page with this but I dont know how to let it accept event from the application to change fonts and color or format them

Hung
0
 
migelCommented:
Hi!
you have to use IOleCommandTarget interface of hte WebBrowser control to change selection style
here is example:
void CMfcieView::OnBoldSelection()
{
    static bool bDesign = false;
    bDesign = !bDesign;
    if (m_pBrowserApp != NULL)
         {
         IOleCommandTarget* pCmdTarg;
         m_pBrowserApp->QueryInterface(IID_IOleCommandTarget, (void**)&pCmdTarg);
         if (pCmdTarg!= NULL)
              {
              // Bold the current selection
              hr = pCmdTarg->Exec(&CGID_MSHTML, IDM_BOLD, MSOCMDEXECOPT_DODEFAULT, NULL, NULL);
              pCmdTarg->Release();
              }
         }
}

// for complete list of the command look into the MSHTMCID.H
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
hung2kAuthor Commented:
Migel,

I don't understand why my previous content are wiped every time I enter Design mode by using OnDesign

I tried not to keep the IHTMLDocument2 around and not release them as you did in OnDesign, but still can not prevent this previous content wiped out

What can I do to load a previous content, turn on Design mode then edit on that content

Thanks for your helpful help
0
 
migelCommented:
Hi!
I do not understant what previous content you mean?
Your changes are gone out when you switch from Design to View mode?
0
 
hung2kAuthor Commented:
I loaded an existing HTML into the browser
Then because I wanted to edit this page, so I switched to edit mode.
But whenever OnDesign was called, everything was gone out, I only got an empty page and can do edit on a blank new page only.

0
 
migelCommented:
hmm
it is so strange
I tested this code and everething was ok;
Do you edit local page?
0
 
hung2kAuthor Commented:
Oh, yes, I forgot to tell you that it's a local page that I loaded during OnBeginNavigate2 instead of loading as normal URL. There may be a problem there ? Whenever it switches to design mode, seemed that it reloads the page ?

Anyway, you deserved the point for this questions. I want to reward the points to you, but still want to discuss more about this a little bit before I close. Can I do that ?

Thanks


0
 
migelCommented:
Hi!
why not use just Navigate method (with proper local URL)?
show your code for loading page please
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 5
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now