2009-10-26 37 views
3

如何在C#中創建一個數學輸入面板?試圖在C#中創建一個數學輸入面板#

我試圖把它放入一個DLL並調用它,但它只是馬上關閉。

#include <stdafx.h> 
#include <atlbase.h> 
#include "micaut.h" 
#include "micaut_i.c" 

extern "C" __declspec(dllexport) int run() 
{ 
    CComPtr<IMathInputControl> g_spMIC; // Math Input Control 
    HRESULT hr = CoInitialize(NULL); 
    hr = g_spMIC.CoCreateInstance(CLSID_MathInputControl); 
    hr = g_spMIC->EnableExtendedButtons(VARIANT_TRUE); 
    hr = g_spMIC->Show(); 

    return hr; 
} 

我打電話在C#中的dll函數和麪板彈出,但立即消失。有什麼建議麼?

回答

8

在您的C#項目中,添加對COM庫micautLib的引用。然後你可以使用下面的代碼(在C#):

MathInputControl ctrl = new MathInputControlClass(); 
ctrl.EnableExtendedButtons(true); 
ctrl.Show(); 

我不知道如果這正是你應該怎麼做,但這似乎乾淨工作(完整的程序)。

using System; 
using System.Windows.Forms; 
using micautLib; 

namespace MathInputPanel 
{ 
    static class Program 
    { 
     [STAThread] 
     static void Main() 
     { 
      Application.EnableVisualStyles(); 
      Application.SetCompatibleTextRenderingDefault(false); 
      MathInputControl ctrl = new MathInputControlClass(); 
      ctrl.EnableExtendedButtons(true); 
      ctrl.Show(); 
      ctrl.Close +=() => Application.ExitThread(); 
      Application.Run(); 
     } 
    } 
} 
+0

感謝蕾,作品像一個魅力。 – Neosani 2009-10-26 07:02:57

+0

這並沒有解釋核心問題,或者這個代碼如何解決它。核心問題是,實例化數學輸入控件的線程需要運行消息循環以分發其消息。這是一個重要的細節。 – IInspectable 2017-09-20 09:37:01