打开基本的数学输入控件

Opening a Basic Math Input Control

本文关键字:输入 控件      更新时间:2023-10-16

我希望有人可以帮助我。我的目标是使用C 打开数学输入面板,但该面板在程序退出之前仅打开一秒钟。这是我尝试的。

  • cin.get((;
  • 系统("暂停"(;
  • getchar((;

上述所有使程序打开的尝试都导致数学输入控制窗口弹出,但保持空白。

我使用的代码直接来自此处。

https://msdn.microsoft.com/en-us/library/windows/desktop/dd317324(v = vs.85(.aspx

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

所有帮助都将受到赞赏。

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

您的程序显示窗口,但立即终止。您将需要运行一个消息循环以服务GUI。

单线公寓中的同步(STA(通过窗口消息实现(请参阅理解和使用COM线程模型(。这要求您在每个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();
    }
}

以响应单击 CLOSS CANCEL 按钮,发送WM_USER + 2消息的数学输入控件不是已记录的合同的一部分。适当的实现将实现_imathinputControlevents,并响应其关闭事件。