How do I detect when a Dragon dialog is closed?

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();

pChantPM->ShowDialog(CDMicTraining, m_hWnd);
long exitCode = pChantPM->GetLastError();
    

pChantPM->ShowDialog(CDMicTraining, Handle);
long exitCode = pChantPM->GetLastError();

var exitCode: Integer;
ChantPM1.ShowDialog(CDMicTraining, Handle);
exitCode := ChantPM1.GetLastError();
    

JChantPM1.showDialog(ChantDialog.CDMicTraining, this, "", "");
int exitCode = JChantPM1.getLastError();
    

exitCode = wChantPM1.ShowDialog(CDMicTraining);
    

Dim exitCode as Integer
exitCode = XChantPM1.ShowDialog(CDMicTraining)
        

Dim exitCode As Integer
NChantPM1.ShowDialog(ChantDialog.CDMicTraining, Me.Handle, "", "")
ntVal = nChantPM.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);

// Turn on SRProgress events
pChantSR->RegisterCallback(CCSRProgress);

// Turn on SRProgress events
pChantSR->RegisterCallback(CCSRProgress);

// Turn on SRProgress events
ChantSR1.RegisterCallback(CCSRProgress);

// Turn on SRProgress events
JChantSR1.registerCallback(ChantCallback.CCSRProgress);

// Turn on SRProgress events
WChantSR1.RegisterCallback(CCSRProgress);

' Turn on SRProgress events
XChantSR1.RegisterCallback 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, "");
    }
}

LRESULT CBackupDlg::DefWindowProc(UINT message, WPARAM wParam, LPARAM lParam)
{
	// TODO: Add your specialized code here and/or call the base class
	if (m_pChantSR != NULL)
	{	
		if (message == m_HasEvent)
		{
			CString compilerMsg;
			CString sText;
			CEdit* pEdit = (CEdit* )GetDlgItem(IDC_EDIT1);
			if (pEdit != NULL)
			{
				pEdit->GetWindowTextW(sText);
			}
            // Get the number of events
            int numberOfEvents = m_pChantSR->GetResourceCount(CSREvent, 0, 0);
            for (int i = 0; i < numberOfEvents; i++)
            {
                // Get the event from the event queue
                CChantSREvent* pChantSREvent = m_pChantSR->GetChantSREvent(0);
				switch (pChantSREvent->GetChantCallback())
                {
					case CCSRProgress:
                        {                       
                            // pChantSREvent->GetID() is the ChantDialog constant
                            // pChantSREvent->GetFlags() is the exit code
                            ...
                            break;
                        }
                    default:
                        break;
                }
                // Remove the event from the event queue
                m_pChantSR->RemoveResource(CSREvent, 0, L"");
 				// Delete the C++ wrapper class object
				delete pChantSREvent;
				pChantSREvent = NULL;
           }
		}
	}
	return CDialog::DefWindowProc(message, wParam, lParam);
}
    

void __fastcall TForm1::OnHasEvent(TMessage& msg)
{
	int numberOfEvents = ChantSR1->GetResourceCount(CSREvent,0,0);
	for (int i = 0; i < numberOfEvents; i++)
	{
		// Get the event from the event queue
		CChantSREvent* pEvent = ChantSR1->GetChantSREvent(0);
		switch (pEvent->GetChantCallback())
		{
			default:
				break;
			case CCSRProgress:
                // pEvent->GetID() is the ChantDialog constant
                // pEvent->GetFlags() is the exit code
                ...
				break;
		}
		// Remove the event from the event queue
		ChantSR1->RemoveResource(CSREvent,0);
		delete pEvent;
	}
}

procedure TForm1.OnHasEvent(var msg: TMessage);
var
  aTChantSREvent: TChantSREvent;
  i: Integer;
begin
    numberOfEvents := ChantSR1.GetResourceCount(CSREvent,0,0);
    for i := 0 to numberOfEvents - 1 do
    begin
      // Get the event from the event queue
      aTChantSREvent := ChantSR1.GetChantSREvent(0);
      case tEvent.ChantCallback of
        CCSRProgress:
          begin
              // aTChantSREvent.ID is the ChantDialog constant
              // aTChantSREvent.Flags is the exit code
              ...
          end;
      end;
      // Remove the event from the event queue
      ChantSR1.RemoveResource(CSREvent);
      aTChantSREvent.Destroy();
    end;
end;
    

public void hasEvent(Object obj1, Object obj2)
{
    // Get the event
    JChantSREvent jevent = JChantSR1.getChantSREvent(0);
    if (jevent != null) 
    {
      int callback = jevent.getChantCallback();
      switch(callback)
      {
        default :
          break;
        case ChantCallback.CCSRProgress :                       
          // jevent.getID() is the ChantDialog constant
          // jevent.getFlags() is the exit code
          ...
          break;
      }
    }
    JChantSR1.removeResource(ChantSpeechResource.CSREvent, 0, "");
}
    

    <script  type="text/javascript" language="JavaScript" for="WChantSR1" event="HasEvent"><!--
	var wChantSREvent;
	var chantLM = document.getElementById('WChantSR1');
	// Get the number of events
	numberOfEvents = chantLM.GetResourceCount(CSREvent);
	for (i = 0; i < numberOfEvents; i++)
	{
		// Get the event from the event queue
		wChantSREvent = chantPM.GetResource(CSREvent, 0);
		switch (wChantSREvent.ChantCallback)
        {
            case CCSRProgress:
                {
                    // wChantSREvent.ID is the ChantDialog constant
                    // wChantSREvent.Flags is the exit code
                    ...
                    break;
                }
            default:
                break;
        }
		// Remove the event from the event queue
		chantLM.RemoveResource(CSREvent,  0, "", "", 0);
	}
	//-->
	</script>
    

Private Sub XChantSR1_HasEvent()
  Dim oChantSREvent As XChantSREvent
  
  ' Get the event from the event queue
  Set oChantSREvent = XChantSR1.GetResource(CSREvent, 0)
  ' Process the type of callback event
  Select Case oChantSREvent.ChantCallback
    Case CCSRProgress
        ProgressBar1.Value = oChantSREvent.Progress
        ' oChantSREvent.ID is the ChantDialog constant
        ' oChantSREvent.Flags is the exit code
        ...
    Case Else
  End Select
 
  ' Remove the event from the event queue
  XChantSR1.RemoveResource CSREvent, 0
End Sub
        

Private Sub NChantSR1_HasEvent(ByVal sender As System.Object, ByVal e As Chant.SpeechKit.HasEventArgs) Handles NChantSR1.HasEvent
    Dim I As Integer
    Dim numberOfEvents As Integer
    Dim nChantSREvent As NChantSREvent
    ' Get the number of events
    numberOfEvents = NChantSR1.GetResourceCount(ChantSpeechResource.CSREvent, 0, 0)
    For I = 0 To numberOfEvents - 1
        ' Get the event from the event queue
        nChantSREvent = NChantSR1.GetChantSREvent(0)
        Select Case nChantSREvent.ChantCallback
            Case ChantCallback.CCSRProgress
                ' nChantSREvent.ID is the ChantDialog constant
                ' nChantSREvent.Flags is the exit code
                ...
        End Select
        ' Remove the event from the event queue
        NChantSR1.RemoveResource(ChantSpeechResource.CSREvent, 0, "")
    Next
End Sub