Last changed 1995.02.10
This procedure does not use an OK or Cancel button to close the dialog because the specified action is accomplished before the dialog is closed.
// To trigger some action const ushort cmTVCommand = 100; void TVDialog::doSomething(void) { // Insert your tasks here; messageBox() for // demonstration only messageBox("Doing something", mfInformation | mfOKButton); } // Virtual function: if the event type is a command // which is yours and the dialog is valid void TVDialog::handleEvent(TEvent& event) { TEvent newEvent; if (event.what == evCommand && event.message.command = cmTVCommand && valid(cmOK)) { doSomething(); clearEvent(event); newEvent.what = evCommand; newEvent.message.command = cmOK; newEvent.message.infoPtr = NULL; putEvent(newEvent); return; } TDialog::handleEvent(event); }
Whether or not to put the newEvent event into the event queue could depend on the result from doSomething().
Either way, the next time around you will have performed your tasks (which, by the way, cannot include posting another event -- only one can be posted at a time without processing the other) and handleEvent will get the cmOK command, and treat it normally.