StartScreenCapturebyWindowId() not excluding overlapping windows for certain programs (Agora Unity), unity3d, windows

I am trying to setup individual window sharing for a project in Unity for Windows. The way I’m currently going about doing this is by using EnumWindows(), IsVisableWindow(), and GetWindowText() to create a dictionary of window titles and handles, then calling StartScreeCapturebyWindowId() to share the selected window.

This works relatively well for most process; the window of the process and only the window of the process is streamed. However, for certain programs (like Google Chrome, Discord, and Windows Photos) the captured area is set correctly, but overlapping windows are not culled out.

Does anyone know what could be causing this problem? Is there something wrong with the way I’m grabbing the handles for these windows? Or is there something about starting a screen capture that I am missing?

Source: Windows Questions