0

我正在尝试从面向 Win 10 x64 的桌面 Windows 应用程序中以 C++ (winrt) 显示消息对话框。以下代码执行,但未显示对话框。ShowAsync 的返回代码很好

int APIENTRY wWinMain(_In_ HINSTANCE    hInstance,
                         _In_opt_ HINSTANCE hPrevInstance,
                         _In_ LPWSTR        lpCmdLine,
                         _In_ int           nCmdShow)
    {

      Microsoft::WRL::Wrappers::RoInitializeWrapper init(RO_INIT_SINGLETHREADED);

        Microsoft::WRL::ComPtr<ABI::Windows::UI::Popups::IMessageDialogFactory> messageDialogFactory;
        Microsoft::WRL::Wrappers::HStringReference messageDialogFactoryId(RuntimeClass_Windows_UI_Popups_MessageDialog);

        Windows::Foundation::GetActivationFactory(messageDialogFactoryId.Get(), messageDialogFactory.GetAddressOf());

        Microsoft::WRL::ComPtr<ABI::Windows::UI::Popups::IMessageDialog> messageDialog;
        Microsoft::WRL::ComPtr<ABI::Windows::Foundation::Collections::IVector<ABI::Windows::UI::Popups::IUICommand*>> uiCommands;

        messageDialogFactory->CreateWithTitle(Microsoft::WRL::Wrappers::HStringReference(L"XXX").Get(), Microsoft::WRL::Wrappers::HStringReference(L"YYY").Get(), messageDialog.GetAddressOf());
        messageDialog->get_Commands(uiCommands.GetAddressOf());

        Microsoft::WRL::ComPtr<ABI::Windows::UI::Popups::IUICommandFactory> uiCommandFactory;
        Microsoft::WRL::Wrappers::HStringReference commandFactoryId(RuntimeClass_Windows_UI_Popups_UICommand);

        Windows::Foundation::GetActivationFactory(commandFactoryId.Get(), uiCommandFactory.GetAddressOf());

        w::ComPtr<pu::IUICommand> button;
        uiCommandFactory->CreateWithHandler(Microsoft::WRL::Wrappers::HStringReference(L"ZZZ").Get(), new ButtonHandler(), button.GetAddressOf());

        uiCommands->Append(button.Get());

        Microsoft::WRL::ComPtr<ABI::Windows::Foundation::IAsyncOperation<ABI::Windows::UI::Popups::IUICommand*>> showOperation;
        HRESULT hr = messageDialog->ShowAsync(showOperation.GetAddressOf());

        MSG msg;
        while( ::GetMessage(&msg, 0, 0, 0) > 0 )
        {
            ::TranslateMessage(&msg);
            ::DispatchMessage(&msg);
        }


      return 0;
    }
4

1 回答 1

0

应该阅读文档 - API 没有 DualApiPartitionAttribute

于 2018-02-10T22:27:39.880 回答