我原来用CHtmlView实现网页显示功能,现在想把显示出的页面实现编辑功能(用户就是可以修改页面上的文字,主要为了之后的打印),各位高人请指点。
解决方案 »
- java?c++?
- (高手请进)请问怎么隐藏弹出的系统属性对话框。
- 如何用Resource Editor打开.rc文件——很菜的问题
- 如何实现可以任意加入任何控件的控件容器?
- VC调用office的问题,超级要我命,各位谁知道?给100分
- 知道VB下的属性和方法,如何在VC下调用?急急急!!!急急急!!!在线等待
- 问在Dialog中引用数据库产生的问题
- 菜鸟TreeView与CTreeCtrl问题
- 求南京数字音频工作一份
- 程序运行中如何用代码切换输入法?(如按个按钮就切换过来)
- 高手们快进来,高分由你拿!
- 请问从数据库中读出了一个字段的值,此时它是variant_t型的,那么怎么把variant_t转换成int or char 类型??
<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>
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 offThe 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");
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 interfacepElement->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."
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 ExampleHRESULT
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.