NO

Author Topic: Sample dialog application  (Read 2556 times)

jmac

  • Guest
Sample dialog application
« on: June 13, 2010, 05:56:33 AM »
The sample wizard that creates a dialog application has an EndDialog() call in both the IDOK (from the Ok button)and the WM_CLOSE from the (default close button) messages, this appears to result in two exit points from the application. Would it be more appropriate to change the EndDialog call in the IDOK section to a SendMessage with a WM_CLOSE so that there is only one exit point

Offline DMac

  • Member
  • *
  • Posts: 272
Re: Sample dialog application
« Reply #1 on: June 21, 2010, 05:53:22 PM »
From the documentation:

Quote
Dialog boxes created by the DialogBox, DialogBoxParam, DialogBoxIndirect, and DialogBoxIndirectParam functions must be destroyed using the EndDialog function. An application calls EndDialog from within the dialog box procedure; the function must not be used for any other purpose.
A dialog box procedure can call EndDialog at any time, even during the processing of the WM_INITDIALOG message. If your application calls the function while WM_INITDIALOG is being processed, the dialog box is destroyed before it is shown and before the input focus is set.

EndDialog does not destroy the dialog box immediately. Instead, it sets a flag and allows the dialog box procedure to return control to the system. The system checks the flag before attempting to retrieve the next message from the application queue. If the flag is set, the system ends the message loop, destroys the dialog box, and uses the value in nResult as the return value from the function that created the dialog box.


There is therefore only one exit point internally.  Not using EndDialog might result in some unfinished business when the window closes.
No one cares how much you know,
until they know how much you care.

jmac

  • Guest
Re: Sample dialog application
« Reply #2 on: June 22, 2010, 04:06:45 AM »
Hi DMac

Seems like you are the only one to answer questions. I was trying some code with the sample dialog created by the wizard and had some variables that were dynamically allocated and I had the free code in the WM_CLOSE event which does not get called if the IDOK button closes the dialog box with and EndDialog. I changed my version to have the IDOK generate a SendMessage with WM_CLOSE that effectively cleaned everythig up, hence the question of whether the sample is correct.

Thanks for the reply.

jmac