as I searched online, the code fragment I found was hard to understand and the reason of that because I'm still new to windowAPI, so can anyone further explain or demonstrate how I would close the application?
By sending the WM_CLOSE message to the Window Handle you would like to close, you will be able to close the application.
sending WM_CLOSE window message won't terminate application. It will jst close the window. You can use TerminateProcess which will unconditionally kill the threads of target process. Safe method of terminating a process is ExitProcess
You can use PostQuitMessage(0); with WM_CLOSE and WM_DESTROY and use enddilaog of application window before PostQuitMessage(0);