Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

How to Edit text in CHtmlView ?

Posted on 2002-07-08
9
Medium Priority
?
550 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Moving data to the cloud? Find out if you’re ready

Before moving to the cloud, it is important to carefully define your db needs, plan for the migration & understand prod. environment. This wp explains how to define what you need from a cloud provider, plan for the migration & what putting a cloud solution into practice entails.

 

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 400 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: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering 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

Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
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.
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…

722 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