I am creating a multi-threading console application where the primary thread initiates 2 more threads. One reads data on sockets and other logs the data in file.

Now i want that the primary thread should be capable of handling window messages like WM_CLOSE or minimize/maximize. If i am able to capture these messages i can gracefully exit my secondary threads and clean up memory allocated and close all open threads.

I want to know how can i capture the messages in console window program when user clicks on close/minimize/maximize button.

Kavitesh Singh.