Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 517323
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T07:49:20+00:00 2026-05-13T07:49:20+00:00

I wish to launch a separate thread for handling window messages (via a blocking

  • 0

I wish to launch a separate thread for handling window messages (via a blocking GetMessage loop), but still create the windows in the initial thread, afterward.

Within the separate thread, as soon as it launches, I am calling PeekMessage with PM_NOREMOVE to ensure a message queue exists (is this necessary?), followed by..

AttachThreadInput(initial thread id,GetCurrentThreadId(),true)

..before finally entering the message loop

I am not yet using a mutex or cs to ensure this is happening in time, but am merely using a Sleep statement in my initial thread for the sake of simplicity.

Regardless, window messages do not appear to be intercepted by the separate thread.

I am a little unsure as to whether I am doing this correctly, and would appreciate any possible guidance. Both threads are in the same process

Thank you all

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T07:49:20+00:00Added an answer on May 13, 2026 at 7:49 am

    It seems the best way to instigate window creation from the main thread, while having messages for them handled in a separate, looping thread is to use a custom message, that can be sent to the separate thread – Thus allowing it to create the window, but still allowing that action to be invoked from the initial thread:

    1) Allocate a custom message, and create a structure to hold the window initialisation parameters:

    message_create_window = WM_USER + 0;
    class Message_create_window{
        Message_create_window(...);
    };
    

    2) Instead of calling CreateWindow(Ex), use something similiar to the following, passing in the relavant window creation parameters:

    PostThreadMessage(
        thread.id,
        message_create_window,
        new Message_create_window(...),
        0
    );
    

    3) Handle the custom message in the message pump of your ui handling thread, extract the creation parameters, & free afterwards:

    MSG msg;
    GetMessage(&msg,0,0,0);
    ...
    switch(msg->message){
        ...
        case message_create_window:{
            Message_create_window *data=msg->wParam;
            CreateWindowEx(data->...);
            delete data;
        }break;
        ...
    

    This does, however, have the following side-effects:

    • The window will be created asynchronously. If it is required that the initial thread block until the window is created (or, indeed, that the window’s existence can ever be asserted) then a thread synchronisation tool must be used (such as an event)
    • Care should be taken when interacting with the window (it is a multithreaded application, after all)

    If there are any major holes in this answer, or this seems like a terrible approach, please correct me.
    (This is still my question, & I am trying to find the best way to accomplish this)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 357k
  • Answers 357k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer The other answers are correct. Here is some code you… May 14, 2026 at 9:40 am
  • Editorial Team
    Editorial Team added an answer you ruin the noConflict concept by reassigning the jquery to… May 14, 2026 at 9:40 am
  • Editorial Team
    Editorial Team added an answer If you get that particular error, you don't actually have… May 14, 2026 at 9:40 am

Related Questions

No related questions found

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.