我如何接受 MathML? [英] How do i accept MathML?

查看:26
本文介绍了我如何接受 MathML?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我今天发现 Windows 7 带有一个非常令人印象深刻的 MathPanel 实用程序,用于执行方程的手写识别:

这很好.(这里我已经输入了sRGB色彩空间伽马转换部分的公式)

但现在我似乎不能用它任何事情.

有一个插入按钮.我假设点击 Insert 会将它插入到它后面活动的应用程序中(就像屏幕键盘的工作原理一样):

除非我假设它会作为粘贴操作进行操作.

我在帮助中找不到关于应用程序需要什么才能使其工作的信息.没有提到某些软件必须支持的任何特殊 API.

我也无法在 MSDN 上找到任何关于接受方程插入所需的特殊 API 的信息.

我必须实现哪些 API、注册、回调、侦听器、消息、COM 对象才能接收 MathPanel 输入?

我提到 MathML 的唯一原因是因为 SuperUser 上的回答提到了 MathML:

<块引用>

理论上,任何支持 MathML(数学标记语言)的应用都可以与 Windows 7 数学输入面板一起使用.数学输入面板仅适用于支持 MathML 的程序.以下是一些此类应用:StarOffice、OpenOffice、Opera 和 Maple.

那么我如何让我的程序支持 MathML?

据我所知 MathML 是一种标记语言;不是 Windows API.这就像在说,我如何让我的程序支持 HTML?"Html 是文本,您可以将其粘贴到任何地方.

除非我支持"MathML,否则 MathPad 拒绝粘贴?

<小时>

更新

在单击插入后检查剪贴板上的IDataObject,我看到两种可用格式(都不是文本,这解释了为什么我没有得到任何标记):

格式 1:

 CLIPFORMAT cfFormat: "MathML Presentation" (49839)PDVTargetDevice ptd:0x00000000DWORD dwAspect:DVASPECT_CONTENT双字索引:-1DWORD tymed: 1 (TYMED_HGLOBAL)

格式 2:

 CLIPFORMAT cfFormat:"MathML" (49838)PDVTargetDevice ptd:0x00000000DWORD dwAspect:DVASPECT_CONTENT双字索引:-1DWORD tymed: 1 (TYMED_HGLOBAL)

所以至少现在我有一些剪贴板格式:

  • MathML 演示"
  • MathML"

我仍然无法在 MSDN 上找到任何关于剪贴板格式的信息.

解决方案

监视发送到我的窗口的消息,看起来像 Math Input Panel 应用程序发送了 Ctrl+V:

  • WM_KEYDOWN (0x11) VK_CONTROL
  • WM_KEYDOWN (0x56) V
  • WM_CHAR (0x16)
  • WM_KEYUP (0x11) VK_CONTROL
  • WM_KEYUP (0x56) V

所以你需要意识到有人试图按下 Ctrl+V.然后你必须提取内容.

首先注册三种剪贴板格式:

Handle CF_MathML_Presentation = RegisterClipboardFormat("MathML Presentation");处理 CF_MathML_Content = RegisterClipboardFormat("MathML 内容");处理 CF_MathML = RegisterClipboardFormat("MathML");

<块引用>

注意: 附录 BW3C 的数学标记语言 (MathML) 版本 3.0 记录了要注册的 Windows 剪贴板格式名称:

  • Generic MathML Windows 剪贴板名称:MathML
  • Presentation MathML Windows 剪贴板名称:MathML Presentation
  • Content MathML Windows 剪贴板名称:MathML Content

然后获取剪贴板中 IDataObject 的句柄:

IDataObject dataObject;OleGetClipboard(dataObject);

然后枚举所有格式,寻找您喜欢的格式:

IEnumFORMATETC 枚举;dataObject.EnumFormatEtc(DATADIR_GET, out enum);String mathXml = "";foreach(枚举中的FormatEtc格式){if (format.cfFormat = CF_MathML_Presentation) ||(format.cfFormat = CF_MathML_Content) ||(format.cfFormat = CF_MathML){//我们知道如何处理这些格式:STGMEDIUM 培养基;dataObject.GetData(format.cfFormat, out medium);mathXml = GetStringFromStorageMedium(medium);//处理所有讨厌的 HGlobal/IStream/IStorage 废话}}ShowMessage(mathXml);//多多!

<小时>

Microsoft 还允许您编程数学输入 COM 对象:

//创建COM对象IMathInputControl mathInputControl = CreateComObject(CLSID_MathInputControl);mathInputControl.Show();

然后您可以创建一个接收通知事件的对象:

class MathEvents : _IMathInputControlEvents{公共 HRESULT 插入(字符串 mathXml){//当插入按钮被点击时通知事件处理程序.MessageBox.Show(mathXml);返回 S_OK;}公共 HRESULT 清除(){//点击清除按钮时通知事件处理程序.返回 S_OK;}公共 HRESULT 关闭(){//当关闭按钮被点击时通知事件处理程序.返回 S_OK;}public HRESULT PaintHRESULT Paint(LONG_PTR hdc, LONG Left, LONG Top, LONG Right, LONG Bottom, LONG Element, LONG State){//当控件的按钮和背景需要绘制时通知事件处理程序.返回 S_OK;}

缺少的要素是如何为 mathInputControl 提供对回调对象的引用.

这是超级秘密的复杂 COM 代码,涉及 ConnectionPointContainer 和Advise`,其中不能从 C# 中完成.

但你不需要,你可以使用Ctrl+V.

i discovered today that Windows 7 comes with a very impressive MathPanel utility, for performing handwriting recognition of equations:

Which is fine. (Here i've entered the formula for the part of the sRGB color space gamma conversion)

But now i don't seem to be able to do anything with it.

There is an Insert button. i would assume that clicking Insert would insert it into the application that is active behind it (much like the On-Screen Keyboard works):

Except i assume it would operate as a Paste operation.

i can find no information in the help on what is required by an application to make it work. There is no mention of any special API some software must support.

Nor can i find any information on MSDN about what special API is required to accept the insertion of an equation.

What API, registration, callback, listener, message, COM Object do i have to implement so that i will receive MathPanel input?

The only reason i mention MathML is because an answer on SuperUser mentioned MathML:

Theoretically, any app that supports MathML (Mathematical Markup Language) can be used with the Windows 7 Math Input Panel. The Math Input Panel only works with programs that support MathML. Here are a few such apps: StarOffice, OpenOffice, Opera and Maple.

Well how do i make my program support MathML?

As far as i know MathML is a markup language; not a Windows API. It would be like saying, "How do i make my program support HTML?" Html is text, and you can paste it anywhere.

MathPad refuses to paste unless i "support" MathML?


Update

Inspecting the IDataObject on the clipboard after clicking Insert, i see two formats available (neither of which are text, which explains why i do not get any markup):

Format 1:

     CLIPFORMAT cfFormat: "MathML Presentation" (49839)
PDVTargetDevice ptd:      0x00000000
          DWORD dwAspect: DVASPECT_CONTENT
          DWORD lindex:   -1
          DWORD tymed:    1  (TYMED_HGLOBAL)

Format 2:

     CLIPFORMAT cfFormat:"MathML" (49838)
PDVTargetDevice ptd:      0x00000000
          DWORD dwAspect: DVASPECT_CONTENT
          DWORD lindex:   -1
          DWORD tymed:    1  (TYMED_HGLOBAL)

So at least now i have some clipboard formats:

  • "MathML Presentation"
  • "MathML"

i still cannot find anything on MSDN about either clipboard format.

解决方案

Spying on messages sent to my window, looks like the Math Input Panel application sends a Ctrl+V:

  • WM_KEYDOWN (0x11) VK_CONTROL
  • WM_KEYDOWN (0x56) V key
  • WM_CHAR (0x16)
  • WM_KEYUP (0x11) VK_CONTROL
  • WM_KEYUP (0x56) V key

So you need to recognize that someone's trying to hit Ctrl+V. Then you must extract the contents.

First register the three clipboard formats:

Handle CF_MathML_Presentation = RegisterClipboardFormat("MathML Presentation");
Handle CF_MathML_Content = RegisterClipboardFormat("MathML Content");
Handle CF_MathML = RegisterClipboardFormat("MathML");

Note: Appendix B of the W3C's Mathematical Markup Language (MathML) Version 3.0 documents the Windows clipboard format names to be registered:

  • Generic MathML Windows Clipboard Name: MathML
  • Presentation MathML Windows Clipboard Name: MathML Presentation
  • Content MathML Windows Clipboard Name: MathML Content

Then get a handle on the IDataObject in the clipboard:

IDataObject dataObject;
OleGetClipboard(dataObject);

Then enumerate all the formats, looking for the one you like:

IEnumFORMATETC enum;
dataObject.EnumFormatEtc(DATADIR_GET, out enum);

String mathXml = "";

foreach (FormatEtc format in enum)
{
    if (format.cfFormat = CF_MathML_Presentation) ||
       (format.cfFormat = CF_MathML_Content) ||
       (format.cfFormat = CF_MathML)
    {
        //We know how to handle these formats:
        STGMEDIUM medium;
        dataObject.GetData(format.cfFormat, out medium);

        mathXml = GetStringFromStorageMedium(medium); //handles all the nasty HGlobal/IStream/IStorage nonsense
    }
}

ShowMessage(mathXml); //tada!


Microsoft also allows you to program the Math Input COM object:

//Create the COM object
IMathInputControl mathInputControl = CreateComObject(CLSID_MathInputControl);
mathInputControl.Show();

You can then create an object that receives the notification events:

class MathEvents : _IMathInputControlEvents
{
    public HRESULT Insert(String mathXml)
    {
       //Notifies the event handler when the Insert button is clicked.
       MessageBox.Show(mathXml);
       return S_OK;
    }

    public HRESULT Clear()
    {
       //Notifies the event handler when the Clear button is clicked.      
       return S_OK;
    }

    public HRESULT Close()
    {
       //Notifies the event handler when the Close button is clicked.
       return S_OK;
    }

    public HRESULT PaintHRESULT Paint(LONG_PTR hdc, LONG Left, LONG Top, LONG Right, LONG Bottom, LONG Element, LONG State)
    {
       //Notifies the event handler when the buttons and background of the control require painting.
       return S_OK;           
    }

The missing ingredient is how to give mathInputControl a reference to our callback object.

That's super-secret complicated COM code, involving ConnectionPointContainer, andAdvise`, which cannot be done from C#.

But you don't need to, you can just use Ctrl+V.

这篇关于我如何接受 MathML?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆