Detect when Nuance Dragon is invoked

221 Views Asked by At

I need to know when Nuance Dragon (Naturally Speaking) for Windows has been invoked by a user.

On the Windows platform, the Dragon Assistant pops up after the user says "Hello, Dragon." A small window pops up with the Dragon icon and some text used to address the user.

My app needs to detect when the Dragon Assistant wakes up and goes to sleep. Does Dragon expose any events for this purpose? If not, is it possible to "drill down" into the Dragon Assistant window and detect something that can let me know about this? When using UI Spy, I can see that the Dragon Assistant icon changes and I can also see the text control used for the user prompts, but I need UI Spy to be running under the Adminstrator account to get to these details.

1

There are 1 best solutions below

2
On

You can use Window Events to listen for EVENT_OBJECT_SHOW events:

    SetWinEventHook( EVENT_OBJECT_SHOW, EVENT_OBJECT_SHOW, NULL, MyWinEventProc, 
                     0, 0, WINEVENT_OUTOFCONTEXT | WINEVENT_SKIPOWNPROCESS);

then, in your event proc, you can check to see if the window being shown is the Dragon Assistant:

void CALLBACK MyWinEventProc(
  HWINEVENTHOOK hWinEventHook,
  DWORD event,
  HWND hwnd,
  LONG idObject,
  LONG idChild,
  DWORD dwEventThread,
  DWORD dwmsEventTime
)
{
     if (idObject == OBJID_WINDOW)     // the window itself is being shown
     {
         // compare window class and/or title here
         WCHAR szClass[255];
         if (GetClassName(hwnd, szClass, ARRAYSIZE(szClass)) != 0 &&
             wcscmp(szClass, "WhatEverDragonAssistantClassNameIs") == 0)
         {
             // the Dragon Assistant is showing; notify the rest of your app here
         }
     }
}