0

Another application is sending a WM_CLOSE to my application's window.

How can I determine if the WM_CLOSE I receive in the WinProc is from my application and not from another application that used SendMessage?

ProgrammingLlama
  • 36,677
  • 7
  • 67
  • 86
John
  • 5,942
  • 3
  • 42
  • 79
  • From [tagging help page](https://stackoverflow.com/help/tagging): _The only time you should use tags in your title is when they are organic to the conversational tone of the title._ – ProgrammingLlama Jun 27 '19 at 07:01
  • 1
    Maybe this: https://stackoverflow.com/questions/910991/how-can-my-app-find-the-sender-of-a-windows-message and this: https://stackoverflow.com/questions/6930685/how-to-detect-differentiate-external-wm-close-vs-internally-triggered-by-form-cl answers your question. – user743414 Jun 27 '19 at 07:14
  • This is practically impossible. The best you could possibly hope for is to find out, whether a sent message originated from the same thread or a different thread by inspecting the call stack. For cross-thread sent messages, you will find a message retrieval call somewhere on the call stack. Sent messages that do not cross threads will call directly into the window procedure. With that out of the way, what are you *really* trying to accomplish here? – IInspectable Jun 27 '19 at 08:23
  • If you have any cleanup to do, it's best to always handle `WM_CLOSE`, regardless of the source. Sending `WM_CLOSE` is the way to request an application to exit gracefully. Task Manager and taskkill.exe both use this. If a process ignores the request, Task Manager will forcefully terminate it. – Eryk Sun Jun 27 '19 at 11:13

0 Answers0