Hi @paopao ,
I could not verify a supported public API combination for this. The reviewed documentation leaves two relationships unspecified: from a foreign HWND to its live TSF context, and from that context's composition to a separate rendering window.
The TSF accessors do not fill those gaps: TF_GetThreadMgr returns the calling thread's manager, and ITfThreadMgr::GetFocus has no foreign-HWND input. ITfContextView::GetWnd returns the document window, possibly NULL, while ITfCompositionView has no rendering-surface accessor. UI-less mode also does not define a general preedit-HWND accessor; its predefined interfaces cover candidate and reading information.
The IME WinEvents provide lifecycle hints, not a documented composition-to-window binding. The event definitions cover visibility and geometry changes, and WinEventProc identifies the event-generating window/object. Neither specifies which MSCTFIME Composition window belongs to the selected application's current composition. These events may help invalidate an independently established association, but are not documented as complete composition-lifetime notifications.
For cooperation, the first question is which participant knows the rendering relationship. An application can receive composition start, update and end through ITfContextOwnerCompositionSink, but those callbacks do not identify a window rendered by another component. The application would need to either own the rendering or obtain the surface binding through an integration with the participant that knows it. An application-side composition sink alone does not expose the existing Microsoft IME preedit HWND.
If application changes are acceptable, the TSF composition guidance describes using display attributes to render composition within the application's own captured surface. For a cooperating IMM32 application that implements its own composition rendering, WM_IME_COMPOSITION supplies update notifications, and a message with no GCS_ values indicates cancellation; WM_IME_ENDCOMPOSITION signals termination. The WM_IME_SETCONTEXT documentation specifies clearing ISC_SHOWUICOMPOSITIONWINDOW from lParam before forwarding to DefWindowProc or ImmIsUIMessage when the application draws the composition itself. Clearing that flag alone does not implement the rendering. The application would handle its own composition data and lifecycle, and the sharing process would capture the resulting pixels. This is conditional application cooperation, not an external lookup for an unchanged application.
Where the composition surface must stay separate, a proposed cooperation contract could expose the selected document/context identity, a composition generation, its surface, and notifications for termination, focus/context changes, surface replacement and process exit. It would also need to keep that surface valid during capture or coordinate revocation with the capturer, because validating once before asynchronous capture leaves a lifetime race. This is an application-defined design, not a TSF-defined IPC protocol, and it need not expose composition text to the sharing process.
Your IncludeSecondaryWindows=true result remains a separate capture observation. Its documented rules cover window styles, intersection and Z-order, and clip secondary-window pixels outside the main top-level window. They do not supply the composition binding, and the color-window comparison does not identify the cause of the real-IME omission.
Can the selected applications participate in rendering or exposing this association, or must their provider-owned Microsoft IME UI remain unchanged? That determines which cooperation route is available.
If you have any further questions, feel free to ask or leave a comment, and if you found my explanation above was truly helpful or informative to you, I would greatly appreciate it if you could follow this guidance so others with the same issue could benefit as well.
Thank you.