0

I want to prevent my MFC dialog from being closed when window X button clicked, instead I want my windows to be hidden like ShowWindow(SW_HIDE);

I tried WM_ON_CLOSE, I get close message, I save my work, but can't prevent termination of my program and minimizing to tray.

I want to prevent X button from closing my dialog, instead hiding it.

Thanks in advance

1 Answer 1

0

Try adding a WM_SYSCOMMAND handler and trap the SC_CLOSE command.

But before you do that, please rethink whether you want to do this. The close button is one of the most fundamental controls in Windows, and overriding its behavior can only be confusing.

2
  • I want to minimize to tray when X pressed, like Skype, instead user could terminate my app when clicked on tray and exit menu in popup menu there. Is there any sample on how can I override WM_SYSCOMMAND and prevent SC_CLOSE message?
    – Adi Shalom
    Jan 17, 2013 at 21:07
  • @AdiShalom, you should be able to capture WM_SYSCOMMAND the same way you add a handler for any other message in MFC. Then just check wParam for SC_CLOSE. Jan 17, 2013 at 21:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.