You can cancel in the beforeclick and then you can write your own popup menu's instead of the default ones.

Another option is use the FindWindow win32 API call to find the window and post a WM_CLOSE to it. I'm not sure in wich event you must do it but easy to find.