Fix freeze when pressing enter to dismiss a dialog while focused in a text box in Mozilla applications.
In this case, the window dies before the message is sent, but the return value of PostMessage wasn't being checked. Therefore, we were waiting forever for an event that would never be set.
However, it's also possible that the thread might die after the message is sent but before it is handled. Therefore, switch to using SendMessageCallback, which calls the callback with a 0 result if the thread dies.
This also fixes a leak, since event handles in the previous code weren't being closed.
Fixes #6422.