Domanda

Come posso creare un pannello di input matematico in C #?

Ho provato a metterlo in una dll e chiamarlo ma si chiude immediatamente.

#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;
}

Chiamo la funzione dll in C # e il pannello si apre ma scompare subito. Qualche suggerimento?

È stato utile?

Soluzione

Nel progetto C #, aggiungere un riferimento alla libreria COM micautLib . Quindi è possibile utilizzare il seguente codice (in C #):

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

Non sono sicuro che sia esattamente come dovresti farlo, ma questo sembra funzionare in modo pulito (programma completo).

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();
        }
    }
}
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top