Created
June 25, 2018 14:05
-
-
Save kennykerr/6490e1494449927147dc18616a5e601e to your computer and use it in GitHub Desktop.
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
#include <winrt/Windows.System.h> | |
#include <ShellScalingAPI.h> | |
#include <DispatcherQueue.h> | |
using namespace std::literals; | |
using namespace winrt; | |
using namespace Windows::Foundation; | |
using namespace Windows::System; | |
auto CreateDispatcherQueueController() | |
{ | |
namespace abi = ABI::Windows::System; | |
DispatcherQueueOptions options | |
{ | |
sizeof(DispatcherQueueOptions), | |
DQTYPE_THREAD_CURRENT, | |
DQTAT_COM_STA | |
}; | |
DispatcherQueueController controller{ nullptr }; | |
check_hresult(CreateDispatcherQueueController(options, reinterpret_cast<abi::IDispatcherQueueController**>(put_abi(controller)))); | |
return controller; | |
} | |
IAsyncAction Async(DispatcherQueue queue) | |
{ | |
while (true) | |
{ | |
co_await 2s; | |
queue.TryEnqueue([] | |
{ | |
puts("handler"); | |
}); | |
} | |
} | |
int main() | |
{ | |
init_apartment(apartment_type::single_threaded); | |
auto controller = CreateDispatcherQueueController(); | |
Async(controller.DispatcherQueue()); | |
MSG message; | |
while (GetMessage(&message, nullptr, 0, 0)) | |
{ | |
DispatchMessage(&message); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment