Skip to content

Instantly share code, notes, and snippets.

@kennykerr
Created June 25, 2018 14:05
Show Gist options
  • Save kennykerr/6490e1494449927147dc18616a5e601e to your computer and use it in GitHub Desktop.
Save kennykerr/6490e1494449927147dc18616a5e601e to your computer and use it in GitHub Desktop.
#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