您如何使用Winrt创建经典的Win32应用程序窗口

How do you create a classic win32 application window with WinRT?

本文关键字:Win32 应用程序 窗口 经典 创建 何使用 Winrt      更新时间:2023-10-16

c winrt等同于Win32 API中的内容是什么,将注册窗口类,创建窗口,然后通过消息泵循环保持窗口?

我目前正在查看Winrt的文档,因为我想学习如何做我过去在Win32中做的所有事情。

到目前为止,我的经历还很糟糕,我只是直接承认我没有得到它。

我尝试了此操作,但是由于我没有在容器中运行,因此似乎尚未创建线程的CoreWindow。

    int WINAPI wWinMain(HINSTANCE, HINSTANCE, LPWSTR, int)
    {
        winrt::init_apartment(winrt::apartment_type::single_threaded);
        winrt::Windows::UI::Core::CoreWindow window = winrt::Windows::UI::Core::CoreWindow::GetForCurrentThread();
        window.Activate();
        auto dispatcher = window.Dispatcher();
        using DispatcherOptions = winrt::Windows::UI::Core::CoreProcessEventsOption;
        const DispatcherOptions options = DispatcherOptions::ProcessUntilQuit;
        dispatcher.ProcessEvents(options);
    }

c /winrt是使用Windows Runtime(又称Winrt(API的现代C 方法。这些API源自IInspectable,该API本身源自IUnknown。除了COM对象的winrt::com_ptr外,它并没有为Classic Win32 API提供太多。

您当然可以使用C /WinRT来消费Win32 Classic应用程序中的Windows运行时API,但是对于Win32 Classic程序,没有" CoreWindow"之类的东西。所有Windows::UI::CoreWindow与通用Windows平台(UWP(应用有关。

请参阅Microsoft Docs

c /winrt旨在支持使用Windows运行时类型系统编写的投影API。其中包括windows.ui.xaml和winodws.ui.com posiot apis。这些API是为UWP风格的应用而设计的,并且与Classic Win32 API交互的能力非常有限。

您可能会发现Wil标题库有用。它没有C /Winrt获得的C 的完整现代包装器,但是您会发现库有许多Win32结构的智能包装器和各种便利助手。您可以在这里找到文档。