title: Getting DXGI swapchain by HWND
body: <p>There is a simple application which works as a manager of MS RDP sessions. You open RDP sessions to different computers and then you can see their previews in a common monitoring panel.</p>
  
  <p>An OLE control is used to organize an RDP session.</p>
  
  <pre><code>CWnd::CreateControl(CLSID_MsRdpClient6NotSafeForScripting, ....
  </code></pre>
  
  <p>Previously I just copied RDP window via PrintWindow and then showed it on the preview.</p>
  
  <pre><code>PrintWindow(hWnd, hCompatibleDC,0);
  </code></pre>
  
  <p>In Windows 10 it does not work. Microsoft Spy++ shows the following picture</p>
  
  <pre><code>Window "Output Painter Window" OPContainerClass
     Window "Output Painter Child Window" OPWindowClass (Invisible)
     Window "Output Painter DX Child Window" OPWindowClass 
  </code></pre>
  
  <p>On older Windows "Output Painter Child Window" is mainly visible and in this case PrintWindow works.</p>
  
  <p>Also on Windows 10, RDP does not work at all if I remove DXGI.dll. So I believe that PrintWindow does not work because RDP uses DirectX to draw the window content.</p>
  
  <p>I thought about DirectX function hooking to get the picture but it looks ridiculous. It is a big overhead. I can control the application entirely. I can access the RDP OPWindowClass HWNDs. I can even control them via ShowWindow, etc.</p>
  
  <p>Is there any way to get DirectX objects (like IDXGISwapChain1 or ID2D1HwndRenderTarget) which are connected to HWND?</p>