I want to implement a text editor from scratch which supports IAccessible interface. I am using MFC and Win32 API.
When the caret position change in the standard text ed
The client would use the SetWinEventHook() function to track the following events of the caret :
If you use a custom control, you need to use NotifyWinEvent() to fire those events yourself, especially EVENT_OBJECT_LOCATIONCHANGE which should trigger the narration.
When the client handle thoses events, it should access the IAccessible interface of the object he's tracking using AccessibleObjectFromEvent().
As you say, Microsoft Active Accessibility would handle this call and send an WM_GETOBJECT message to the corresponding window depending on the handler given to AccessibleObjectFromEvent() (which should be the handler contained in the event).
When you receive the WM_GETOBJECT for the caret you should return the corresponding IAccessible interface which would report the proper accRole and accLocation.
If you're not receiving the right WM_GETOBJECT message it may be because you're not triggering the right events.
You can use the Accessible Event Watcher to check if the right events are sent : http://msdn.microsoft.com/en-us/library/windows/desktop/dd317979%28v=vs.85%29.aspx
See the Developer's Guide for Active Accessibility Servers on MSDN : http://msdn.microsoft.com/en-us/library/windows/desktop/dd318053%28v=vs.85%29.aspx
Edit
Also, if you're using the standard caret provided by Riched20.dll (in a Rich Edit as instance), the documentation stipulate that unlike other UI elements, it does not have an associated window handle.