The CWnd class has a SendMessage() member function which allows you to send messages to its window. For example, let’s say you have a CWnd pointer to the Calculator, and you want to close it. What you should do is send a WM_CLOSE message, which will notify the Calculator that it should close. You can use the following code.
https://www.codeproject.com/articles/Windows-Message-Handling-Part-1