高分:HTML编辑问题

大圆镜智1222 2003-02-26 08:00:30
我原来用CHtmlView实现网页显示功能,现在想把显示出的页面实现编辑功能(用户就是可以修改页面上的文字,主要为了之后的打印),各位高人请指点。
...全文
148 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
蒋晟 2003-02-27
  • 打赏
  • 举报
回复
Using DISPID_AMBIENT_USERMODE
The final way to activate the MSHTML Editor uses an ambient property through an IDispatch interface implemented by an application hosting the WebBrowser. To switch between browsing and editing this way, you need to implement IDispatch so that it handles the DISPID_AMBIENT_USERMODE message passed into IDispatch::Invoke:

Hide Example

HRESULT
CAtlBrCon::Invoke(DISPID dispidMember,
REFIID riid,
LCID lcid, WORD wFlags,
DISPPARAMS* pDispParams,
VARIANT* pvarResult,
EXCEPINFO* pExcepInfo,
UINT* puArgErr)
{
switch (dispidMember)
{
case DISPID_AMBIENT_USERMODE:

V_VT(pvarResult) = VT_BOOL;
V_BOOL(pvarResult) = m_bBrowseMode ?
VARIANT_TRUE : VARIANT_FALSE;

break;
.
.
.

Here, IDispatch::Invoke sets the out-parameter pvarResult that is returned to MSHTML based on the value of the variable m_bBrowseMode. Passing VARIANT_TRUE back to MSHTML in the pvarResult parameter switches the browser into browse mode. Passing VARIANT_FALSE switches it into editing mode.

Once your IDispatch interface is implemented, you must trigger MSHTML to call your IDispatch::Invoke implementation. To do this, use the IOleControl::OnAmbientPropertyChange method of an IOleControl interface obtained from the IWebBrowser2 control.

IOleControl* pControl;

hr = m_spWebBrowser->QueryInterface(IID_IOleControl,
(void**)&pControl);

pControl->OnAmbientPropertyChange(DISPID_AMBIENT_USERMODE);

pControl->Release();

In this example, the call to IOleControl::OnAmbientPropertyChange causes MSHTML to call the IDispatch::Invoke method passing DISPID_AMBIENT_USERMODE for the DISPID.

蒋晟 2003-02-27
  • 打赏
  • 举报
回复
Using IHTMLElement3::put_contentEditable
The MSHTML Editor can also be activated on a per-element basis using the IHTMLElement3::contentEditable property.

// Assume pElement is a valid pointer to an IHTMLElement3 interface

pElement->put_contentEditable(L"true");

Notice that the IHTMLElement3::contentEditable property is set with a BSTR rather than a Boolean value. This is because it has a possible value of "inherit," besides the usual "true" and "false" values.

Before you can make an element editable, you must locate it in the document. Here is how you might locate an element whose id is "editableblock."
蒋晟 2003-02-27
  • 打赏
  • 举报
回复
Using IHTMLDocument2::put_designMode
IHTMLDocument2 has an IHTMLDocument2::designMode property that takes a BSTR argument. The IHTMLDocument2::designMode property can be switched on and off like this:

// Assume pDoc is a valid IHTMLDocument2 interface pointer
pDoc->put_designMode(L"On"); // switches MSHTML Editor on
pDoc->put_designMode(L"Off"); // switches MSHTML Editor off

The IHTMLDocument2::designMode property is stored with an initial capital letter. It also has an initial value of "Inherit" when the WebBrowser is first activated. Remember this if you test the IHTMLDocument2::designMode property's value. For instance, the following code switches the MSHTML Editor on and off based on the current IHTMLDocument2::designMode value. Note: even if you don't use an initial capital letter in the argument for the put_designMode calls, the method still works correctly.

USES_CONVERSION; // Needed for the OLE2A conversion macro
BSTR bstrMode;

pDoc->get_designMode(&bstrMode);
char* cMode = OLE2A(bstrMode);

// The "O" in "On" must be capitalized
if (strcmp(cMode, "On")) // strcmp returns 0 when
// the strings are the same
pDoc->put_designMode(L"On");
else
pDoc->put_designMode(L"Off");

88dd 2003-02-26
  • 打赏
  • 举报
回复
<P>Table 1 Editable</P><BR/>
<TABLE BORDER=1 WIDTH=80%>
<THEAD>
<TR>
<TH><DIV CONTENTEDITABLE STYLE="height: 100%; width: 100%;">Heading 1 <DIV></TH>
<TH><DIV CONTENTEDITABLE STYLE="height: 100%; width: 100%;">Heading 2 <DIV></TH>
</TR>
</THEAD>
<TBODY>
<TR>
<TD><DIV CONTENTEDITABLE STYLE="height: 100%; width: 100%;">Row 1, Column 1 text.<DIV></TD>
<TD><DIV CONTENTEDITABLE STYLE="height: 100%; width: 100%;">Row 1, Column 2 text.<DIV></TD>
</TR>
<TR>
<TD><DIV CONTENTEDITABLE STYLE="height: 100%; width: 100%;">Row 2, Column 1 text.<DIV></TD>
<TD><DIV CONTENTEDITABLE STYLE="height: 100%; width: 100%;">Row 2, Column 2 text.<DIV></TD>
</TR>
</TBODY>
</TABLE>

3,055

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC HTML/XML
社区管理员
  • HTML/XML社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧