Solved

How to Edit text in CHtmlView ?

Posted on 2002-07-08
9
536 Views
Last Modified: 2013-11-20
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
Comment
Question by:hung2k
  • 5
  • 4
9 Comments
 
LVL 12

Expert Comment

by:migel
ID: 7140183
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
 

Author Comment

by:hung2k
ID: 7176324
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
 
LVL 12

Expert Comment

by:migel
ID: 7176429
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
Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

 

Author Comment

by:hung2k
ID: 7196572
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
 
LVL 12

Expert Comment

by:migel
ID: 7196863
Hi!
I do not understant what previous content you mean?
Your changes are gone out when you switch from Design to View mode?
0
 

Author Comment

by:hung2k
ID: 7197488
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
 
LVL 12

Expert Comment

by:migel
ID: 7197743
hmm
it is so strange
I tested this code and everething was ok;
Do you edit local page?
0
 

Author Comment

by:hung2k
ID: 7224625
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
 
LVL 12

Accepted Solution

by:
migel earned 100 total points
ID: 7224656
Hi!
why not use just Navigate method (with proper local URL)?
show your code for loading page please
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

860 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question