负载墨水在C#中MathInputControl [英] Load ink to a MathInputControl in C#

查看:721
本文介绍了负载墨水在C#中MathInputControl的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图用使用mathinputcontrol的LoadInk方法,但我想不通的地方创建从IIDispInk对象,因为它只是似乎是一个接口。

I'm trying to use use the LoadInk method of an mathinputcontrol but I can't figure out where to create the IIDispInk object from, as it just appears to be an interface.

http://msdn.microsoft.com /en-us/library/dd372605(VS.85).aspx

任何指导,将不胜感激。

Any guidance would be highly appreciated.

感谢:)

编辑:为清楚起见,这里是我到目前为止的代码(感谢汉斯帕桑特)

for clarity, here is my code so far [edit 2: by "so far", I mean of what's been added. Pretty much all the rest of my code can be found on SO under how to create the MIC in C#] (thanks to Hans Passant)

MSINKAUTLib.InkDispClass loadInkTest = new MSINKAUTLib.InkDispClass();

Stream stream = File.Open("C:\\Tim\\bytes.isf", FileMode.Open);
byte[] bytes = new byte[stream.Length];
stream.Read(bytes, 0, bytes.Length);
loadInkTest.Load(bytes);


ctrl.LoadInk((micautLib.IInkDisp)loadInkTest);



不幸的是,这将引发如出一辙例外

Unfortunately this throws exactly the same exception

灾难性故障(从HRESULT异常:0x8000FFFF(E_UNEXPECTED))

C:\Tim\bytes。 ISF包含来自InkPicture控制,加载和保存该文件的文件保存OK字节,所以我认为,因为loadInkTest.Load()方法不抛出异常(通常是毫不避讳地这样做),它加载的数据确定。如果有一个更好的(或更明显)的地方建议,获取的字节数,请让我知道。

C:\Tim\bytes.isf contain bytes saved from an InkPicture control which loads and saves this file file OK, so I assume that because the loadInkTest.Load() method did not throw an exception (normally it is not shy to do so) that it loaded the data OK. If there is a suggestion on a better (or more obvious) place to get the bytes, please let me know.

推荐答案

使用项目+添加引用,浏览选项卡。导航到C:\program files\common files\microsoft shared\ink并选择InkObj.dll。现在,您可以创建MSINKAUTLib.InkDispClass的一个实例。它实现IInkDisp并具有保存和载入的方法。

Use Project + Add Reference, Browse tab. Navigate to c:\program files\common files\microsoft shared\ink and select InkObj.dll. You can now create an instance of MSINKAUTLib.InkDispClass. It implements IInkDisp and has Save and Load methods.

您必须将对象转换为micautLib.IInkDisp,接口来自不同的类型库。而硬道理,你必须先()之前使用LoadInk调用MathInputControl的Show()方法。错误报告是苦不堪言,一切都是E_UNEXPECTED。我得到的代码工作:

You will have to cast the object to micautLib.IInkDisp, the interfaces come from different type libraries. And the clincher, you have to call the MathInputControl's Show() method first before using LoadInk(). Error reporting is miserable, everything is E_UNEXPECTED. The code I got to work:

        var ctl = new micautLib.MathInputControl();
        var ink = new MSINKAUTLib.InkDisp();
        ink.Load(System.IO.File.ReadAllBytes("c:\\temp\\test.isf"));
        var iink = (micautLib.IInkDisp)ink;
        ctl.Show();
        ctl.LoadInk(iink);



加上插入和关闭事件的事件处理程序。和胶水来获得在正确的地方的窗口。

Plus event handlers for the Insert and Close event. And the glue to get the window in the right place.

另外注意的是,micautLib类型库对本机的位岬的依赖。肇事者是SetOwnerWindow()方法,您的真正的想用它来防止该对话框的消失背后的另一个窗口。它的参数被声明为LONG_PTR,一个类型,是一个32位操作系统,在x64 64位在32位。该窗口的句柄。当您使用Visual Studio,你总是会得到该方法的32位版本,因为VS是一个32位程序。

Also beware that the micautLib type library has a dependency on the bit-ness of the machine. The troublemaker is the SetOwnerWindow() method, you really want to use it to prevent the dialog from disappearing behind another window. Its argument is declared as LONG_PTR, a type that is 32-bits on a 32-bit operating system, 64-bits on x64. The window handle. When you use Visual Studio, you will always get the 32-bit version of that method since VS is a 32-bit program.

如果您打算支持64位操作系统,那么你将要建立你的程序的一个单独的版本。与运行Tlbimp.exe将的64位版本(不Visual Studio的)来创建Interop包装开始。这样的说法将是一个64位的值,并传递给该方法的窗口句柄兼容。

If you plan on supporting 64-bit operating systems then you will have to build a separate version of your program. Starting with running the 64-bit version of Tlbimp.exe (not Visual Studio) to create the interop wrapper. So that the argument will be a 64-bit value and compatible with the window Handle you pass to the method.

嗯,COM的乐趣。没有真正的事故,这是没有的Microsoft.Ink.dll包裹:)

Ah, the joys of COM. No real accident that this wasn't wrapped by Microsoft.Ink.dll :)

这篇关于负载墨水在C#中MathInputControl的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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