Solved

How to Edit text in CHtmlView ?

Posted on 2002-07-08
9
526 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
 

Author Comment

by:hung2k
Comment Utility
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
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 12

Expert Comment

by:migel
Comment Utility
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
Comment Utility
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
Comment Utility
hmm
it is so strange
I tested this code and everething was ok;
Do you edit local page?
0
 

Author Comment

by:hung2k
Comment Utility
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
Comment Utility
Hi!
why not use just Navigate method (with proper local URL)?
show your code for loading page please
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
repeatEnd java challenge 42 83
Question regarding Copy/Paste 16 85
Separate files macro - Errors on larger data set 18 56
Fibonacci challenge 11 81
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…
In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
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.
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

728 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now