hung2k
asked on
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
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
ASKER
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
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
Hi!
you have to use IOleCommandTarget interface of hte WebBrowser control to change selection style
here is example:
void CMfcieView::OnBoldSelectio n()
{
static bool bDesign = false;
bDesign = !bDesign;
if (m_pBrowserApp != NULL)
{
IOleCommandTarget* pCmdTarg;
m_pBrowserApp->QueryInterf ace(IID_IO leCommandT arget, (void**)&pCmdTarg);
if (pCmdTarg!= NULL)
{
// Bold the current selection
hr = pCmdTarg->Exec(&CGID_MSHTM L, IDM_BOLD, MSOCMDEXECOPT_DODEFAULT, NULL, NULL);
pCmdTarg->Release();
}
}
}
// for complete list of the command look into the MSHTMCID.H
you have to use IOleCommandTarget interface of hte WebBrowser control to change selection style
here is example:
void CMfcieView::OnBoldSelectio
{
static bool bDesign = false;
bDesign = !bDesign;
if (m_pBrowserApp != NULL)
{
IOleCommandTarget* pCmdTarg;
m_pBrowserApp->QueryInterf
if (pCmdTarg!= NULL)
{
// Bold the current selection
hr = pCmdTarg->Exec(&CGID_MSHTM
pCmdTarg->Release();
}
}
}
// for complete list of the command look into the MSHTMCID.H
ASKER
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
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
Hi!
I do not understant what previous content you mean?
Your changes are gone out when you switch from Design to View mode?
I do not understant what previous content you mean?
Your changes are gone out when you switch from Design to View mode?
ASKER
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.
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.
hmm
it is so strange
I tested this code and everething was ok;
Do you edit local page?
it is so strange
I tested this code and everething was ok;
Do you edit local page?
ASKER
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
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
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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->QueryIn
(LPVOID*) &lpTarget)))
{
lpTarget->put_designMode(b
lpTarget->Release();
}
lpDisp->Release();
}
}
}