sashoalm
sashoalm

Reputation: 79447

Why is WM_CLOSE not handled automatically by DefDlgProc?

When I create a dialog using DialogBox, it won't close unless I handle WM_CLOSE in my own DLGPROC function and call EndDialog.

I know that this is by design, but I'm interested why was it chosen for WM_CLOSE not to be handled automatically by DefDlgProc? Are there any good reasons for that?

Upvotes: 3

Views: 617

Answers (1)

Stefan
Stefan

Reputation: 43575

Ask yourself this:

What would the default handling of WM_CLOSE be? Calling EndDialog? I think EndDialog would only work in very rare situations.

Other suggestions:

  • validating user input in the dialog, showing errors if input is out-of-range or otherwise not valid, not ending the dialog
  • closing child windows, releasing resources/memory that child windows of the dialog are using, releasing COM-Objects, basically: cleaning up first and then end the dialog.

Upvotes: 3

Related Questions