diff --git a/src/ruisapp/glue/windows/application.cxx b/src/ruisapp/glue/windows/application.cxx index 4d7f372..2c8c8a4 100644 --- a/src/ruisapp/glue/windows/application.cxx +++ b/src/ruisapp/glue/windows/application.cxx @@ -145,7 +145,11 @@ application_glue::application_glue(const utki::version_duplet& gl_version) : ), ruis_style_provider( // utki::make_shared(this->ruis_resource_loader) - ) + ), + // the glue is created on the UI thread (the thread running the main loop); + // post_to_ui_thread() uses this id to post procedures to the UI thread's + // message queue + ui_thread_id(::GetCurrentThreadId()) {} void application_glue::render() @@ -158,15 +162,15 @@ void application_glue::render() void application_glue::post_to_ui_thread(std::function procedure) { if ( // - PostMessage( // - NULL, // post message to UI thread's message queue + PostThreadMessage( // + this->ui_thread_id, // post message to the UI thread's message queue WM_USER, 0, // no wParam // NOLINTNEXTLINE(cppcoreguidelines-owning-memory, cppcoreguidelines-pro-type-reinterpret-cast) reinterpret_cast(new std::function(std::move(procedure))) ) == 0) { - throw std::runtime_error("PostMessage(): failed"); + throw std::runtime_error("PostThreadMessage(): failed"); } } diff --git a/src/ruisapp/glue/windows/application.hxx b/src/ruisapp/glue/windows/application.hxx index 9f55ca1..e4d6596 100644 --- a/src/ruisapp/glue/windows/application.hxx +++ b/src/ruisapp/glue/windows/application.hxx @@ -131,6 +131,11 @@ private: public: std::atomic_bool quit_flag = false; + // the id of the UI thread (the thread that created the glue and runs the + // main loop); post_to_ui_thread() uses it to post procedures to the UI + // thread's message queue + const DWORD ui_thread_id; + const utki::shared_ref updater = utki::make_shared(); std::vector> windows_to_destroy;