C++ 打开基本数学输入控件

C++ 打开基本数学输入控件,c++,winapi,com,C++,Winapi,Com,我希望有人能帮助我。我的目标是用C++打开一个数学输入面板,但是面板只在程序退出之前打开一秒钟。这是我试过的 cin.get() 系统(“暂停”) getchar() 所有上述保持程序打开的尝试都导致“数学输入控制”窗口弹出,但保持空白 我使用的代码直接来自这里 我正在使用Visual Studio Community Edition 2017和Windows 10 非常感谢您的帮助 #include "stdafx.h" #include "micaut.h" #include "mic

我希望有人能帮助我。我的目标是用C++打开一个数学输入面板,但是面板只在程序退出之前打开一秒钟。这是我试过的

  • cin.get()
  • 系统(“暂停”)
  • getchar()
所有上述保持程序打开的尝试都导致“数学输入控制”窗口弹出,但保持空白

我使用的代码直接来自这里

我正在使用Visual Studio Community Edition 2017和Windows 10

非常感谢您的帮助

#include "stdafx.h"
#include "micaut.h"
#include "micaut_i.c"
#include "atlcomcli.h"

using namespace std;



int main()
{
    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 0;
}
#包括“stdafx.h”
#包括“micaut.h”
#包括“micaut_i.c”
#包括“atlcomcli.h”
使用名称空间std;
int main()
{
CComPtr g_spMIC;//数学输入控件
HRESULT hr=协同初始化(NULL);
hr=g_spMIC.CoCreateInstance(CLSID_MathInputControl);
hr=g\u spMIC->EnableExtendedButtons(VARIANT\u TRUE);
hr=g_spMIC->Show();
返回0;
}

您的程序显示窗口,但随后立即终止。您需要运行一个消息循环来为GUI提供服务

单线程单元(STA)中的同步是通过窗口消息实现的(请参阅)。这需要在每个STA线程中运行消息循环

#include <windows.h>
#include <micaut.h>
#include <micaut_i.c>
#include <atlcomcli.h>

int main() {
    HRESULT hr = ::CoInitialize(NULL);

    CComPtr<IMathInputControl> g_spMIC; // Math Input Control
    if ( SUCCEEDED( hr ) ) {
        hr = g_spMIC.CoCreateInstance(CLSID_MathInputControl);
    }
    if ( SUCCEEDED( hr ) ) {
        hr = g_spMIC->EnableExtendedButtons(VARIANT_TRUE);
    }
    if ( SUCCEEDED( hr ) ) {
        hr = g_spMIC->Show();
    }

    if ( SUCCEEDED( hr ) ) {
        // Message loop for STA
        MSG msg{ 0 };
        while ( ::GetMessageW( &msg, nullptr, 0, 0 ) ) {
            // MathInputControl sends WM_USER + 2 when it should close
            if ( msg.message == ( WM_USER + 2 ) )
                break;
            ::TranslateMessage( &msg );
            ::DispatchMessageW( &msg );
        }

        ::CoUninitialize();
    }
}
#包括
#包括
#包括

#包含并响应其事件。

“导致数学输入控制窗口弹出,但保持空白”-您希望看到什么,为什么?您的程序立即终止。你需要它来维持生命。您需要运行一个消息循环。@IInspectable:我希望它呈现数学输入控件,但它只打开一个空白窗口。没有暂停技术,它会呈现数学输入控件,但会自动关闭。@David Heffernan:太好了!我将研究如何做到这一点,并报告回来。谢谢。由于您将数学输入面板实例化为STA,因此必须确保发送消息,以便它能够正常工作。正如David Heffernan所指出的,您需要运行一个数据库。