如何使用 WinRT 创建经典的 win32 应用程序窗口? [英] How do you create a classic win32 application window with WinRT?
问题描述
在 Win32 API 中注册窗口类、创建窗口然后通过消息泵循环保持活动状态的 C++ WinRT 等价物是什么?
What's the C++ WinRT equivalent for what in the Win32 API would be registering a window class, creating a window and then keeping it alive via a message pump loop?
我目前正在查看和阅读 WinRT 的文档,因为我想学习如何以现代 C++ 方式完成我过去在 Win32 中所做的所有事情.
I'm currently looking at and reading the documentation for WinRT because I wanted to learn how to do all of the stuff I used to do in Win32 the modern C++ way.
到目前为止,我的经历很糟糕,我要直截了当地承认我没有得到它.
My experience has been awful so far and I'm just gonna admit straight out that I'm not getting it.
我试过了,但由于我没有在容器中运行,似乎尚未创建线程的 CoreWindow.
I tried this but since I'm not running in a container it seems like the CoreWindow for the thread hasn't been created yet.
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 是 现代 C++ 使用 Windows 运行时(又名 WinRT)API 的方式.这些 API 派生自 IInspectable
,后者本身派生自 IUnknown
.除了用于 COM 对象的 winrt::com_ptr
之外,它并没有真正为经典的 Win32 API 提供多少.
C++/WinRT is the Modern C++ way of using Windows Runtime (a.k.a. WinRT) APIs. These APIs are derived from IInspectable
, which itself derives from IUnknown
. Other than the winrt::com_ptr
for COM objects, it doesn't really offer much for classic Win32 APIs.
您当然可以使用 C++/WinRT 从 Win32 经典应用程序使用 Windows 运行时 API,但对于 Win32 经典程序,没有CoreWindow"这样的东西.所有 Windows::UI::CoreWindow
都与通用 Windows 平台 (UWP) 应用相关.
You can certainly use C++/WinRT to consume Windows Runtime APIs from a Win32 classic application, but there's no such thing as a 'CoreWindow' for Win32 classic programs. All of Windows::UI::CoreWindow
is related to Universal Windows Platform (UWP) apps.
这篇关于如何使用 WinRT 创建经典的 win32 应用程序窗口?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!