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?
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.
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);
}
Technology. WinRT is implemented in the programming language C++ and is object-oriented by design. Its underlying technology, the Windows API (Win32 API), is written mostly in the language C.
What is WinRT(Windows Runtime)? In simple words, Windows Runtime Library (WinRT) is the default application programming interface (API) used by Windows 8. It does not replace the Win32 API that has been running underneath all Windows applications, but rather augments it.
On the File menu, choose New and then choose Project. In the New Project dialog box, in the left pane, expand Installed > Templates > Visual C++, and then select Win32. In the middle pane, select Win32 Project. In the Name box, type a name for the project, for example, DesktopApp.
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.
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.
See Microsoft Docs
C++ /WinRt was designed to support the projected APIs written using the Windows Runtime type system. These include the Windows.UI.XAML and Winodws.UI.Composition APIs. These APIs are designed for UWP-style applications though, and have very limited ability to interface with the classic Win32 APIs.
You might find the WIL header libraries useful. It doesn't have the complete modern wrappers for C++ that you get with C++ /WinRT, but you will find the libraries have smart wrappers and various convenience helpers for many Win32 constructs. You can find documentation here.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With