How can I close an application if I write it only using WinApi, without windows?
It can be even simpler:
- Nobody, by the way, mentioned a
gracefulway to exit the application (compared to ExitProcess ), which is to use the PostQuitMessage function .
The difference between
PostQuitMessageis that the second method assumes a smoother output from the point of view of the
WM_QUITmessage is virtual, which ideologically corresponds to a low priority message for a
pull'afrom the queue. From a practical point of view, this allows your application to process all non-virtual (that is, higher priority) messages before exiting the program.
I did not encounter it in practice, but I think that potentially calling
ExitProcessmay well lead to visual artifacts and some other undesirable
- A good article on the topic can be read here.
Argument = 0, meaning "without error."
You can even halt, but I do not advise to abuse it, because it is difficult to debug.
Get the isRunning boolean variable and check it in the message loop. If it is false, then stop the loop. Thus, the program will end automatically. This will be more correct than calling ExitProcess, because all objects will be correctly deleted.