In a Windows Application, when multiple threads are used, I know that it’s necessary to invoke the main thread to update GUI components. How is this done in a Console Applic
As the documentation on MSDN say :
The function will fail in the following situations:
- [...]
- If the thread does not own the window. [...]
So there is no "main" thread in question here (AFAIK Win32Api doesn't care about witch thread your program entry point is executed on).
The only condition is that you must execute AnimateWindow on a thread that is owning the window that you are animating. That's the one that called CreateWindow as it is the function that define the thread / message-loop afinity).
Now that you have posted your sample code, the problem that you will have is that you aren't trying to animate just any window... but you are trying to animate the console window itself... And you aren't on it's owner thread (otherwise it won't refresh when you create an infinite loop in your application)... so calling AnimateWindow won't be possible except if you manage to coerce windows to execute code on that thread.
The fact console windows are in fact owned by CSRSS witch is a system process executing with elevated rights make messing with them really risky anyway.
Since windows vista it's even impossible to send a message to such windows due to process protection so any vulnerability that could be exploited previously to coerce this thread to execute code should now be unusable.
For the details regarding the specificity of the console window see the Why aren't console windows themed on Windows XP? post on the Raymond Chen blog (from the microsoft windows shell team so it's pretty much from the source)