2

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.

Eric Brown
  • 13,774
  • 7
  • 30
  • 71
gonzobrains
  • 7,856
  • 14
  • 81
  • 132

1 Answers1

2

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
         }
     }
}
Eric Brown
  • 13,774
  • 7
  • 30
  • 71
  • I can surely try this, but I think it may not work because this window is set to "always on top" and UI Spy says it is always visible. I think they app is performing some trickery to make it transparent when not in use and is not actually changing the z order. – gonzobrains Jul 10 '13 at 19:27
  • 1
    @gonzobrains - I don't know what the window looks like, but the layered window apis only affect the client area, not the non-client area; setting the window transparent would leave a rectangle. (Of course, this might not prevent them from doing even more trickery to remove the non-client area...) Spy++ would be helpful to show the window styles & class name. – Eric Brown Jul 10 '13 at 20:05