The correct way is to send the WM_CLOSE message to the appropriate window, or simply call DestroyWindow , which will send the WM_DESTROY message to the window.
A thread cannot use DestroyWindow to destroy a window created by another thread.
The difference between WM_CLOSE and WM_DESTROY:
WM_CLOSE , WM_CLOSE DestroyWindow, .
, WM_CLOSE , "", WM_DESTROY, .
, WM_DESTROY.
HWND , !
, , WM_CLOSE.