Reputation: 14264
When a new window is created using CreateEx
does its code execute in its own thread or that of its parent (i.e. the thread in which the its instantiating code was executed)? Thanks.
Upvotes: 1
Views: 351
Reputation: 7829
Cross-thread GUI stuff usually ends in disaster. The windows libraries actively discourage it by throwing exceptions.
Even if it was allowed, CreateWindowEx could not do this by default because it would be making some very big assumptions about your code (locks, thread safety, etc); and most Windows development is probably still essentially single threaded.
Upvotes: 0
Reputation: 613521
Windows have thread affinity – see Raymond Chen's article on this matter.
Upvotes: 2
Reputation: 101506
CreateWindowEx() does not create a new thread. If you want a new thread you have to call either _beginthreadex() (usually preferred) or CreateThread().
In case you're wondering, _beginthreadex()
is preferred over CreateThread()
because the former initializes parts of the CRT that the latter does not.
Upvotes: 2
Reputation: 308530
The window doesn't actually run any code on its own, all the code is called from the message loop which is part of your own code. You can run into huge issues trying to interact with the Windows UI with multiple threads, so you should always respond to the messages within a single thread.
Upvotes: 6