Detecting when Dragon dialogs close

Last reviewed: 10/1/2011

HOW Article ID: H101101

The information in this article applies to:

  • ProfileKit 4
  • SpeechKit 7

Summary

Dragon NatuallySpeaking has a lot of dialogs with which the end user can tailor their environment. In various application scenarios, it would be helpful to know when the dialog was dismissed and if the dialog was successful.

More Information

The ChantPM (ProfileKit) ShowDialog method enables you to launch a variety of dialogs to administer Dragon user settings and preferences. The dialog invocation is modal to your application. Control is not returned to your application until the dialog is dismissed. The Dragon dialog exit code is returned to the application when the dialog is dismissed.

NChantPM1.ShowDialog(ChantDialog.CDMicTraining, this.Handle, "", "");
int exitCode = NChantPM1.GetLastError();

The ChantSR (SpeechKit) ShowDialog method enables you to launch a variety of dialogs to administer Dragon user settings and preferences. The dialog invocation is modeless and control is returned to your application immediately. To know when the dialog is dismissed and to obtain the exit code, register for the ChantCallback event CCSRProgress.

// Turn on SRProgress events
NChantSR1.RegisterCallback(ChantCallback.CCSRProgress);

In your HasEvent handler for this event, you may obtain the ChantDialog constant from the event ID property and the Dragon dialog exitCode value from the event Flags property.

private void NChantSR1_HasEvent(object sender, Chant.SpeechKit.HasEventArgs e)
{
    // Get the number of events
    int numberOfEvents = NChantSR1.GetResourceCount(ChantSpeechResource.CSREvent, 0, 0);
    for (int i = 0; i < numberOfEvents; i++)
    {
        // Get the event from the event queue
        NChantSREvent nChantSREvent = NChantSR1.GetChantSREvent(0);
        switch (nChantSREvent.ChantCallback)
        {
            case ChantCallback.CCSRProgress:
                {
                    progressBar1.Value = nChantSREvent.Progress;                         
                    // nChantSREvent.ID is the ChantDialog constant
                    // nChantSREvent.Flags is the exit code
                    ...
                    break;
                }
            default:
                break;
        }
        // Remove the event from the event queue
        NChantSR1.RemoveResource(ChantSpeechResource.CSREvent, 0, "");
    }
}