You could get it to work as follows:
When you receive WM_NCACTIVATE, create a timer say for 5 seconds. If you receive a WM_ACTIVATE message look at what HWND is gaining activation, and decide if you want your app to close or not. That would also solve the problem of allowing the user to switch to other apps without closing your app (you reported that a WM_ACTIVATE is not received when the "close" button is clicked). Set a flag based on that info. In your timer handler, which will be triggered 5 seconds after WM_NCACTIVATE, only close your app based on the setting of your flag.
Dan East