Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Are Win32 windows thread safe?

I'd like to create a window on one thread, and then have that HWND migrate to one of any number of threads on which it will execute. My program will have multiple such windows. Is this possible or was the Win32 API not designed for this?

like image 302
May Oakes Avatar asked Sep 20 '11 17:09

May Oakes


1 Answers

Yes, to a certain extent.

You can send and post messages to an HWND from any thread.

http://msdn.microsoft.com/en-us/library/ms644944(v=VS.85).aspx

Attempting to configure the UI (e.g. add controls) from another thread will end badly. However, if you send your window a message, you can be sure that the message will be processed on the creating thread.

like image 78
Andy Davis Avatar answered Oct 07 '22 22:10

Andy Davis