-
Notifications
You must be signed in to change notification settings - Fork 90
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
65 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
#pragma once | ||
#include <winrt/Windows.Foundation.h> | ||
#include <winrt/Windows.System.h> | ||
#include <dispatcherqueue.h> | ||
|
||
namespace robmikh::common::desktop | ||
{ | ||
namespace impl | ||
{ | ||
inline void ShutdownAndThenPostQuitMessage(winrt::Windows::System::DispatcherQueueController const& controller, int exitCode) | ||
{ | ||
auto action = controller.ShutdownQueueAsync(); | ||
action.Completed([exitCode](auto&&, auto&&) | ||
{ | ||
PostQuitMessage(exitCode); | ||
}); | ||
} | ||
} | ||
|
||
inline auto CreateDispatcherQueueControllerForCurrentThread() | ||
{ | ||
namespace abi = ABI::Windows::System; | ||
|
||
DispatcherQueueOptions options | ||
{ | ||
sizeof(DispatcherQueueOptions), | ||
DQTYPE_THREAD_CURRENT, | ||
DQTAT_COM_NONE | ||
}; | ||
|
||
winrt::Windows::System::DispatcherQueueController controller{ nullptr }; | ||
winrt::check_hresult(CreateDispatcherQueueController(options, reinterpret_cast<abi::IDispatcherQueueController**>(winrt::put_abi(controller)))); | ||
return controller; | ||
} | ||
|
||
inline int ShutdownDispatcherQueueControllerAndWait(winrt::Windows::System::DispatcherQueueController const& controller, int exitCode) | ||
{ | ||
impl::ShutdownAndThenPostQuitMessage(controller, exitCode); | ||
MSG msg = {}; | ||
while (GetMessageW(&msg, nullptr, 0, 0)) | ||
{ | ||
TranslateMessage(&msg); | ||
DispatchMessageW(&msg); | ||
} | ||
return static_cast<int>(msg.wParam); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<packages> | ||
<package id="Microsoft.Windows.CppWinRT" version="2.0.220418.1" targetFramework="native" /> | ||
<package id="Microsoft.Windows.ImplementationLibrary" version="1.0.220201.1" targetFramework="native" /> | ||
<package id="robmikh.common" version="0.0.15-beta" targetFramework="native" /> | ||
<package id="Microsoft.Windows.CppWinRT" version="2.0.230706.1" targetFramework="native" /> | ||
<package id="Microsoft.Windows.ImplementationLibrary" version="1.0.231216.1" targetFramework="native" /> | ||
<package id="robmikh.common" version="0.0.22-beta" targetFramework="native" /> | ||
</packages> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters