<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
	<channel>
		<title><![CDATA[Серый форум &mdash; AHK: Захват окна или монитора с помощью WindowsGraphicsCapture API]]></title>
		<link>http://forum.script-coding.com/viewtopic.php?id=17656</link>
		<atom:link href="http://forum.script-coding.com/extern.php?action=feed&amp;tid=17656&amp;type=rss" rel="self" type="application/rss+xml" />
		<description><![CDATA[Недавние сообщения в теме «AHK: Захват окна или монитора с помощью WindowsGraphicsCapture API».]]></description>
		<lastBuildDate>Fri, 17 Mar 2023 19:07:01 +0000</lastBuildDate>
		<generator>PunBB</generator>
		<item>
			<title><![CDATA[Re: AHK: Захват окна или монитора с помощью WindowsGraphicsCapture API]]></title>
			<link>http://forum.script-coding.com/viewtopic.php?pid=157204#p157204</link>
			<description><![CDATA[<p>Добавил пример с захватом монитора - может быть полезно когда используется лупа, а нужно захватить весь экран.</p>]]></description>
			<author><![CDATA[null@example.com (Malcev)]]></author>
			<pubDate>Fri, 17 Mar 2023 19:07:01 +0000</pubDate>
			<guid>http://forum.script-coding.com/viewtopic.php?pid=157204#p157204</guid>
		</item>
		<item>
			<title><![CDATA[AHK: Захват окна или монитора с помощью WindowsGraphicsCapture API]]></title>
			<link>http://forum.script-coding.com/viewtopic.php?pid=157093#p157093</link>
			<description><![CDATA[<p>Работает на win10 build &gt;= 19041, а также с окнами с аппаратным ускорением.<br /><a href="https://blogs.windows.com/windowsdeveloper/2019/09/16/new-ways-to-do-screen-capture/">https://blogs.windows.com/windowsdevelo … n-capture/</a><br /></p><div class="codebox"><pre><code>window_handle := 0x290538
; captureCursor := true
; hideBorder := true   ; убирает рамку у захватываемого окна, только для winver &gt;= 20348

f11::
DllCall(&quot;QueryPerformanceCounter&quot;, &quot;int64*&quot;, StartTime)
a := a_tickcount
if !init
{
   setbatchlines -1
   DllCall(&quot;LoadLibrary&quot;,&quot;str&quot;,&quot;DXGI&quot;)
   DllCall(&quot;LoadLibrary&quot;,&quot;str&quot;,&quot;D3D11&quot;)
   DllCall(&quot;LoadLibrary&quot;,&quot;str&quot;,&quot;Dwmapi&quot;)
   DllCall(&quot;LoadLibrary&quot;, &quot;str&quot;, &quot;gdiplus&quot;)
   VarSetCapacity(si, A_PtrSize = 8 ? 24 : 16, 0), si := Chr(1)
   DllCall(&quot;gdiplus\GdiplusStartup&quot;, &quot;ptr*&quot;, pToken, &quot;ptr&quot;, &amp;si, &quot;ptr&quot;, 0)
   VarSetCapacity(rect, 16, 0)
   DllCall(&quot;Dwmapi.dll\DwmGetWindowAttribute&quot;, &quot;ptr&quot;, window_handle, &quot;uint&quot;, DWMWA_EXTENDED_FRAME_BOUNDS := 9, &quot;ptr&quot;, &amp;rect, &quot;uint&quot;, 16)
   width := NumGet(rect, 8, &quot;int&quot;) - NumGet(rect, 0, &quot;int&quot;)
   height := NumGet(rect, 12, &quot;int&quot;) - NumGet(rect, 4, &quot;int&quot;)
   DllCall(&quot;D3D11\D3D11CreateDevice&quot;, &quot;ptr&quot;, 0, &quot;int&quot;, D3D_DRIVER_TYPE_HARDWARE := 1, &quot;ptr&quot;, 0, &quot;uint&quot;, D3D11_CREATE_DEVICE_BGRA_SUPPORT := 0x20, &quot;ptr&quot;, 0, &quot;uint&quot;, 0, &quot;uint&quot;, D3D11_SDK_VERSION := 7, &quot;ptr*&quot;, d3d_device, &quot;ptr*&quot;, 0, &quot;ptr*&quot;, d3d_context)
   dxgiDevice := ComObjQuery(d3d_device, IID_IDXGIDevice := &quot;{54ec77fa-1377-44e6-8c32-88fd5f44c84c}&quot;)
   DllCall(&quot;D3D11\CreateDirect3D11DeviceFromDXGIDevice&quot;, &quot;ptr&quot;, dxgiDevice, &quot;ptr*&quot;, inspectable)
   device := ComObjQuery(inspectable, IDirect3DDevice := &quot;{A37624AB-8D5F-4650-9D3E-9EAE3D9BC670}&quot;)
   CreateClass(&quot;Windows.Graphics.Capture.Direct3D11CaptureFramePool&quot;, IDirect3D11CaptureFramePoolStatics := &quot;{7784056a-67aa-4d53-ae54-1088d5a8ca21}&quot;, Direct3D11CaptureFramePoolStatics)
   DllCall(NumGet(NumGet(Direct3D11CaptureFramePoolStatics+0)+6*A_PtrSize), &quot;ptr&quot;, Direct3D11CaptureFramePoolStatics, &quot;ptr&quot;, device, &quot;int&quot;, B8G8R8A8UIntNormalized := 87, &quot;int&quot;, numberOfBuffers := 2, &quot;int64&quot;, (height &lt;&lt; 32) | width, &quot;ptr*&quot;, frame_pool)   ; Direct3D11CaptureFramePool.Create
   CreateClass(&quot;Windows.Graphics.Capture.GraphicsCaptureItem&quot;, IGraphicsCaptureItemStatics := &quot;{A87EBEA5-457C-5788-AB47-0CF1D3637E74}&quot;, GraphicsCaptureItemStatics)
   interop_factory := ComObjQuery(GraphicsCaptureItemStatics, IGraphicsCaptureItemInterop := &quot;{3628E81B-3CAC-4C60-B7F4-23CE0E0C3356}&quot;)
   VarSetCapacity(GUID, 16, 0)
   DllCall(&quot;ole32\CLSIDFromString&quot;, &quot;wstr&quot;, IGraphicsCaptureItem := &quot;{79c3f95b-31f7-4ec2-a464-632ef5d30760}&quot;, &quot;ptr&quot;, &amp;GUID)
   hr := DllCall(NumGet(NumGet(interop_factory+0)+3*A_PtrSize), &quot;ptr&quot;, interop_factory, &quot;ptr&quot;, window_handle, &quot;ptr&quot;, &amp;GUID, &quot;ptr*&quot;, capture_item, &quot;uint&quot;)   ; IGraphicsCaptureItemInterop::CreateForWindow
   if hr
   {
      msgbox Cannot capture such a window.`nError: %hr%
      ExitApp
   }
   DllCall(NumGet(NumGet(frame_pool+0)+10*A_PtrSize), &quot;ptr&quot;, frame_pool, &quot;ptr&quot;, capture_item, &quot;ptr*&quot;, session)   ; Direct3D11CaptureFramePool.CreateCaptureSession
   if (captureCursor != 1)
   {
      session2 := ComObjQuery(session, IGraphicsCaptureSession2 := &quot;{2c39ae40-7d2e-5044-804e-8b6799d4cf9e}&quot;)
      DllCall(NumGet(NumGet(session2+0)+7*A_PtrSize), &quot;ptr&quot;, session2, &quot;int&quot;, 0)   ; GraphicsCaptureSession.IsCursorCaptureEnabled put
   }
   if (hideBorder = 1) and (StrSplit(A_OSVersion, &quot;.&quot;)[3] &gt;= 20348)
   {
      session3 := ComObjQuery(session, IGraphicsCaptureSession3 := &quot;{f2cdd966-22ae-5ea1-9596-3a289344c3be}&quot;)
      DllCall(NumGet(NumGet(session3+0)+7*A_PtrSize), &quot;ptr&quot;, session3, &quot;int&quot;, 0)   ; GraphicsCaptureSession.IsBorderRequired put
   }
   DllCall(NumGet(NumGet(session+0)+6*A_PtrSize), &quot;ptr&quot;, session)   ; GraphicsCaptureSession.StartCapture
}
loop
{
   DllCall(NumGet(NumGet(frame_pool+0)+7*A_PtrSize), &quot;ptr&quot;, frame_pool, &quot;ptr*&quot;, frame)   ; Direct3D11CaptureFramePool.TryGetNextFrame
   if (frame != 0)
   {
      DllCall(NumGet(NumGet(frame+0)+7*A_PtrSize), &quot;ptr&quot;, frame, &quot;int64*&quot;, SystemRelativeTime)   ; Direct3D11CaptureFrame.SystemRelativeTime
      if !init or (SystemRelativeTime &gt;= StartTime)
         break
      Close := ComObjQuery(frame, IClosable := &quot;{30D5A829-7FA4-4026-83BB-D75BAE4EA99E}&quot;)
      DllCall(NumGet(NumGet(Close+0)+6*A_PtrSize), &quot;ptr&quot;, Close)   ; Close
      ObjRelease(Close)
      ObjRelease(frame)
   }
}
if !init
{
   DllCall(NumGet(NumGet(frame+0)+6*A_PtrSize), &quot;ptr&quot;, frame, &quot;ptr*&quot;, surface)   ; Direct3D11CaptureFrame.Surface
   access := ComObjQuery(surface, IDirect3DDxgiInterfaceAccess := &quot;{A9B3D012-3DF2-4EE3-B8D1-8695F457D3C1}&quot;)
   VarSetCapacity(GUID, 16, 0)
   DllCall(&quot;ole32\CLSIDFromString&quot;, &quot;wstr&quot;, IID_ID3D11Texture2D := &quot;{6f15aaf2-d208-4e89-9ab4-489535d34f9c}&quot;, &quot;ptr&quot;, &amp;GUID)
   DllCall(NumGet(NumGet(access+0)+3*A_PtrSize), &quot;ptr&quot;, access, &quot;ptr&quot;, &amp;GUID, &quot;ptr*&quot;, texture)   ; IDirect3DDxgiInterfaceAccess::GetInterface
   VarSetCapacity(captured_texture_desc, 44, 0)
   DllCall(NumGet(NumGet(texture+0)+10*A_PtrSize), &quot;ptr&quot;, texture, &quot;ptr&quot;, &amp;captured_texture_desc)   ; ID3D11Texture2D::GetDesc
   NumPut(D3D11_USAGE_STAGING := 3, captured_texture_desc, 28, &quot;uint&quot;)   ; Usage
   NumPut(0, captured_texture_desc, 32, &quot;uint&quot;)   ; BindFlags
   NumPut(D3D11_CPU_ACCESS_READ := 0x20000, captured_texture_desc, 36, &quot;uint&quot;)   ; CPUAccessFlags
   NumPut(0, captured_texture_desc, 40, &quot;uint&quot;)   ; MiscFlags
   DllCall(NumGet(NumGet(d3d_device+0)+5*A_PtrSize), &quot;ptr&quot;, d3d_device, &quot;ptr&quot;, &amp;captured_texture_desc, &quot;ptr&quot;, 0, &quot;ptr*&quot;, user_texture)   ; ID3D11Device::CreateTexture2D
   init := 1 
}
DllCall(NumGet(NumGet(d3d_context+0)+47*A_PtrSize), &quot;ptr&quot;, d3d_context, &quot;ptr&quot;, user_texture, &quot;ptr&quot;, texture)   ; ID3D11DeviceContext::CopyResource
VarSetCapacity(D3D11_MAPPED_SUBRESOURCE, 8+A_PtrSize, 0)
DllCall(NumGet(NumGet(d3d_context+0)+14*A_PtrSize), &quot;ptr&quot;, d3d_context, &quot;ptr&quot;, user_texture, &quot;uint&quot;, 0, &quot;uint&quot;, D3D11_MAP_READ := 1, &quot;uint&quot;, 0, &quot;ptr&quot;, &amp;D3D11_MAPPED_SUBRESOURCE)   ; ID3D11DeviceContext::Map
pBits := NumGet(D3D11_MAPPED_SUBRESOURCE, 0, &quot;ptr&quot;)
pitch := NumGet(D3D11_MAPPED_SUBRESOURCE, A_PtrSize, &quot;uint&quot;)
msgbox % a_tickcount - a
DllCall(&quot;gdiplus\GdipCreateBitmapFromScan0&quot;, &quot;int&quot;, width, &quot;int&quot;, height, &quot;int&quot;, pitch, &quot;int&quot;, PixelFormat32bppRGB := 0x22009, &quot;ptr&quot;, pBits, &quot;ptr*&quot;, pBitmap)
DllCall(&quot;gdiplus\GdipCreateHBITMAPFromBitmap&quot;, &quot;ptr&quot;, pBitmap, &quot;ptr*&quot;, hBitmap, &quot;uint&quot;, 0xffffffff)
Gui, Destroy
Gui, Add, Picture, vpic, HBITMAP:%hBitmap%
Gui, Show
DllCall(&quot;gdiplus\GdipDisposeImage&quot;, &quot;ptr&quot;, pBitmap)
DllCall(&quot;DeleteObject&quot;, &quot;ptr&quot;, hBitmap)
DllCall(NumGet(NumGet(d3d_context+0)+15*A_PtrSize), &quot;ptr&quot;, d3d_context, &quot;ptr&quot;, user_texture, &quot;uint&quot;, 0)   ; ID3D11DeviceContext::Unmap
Close := ComObjQuery(frame, IClosable := &quot;{30D5A829-7FA4-4026-83BB-D75BAE4EA99E}&quot;)
DllCall(NumGet(NumGet(Close+0)+6*A_PtrSize), &quot;ptr&quot;, Close)   ; Close
ObjRelease(Close)
ObjRelease(frame)
return



CreateClass(string, interface, ByRef Class)
{
   CreateHString(string, hString)
   VarSetCapacity(GUID, 16)
   DllCall(&quot;ole32\CLSIDFromString&quot;, &quot;wstr&quot;, interface, &quot;ptr&quot;, &amp;GUID)
   result := DllCall(&quot;Combase.dll\RoGetActivationFactory&quot;, &quot;ptr&quot;, hString, &quot;ptr&quot;, &amp;GUID, &quot;ptr*&quot;, Class, &quot;uint&quot;)
   if (result != 0)
   {
      if (result = 0x80004002)
         msgbox No such interface supported
      else if (result = 0x80040154)
         msgbox Class not registered
      else
         msgbox error: %result%
      ExitApp
   }
   DeleteHString(hString)
}

CreateHString(string, ByRef hString)
{
    DllCall(&quot;Combase.dll\WindowsCreateString&quot;, &quot;wstr&quot;, string, &quot;uint&quot;, StrLen(string), &quot;ptr*&quot;, hString)
}

DeleteHString(hString)
{
   DllCall(&quot;Combase.dll\WindowsDeleteString&quot;, &quot;ptr&quot;, hString)
}</code></pre></div><p>Пример с захватом разных активных окон (медленно): <br /></p><div class="codebox"><pre><code>; captureCursor := true
; hideBorder := true   ; убирает рамку у захватываемого окна, только для winver &gt;= 20348

f11::
if !init
{
   setbatchlines -1
   DllCall(&quot;LoadLibrary&quot;,&quot;str&quot;,&quot;DXGI&quot;)
   DllCall(&quot;LoadLibrary&quot;,&quot;str&quot;,&quot;D3D11&quot;)
   DllCall(&quot;LoadLibrary&quot;,&quot;str&quot;,&quot;Dwmapi&quot;)
   DllCall(&quot;LoadLibrary&quot;, &quot;str&quot;, &quot;gdiplus&quot;)
   VarSetCapacity(si, A_PtrSize = 8 ? 24 : 16, 0), si := Chr(1)
   DllCall(&quot;gdiplus\GdiplusStartup&quot;, &quot;ptr*&quot;, pToken, &quot;ptr&quot;, &amp;si, &quot;ptr&quot;, 0)
   DllCall(&quot;D3D11\D3D11CreateDevice&quot;, &quot;ptr&quot;, 0, &quot;int&quot;, D3D_DRIVER_TYPE_HARDWARE := 1, &quot;ptr&quot;, 0, &quot;uint&quot;, D3D11_CREATE_DEVICE_BGRA_SUPPORT := 0x20, &quot;ptr&quot;, 0, &quot;uint&quot;, 0, &quot;uint&quot;, D3D11_SDK_VERSION := 7, &quot;ptr*&quot;, d3d_device, &quot;ptr*&quot;, 0, &quot;ptr*&quot;, d3d_context)
   dxgiDevice := ComObjQuery(d3d_device, IID_IDXGIDevice := &quot;{54ec77fa-1377-44e6-8c32-88fd5f44c84c}&quot;)
   DllCall(&quot;D3D11\CreateDirect3D11DeviceFromDXGIDevice&quot;, &quot;ptr&quot;, dxgiDevice, &quot;ptr*&quot;, inspectable)
   device := ComObjQuery(inspectable, IDirect3DDevice := &quot;{A37624AB-8D5F-4650-9D3E-9EAE3D9BC670}&quot;)
   CreateClass(&quot;Windows.Graphics.Capture.Direct3D11CaptureFramePool&quot;, IDirect3D11CaptureFramePoolStatics := &quot;{7784056a-67aa-4d53-ae54-1088d5a8ca21}&quot;, Direct3D11CaptureFramePoolStatics)
   CreateClass(&quot;Windows.Graphics.Capture.GraphicsCaptureItem&quot;, IGraphicsCaptureItemStatics := &quot;{A87EBEA5-457C-5788-AB47-0CF1D3637E74}&quot;, GraphicsCaptureItemStatics)
   interop_factory := ComObjQuery(GraphicsCaptureItemStatics, IGraphicsCaptureItemInterop := &quot;{3628E81B-3CAC-4C60-B7F4-23CE0E0C3356}&quot;)
   VarSetCapacity(GraphicsCaptureItemGUID, 16, 0)
   DllCall(&quot;ole32\CLSIDFromString&quot;, &quot;wstr&quot;, IGraphicsCaptureItem := &quot;{79c3f95b-31f7-4ec2-a464-632ef5d30760}&quot;, &quot;ptr&quot;, &amp;GraphicsCaptureItemGUID)
   VarSetCapacity(D3D11Texture2DGUID, 16, 0)
   DllCall(&quot;ole32\CLSIDFromString&quot;, &quot;wstr&quot;, IID_ID3D11Texture2D := &quot;{6f15aaf2-d208-4e89-9ab4-489535d34f9c}&quot;, &quot;ptr&quot;, &amp;D3D11Texture2DGUID)
   init := 1
}
window_handle := WinExist(&quot;A&quot;)
VarSetCapacity(rect, 16, 0)
DllCall(&quot;Dwmapi.dll\DwmGetWindowAttribute&quot;, &quot;ptr&quot;, window_handle, &quot;uint&quot;, DWMWA_EXTENDED_FRAME_BOUNDS := 9, &quot;ptr&quot;, &amp;rect, &quot;uint&quot;, 16)
width := NumGet(rect, 8, &quot;int&quot;) - NumGet(rect, 0, &quot;int&quot;)
height := NumGet(rect, 12, &quot;int&quot;) - NumGet(rect, 4, &quot;int&quot;)
DllCall(NumGet(NumGet(Direct3D11CaptureFramePoolStatics+0)+6*A_PtrSize), &quot;ptr&quot;, Direct3D11CaptureFramePoolStatics, &quot;ptr&quot;, device, &quot;int&quot;, B8G8R8A8UIntNormalized := 87, &quot;int&quot;, numberOfBuffers := 2, &quot;int64&quot;, (height &lt;&lt; 32) | width, &quot;ptr*&quot;, frame_pool)   ; Direct3D11CaptureFramePool.Create
hr := DllCall(NumGet(NumGet(interop_factory+0)+3*A_PtrSize), &quot;ptr&quot;, interop_factory, &quot;ptr&quot;, window_handle, &quot;ptr&quot;, &amp;GraphicsCaptureItemGUID, &quot;ptr*&quot;, capture_item, &quot;uint&quot;)   ; IGraphicsCaptureItemInterop::CreateForWindow
if hr
{
   msgbox Cannot capture such a window.`nError: %hr%
   ObjReleaseClose(frame_pool)
   return
}
DllCall(NumGet(NumGet(frame_pool+0)+10*A_PtrSize), &quot;ptr&quot;, frame_pool, &quot;ptr&quot;, capture_item, &quot;ptr*&quot;, session)   ; Direct3D11CaptureFramePool.CreateCaptureSession
if (captureCursor != 1)
{
   session2 := ComObjQuery(session, IGraphicsCaptureSession2 := &quot;{2c39ae40-7d2e-5044-804e-8b6799d4cf9e}&quot;)
   DllCall(NumGet(NumGet(session2+0)+7*A_PtrSize), &quot;ptr&quot;, session2, &quot;int&quot;, 0)   ; GraphicsCaptureSession.IsCursorCaptureEnabled put
}
if (hideBorder = 1) and (StrSplit(A_OSVersion, &quot;.&quot;)[3] &gt;= 20348)
{
   session3 := ComObjQuery(session, IGraphicsCaptureSession3 := &quot;{f2cdd966-22ae-5ea1-9596-3a289344c3be}&quot;)
   DllCall(NumGet(NumGet(session3+0)+7*A_PtrSize), &quot;ptr&quot;, session3, &quot;int&quot;, 0)   ; GraphicsCaptureSession.IsBorderRequired put
}
DllCall(NumGet(NumGet(session+0)+6*A_PtrSize), &quot;ptr&quot;, session)   ; GraphicsCaptureSession.StartCapture
loop
{
   DllCall(NumGet(NumGet(frame_pool+0)+7*A_PtrSize), &quot;ptr&quot;, frame_pool, &quot;ptr*&quot;, frame)   ; Direct3D11CaptureFramePool.TryGetNextFrame
   if (frame != 0)
      break
}
DllCall(NumGet(NumGet(frame+0)+6*A_PtrSize), &quot;ptr&quot;, frame, &quot;ptr*&quot;, surface)   ; Direct3D11CaptureFrame.Surface
access := ComObjQuery(surface, IDirect3DDxgiInterfaceAccess := &quot;{A9B3D012-3DF2-4EE3-B8D1-8695F457D3C1}&quot;)
DllCall(NumGet(NumGet(access+0)+3*A_PtrSize), &quot;ptr&quot;, access, &quot;ptr&quot;, &amp;D3D11Texture2DGUID, &quot;ptr*&quot;, texture)   ; IDirect3DDxgiInterfaceAccess::GetInterface
VarSetCapacity(captured_texture_desc, 44, 0)
DllCall(NumGet(NumGet(texture+0)+10*A_PtrSize), &quot;ptr&quot;, texture, &quot;ptr&quot;, &amp;captured_texture_desc)   ; ID3D11Texture2D::GetDesc
NumPut(D3D11_USAGE_STAGING := 3, captured_texture_desc, 28, &quot;uint&quot;)   ; Usage
NumPut(0, captured_texture_desc, 32, &quot;uint&quot;)   ; BindFlags
NumPut(D3D11_CPU_ACCESS_READ := 0x20000, captured_texture_desc, 36, &quot;uint&quot;)   ; CPUAccessFlags
NumPut(0, captured_texture_desc, 40, &quot;uint&quot;)   ; MiscFlags
DllCall(NumGet(NumGet(d3d_device+0)+5*A_PtrSize), &quot;ptr&quot;, d3d_device, &quot;ptr&quot;, &amp;captured_texture_desc, &quot;ptr&quot;, 0, &quot;ptr*&quot;, user_texture)   ; ID3D11Device::CreateTexture2D
DllCall(NumGet(NumGet(d3d_context+0)+47*A_PtrSize), &quot;ptr&quot;, d3d_context, &quot;ptr&quot;, user_texture, &quot;ptr&quot;, texture)   ; ID3D11DeviceContext::CopyResource
VarSetCapacity(D3D11_MAPPED_SUBRESOURCE, 8+A_PtrSize, 0)
DllCall(NumGet(NumGet(d3d_context+0)+14*A_PtrSize), &quot;ptr&quot;, d3d_context, &quot;ptr&quot;, user_texture, &quot;uint&quot;, 0, &quot;uint&quot;, D3D11_MAP_READ := 1, &quot;uint&quot;, 0, &quot;ptr&quot;, &amp;D3D11_MAPPED_SUBRESOURCE)   ; ID3D11DeviceContext::Map
pBits := NumGet(D3D11_MAPPED_SUBRESOURCE, 0, &quot;ptr&quot;)
pitch := NumGet(D3D11_MAPPED_SUBRESOURCE, A_PtrSize, &quot;uint&quot;)
DllCall(&quot;gdiplus\GdipCreateBitmapFromScan0&quot;, &quot;int&quot;, width, &quot;int&quot;, height, &quot;int&quot;, pitch, &quot;int&quot;, PixelFormat32bppRGB := 0x22009, &quot;ptr&quot;, pBits, &quot;ptr*&quot;, pBitmap)
DllCall(&quot;gdiplus\GdipCreateHBITMAPFromBitmap&quot;, &quot;ptr&quot;, pBitmap, &quot;ptr*&quot;, hBitmap, &quot;uint&quot;, 0xffffffff)
Gui, Destroy
Gui, Add, Picture, vpic, HBITMAP:%hBitmap%
Gui, Show
DllCall(&quot;gdiplus\GdipDisposeImage&quot;, &quot;ptr&quot;, pBitmap)
DllCall(&quot;DeleteObject&quot;, &quot;ptr&quot;, hBitmap)
DllCall(NumGet(NumGet(d3d_context+0)+15*A_PtrSize), &quot;ptr&quot;, d3d_context, &quot;ptr&quot;, user_texture, &quot;uint&quot;, 0)   ; ID3D11DeviceContext::Unmap
ObjReleaseClose(frame_pool)
ObjRelease(capture_item)
ObjReleaseClose(session)
if session2
{
   ObjReleaseClose(session2)
   session2 := &quot;&quot;
}
if session3
{
   ObjReleaseClose(session3)
   session3 := &quot;&quot;
}
ObjReleaseClose(frame)
ObjReleaseClose(surface)
ObjReleaseClose(access)
ObjRelease(texture)
ObjRelease(user_texture)
return



CreateClass(string, interface, ByRef Class)
{
   CreateHString(string, hString)
   VarSetCapacity(GUID, 16)
   DllCall(&quot;ole32\CLSIDFromString&quot;, &quot;wstr&quot;, interface, &quot;ptr&quot;, &amp;GUID)
   result := DllCall(&quot;Combase.dll\RoGetActivationFactory&quot;, &quot;ptr&quot;, hString, &quot;ptr&quot;, &amp;GUID, &quot;ptr*&quot;, Class, &quot;uint&quot;)
   if (result != 0)
   {
      if (result = 0x80004002)
         msgbox No such interface supported
      else if (result = 0x80040154)
         msgbox Class not registered
      else
         msgbox error: %result%
      ExitApp
   }
   DeleteHString(hString)
}

CreateHString(string, ByRef hString)
{
    DllCall(&quot;Combase.dll\WindowsCreateString&quot;, &quot;wstr&quot;, string, &quot;uint&quot;, StrLen(string), &quot;ptr*&quot;, hString)
}

DeleteHString(hString)
{
   DllCall(&quot;Combase.dll\WindowsDeleteString&quot;, &quot;ptr&quot;, hString)
}

ObjReleaseClose(ByRef Object)
{
   Close := ComObjQuery(Object, IClosable := &quot;{30D5A829-7FA4-4026-83BB-D75BAE4EA99E}&quot;)
   DllCall(NumGet(NumGet(Close+0)+6*A_PtrSize), &quot;ptr&quot;, Close)   ; Close
   ObjRelease(Close)
   ObjRelease(Object)
   Object := &quot;&quot;
}</code></pre></div><p>Пример сохранения монитора:<br /></p><div class="codebox"><pre><code>hMonitor := DllCall(&quot;MonitorFromPoint&quot;, &quot;int64&quot;, 0, &quot;uint&quot;, MONITOR_DEFAULTTOPRIMARY := 1, &quot;ptr&quot;)
width := a_screenwidth
height := a_screenheight
extension := &quot;jpg&quot;
filename := &quot;test&quot;
; captureCursor := true
; hideBorder := true   ; убирает рамку у захватываемого окна, только для winver &gt;= 20348
return

f11::
DllCall(&quot;QueryPerformanceCounter&quot;, &quot;int64*&quot;, StartTime)
if !init
{
   setbatchlines -1
   DllCall(&quot;LoadLibrary&quot;,&quot;str&quot;,&quot;DXGI&quot;)
   DllCall(&quot;LoadLibrary&quot;,&quot;str&quot;,&quot;D3D11&quot;)
   DllCall(&quot;LoadLibrary&quot;, &quot;str&quot;, &quot;gdiplus&quot;)
   VarSetCapacity(si, A_PtrSize = 8 ? 24 : 16, 0), si := Chr(1)
   DllCall(&quot;gdiplus\GdiplusStartup&quot;, &quot;ptr*&quot;, pToken, &quot;ptr&quot;, &amp;si, &quot;ptr&quot;, 0)
   DllCall(&quot;gdiplus\GdipGetImageEncodersSize&quot;, &quot;uint*&quot;, count:=0, &quot;uint*&quot;, size:=0)
   VarSetCapacity(ci, size)
   DllCall(&quot;gdiplus\GdipGetImageEncoders&quot;, &quot;uint&quot;, count, &quot;uint&quot;, size, &quot;ptr&quot;, &amp;ci)
   if !(count &amp;&amp; size)
      throw Exception(&quot;Could not get a list of image codec encoders on this system.&quot;)
   Loop % count
      EncoderExtensions := StrGet(NumGet(ci, (idx:=(48+7*A_PtrSize)*(A_Index-1))+32+3*A_PtrSize, &quot;uptr&quot;), &quot;UTF-16&quot;)
         until InStr(EncoderExtensions, &quot;*.&quot; extension)
   if !(pCodec := &amp;ci + idx)
      throw Exception(&quot;Could not find a matching encoder for the specified file format.&quot;)

   DllCall(&quot;D3D11\D3D11CreateDevice&quot;, &quot;ptr&quot;, 0, &quot;int&quot;, D3D_DRIVER_TYPE_HARDWARE := 1, &quot;ptr&quot;, 0, &quot;uint&quot;, D3D11_CREATE_DEVICE_BGRA_SUPPORT := 0x20, &quot;ptr&quot;, 0, &quot;uint&quot;, 0, &quot;uint&quot;, D3D11_SDK_VERSION := 7, &quot;ptr*&quot;, d3d_device, &quot;ptr*&quot;, 0, &quot;ptr*&quot;, d3d_context)
   dxgiDevice := ComObjQuery(d3d_device, IID_IDXGIDevice := &quot;{54ec77fa-1377-44e6-8c32-88fd5f44c84c}&quot;)
   DllCall(&quot;D3D11\CreateDirect3D11DeviceFromDXGIDevice&quot;, &quot;ptr&quot;, dxgiDevice, &quot;ptr*&quot;, inspectable)
   device := ComObjQuery(inspectable, IDirect3DDevice := &quot;{A37624AB-8D5F-4650-9D3E-9EAE3D9BC670}&quot;)
   CreateClass(&quot;Windows.Graphics.Capture.Direct3D11CaptureFramePool&quot;, IDirect3D11CaptureFramePoolStatics := &quot;{7784056a-67aa-4d53-ae54-1088d5a8ca21}&quot;, Direct3D11CaptureFramePoolStatics)
   DllCall(NumGet(NumGet(Direct3D11CaptureFramePoolStatics+0)+6*A_PtrSize), &quot;ptr&quot;, Direct3D11CaptureFramePoolStatics, &quot;ptr&quot;, device, &quot;int&quot;, B8G8R8A8UIntNormalized := 87, &quot;int&quot;, numberOfBuffers := 2, &quot;int64&quot;, (height &lt;&lt; 32) | width, &quot;ptr*&quot;, frame_pool)   ; Direct3D11CaptureFramePool.Create
   CreateClass(&quot;Windows.Graphics.Capture.GraphicsCaptureItem&quot;, IGraphicsCaptureItemStatics := &quot;{A87EBEA5-457C-5788-AB47-0CF1D3637E74}&quot;, GraphicsCaptureItemStatics)
   interop_factory := ComObjQuery(GraphicsCaptureItemStatics, IGraphicsCaptureItemInterop := &quot;{3628E81B-3CAC-4C60-B7F4-23CE0E0C3356}&quot;)
   VarSetCapacity(GUID, 16, 0)
   DllCall(&quot;ole32\CLSIDFromString&quot;, &quot;wstr&quot;, IGraphicsCaptureItem := &quot;{79c3f95b-31f7-4ec2-a464-632ef5d30760}&quot;, &quot;ptr&quot;, &amp;GUID)
   DllCall(NumGet(NumGet(interop_factory+0)+4*A_PtrSize), &quot;ptr&quot;, interop_factory, &quot;ptr&quot;, hMonitor, &quot;ptr&quot;, &amp;GUID, &quot;ptr*&quot;, capture_item)   ; IGraphicsCaptureItemInterop::CreateForMonitor
   DllCall(NumGet(NumGet(frame_pool+0)+10*A_PtrSize), &quot;ptr&quot;, frame_pool, &quot;ptr&quot;, capture_item, &quot;ptr*&quot;, session)   ; Direct3D11CaptureFramePool.CreateCaptureSession
   if (captureCursor != 1)
   {
      session2 := ComObjQuery(session, IGraphicsCaptureSession2 := &quot;{2c39ae40-7d2e-5044-804e-8b6799d4cf9e}&quot;)
      DllCall(NumGet(NumGet(session2+0)+7*A_PtrSize), &quot;ptr&quot;, session2, &quot;int&quot;, 0)   ; GraphicsCaptureSession.IsCursorCaptureEnabled put
   }
   if (hideBorder = 1) and (StrSplit(A_OSVersion, &quot;.&quot;)[3] &gt;= 20348)
   {
      session3 := ComObjQuery(session, IGraphicsCaptureSession3 := &quot;{f2cdd966-22ae-5ea1-9596-3a289344c3be}&quot;)
      DllCall(NumGet(NumGet(session3+0)+7*A_PtrSize), &quot;ptr&quot;, session3, &quot;int&quot;, 0)   ; GraphicsCaptureSession.IsBorderRequired put
   }
   DllCall(NumGet(NumGet(session+0)+6*A_PtrSize), &quot;ptr&quot;, session)   ; GraphicsCaptureSession.StartCapture
}
loop
{
   DllCall(NumGet(NumGet(frame_pool+0)+7*A_PtrSize), &quot;ptr&quot;, frame_pool, &quot;ptr*&quot;, frame)   ; Direct3D11CaptureFramePool.TryGetNextFrame
   if (frame != 0)
   {
      DllCall(NumGet(NumGet(frame+0)+7*A_PtrSize), &quot;ptr&quot;, frame, &quot;int64*&quot;, SystemRelativeTime)   ; Direct3D11CaptureFrame.SystemRelativeTime
      if !init or (SystemRelativeTime &gt;= StartTime)
         break
      Close := ComObjQuery(frame, IClosable := &quot;{30D5A829-7FA4-4026-83BB-D75BAE4EA99E}&quot;)
      DllCall(NumGet(NumGet(Close+0)+6*A_PtrSize), &quot;ptr&quot;, Close)   ; Close
      ObjRelease(Close)
      ObjRelease(frame)
   }
}
if !init
{
   DllCall(NumGet(NumGet(frame+0)+6*A_PtrSize), &quot;ptr&quot;, frame, &quot;ptr*&quot;, surface)   ; Direct3D11CaptureFrame.Surface
   access := ComObjQuery(surface, IDirect3DDxgiInterfaceAccess := &quot;{A9B3D012-3DF2-4EE3-B8D1-8695F457D3C1}&quot;)
   VarSetCapacity(GUID, 16, 0)
   DllCall(&quot;ole32\CLSIDFromString&quot;, &quot;wstr&quot;, IID_ID3D11Texture2D := &quot;{6f15aaf2-d208-4e89-9ab4-489535d34f9c}&quot;, &quot;ptr&quot;, &amp;GUID)
   DllCall(NumGet(NumGet(access+0)+3*A_PtrSize), &quot;ptr&quot;, access, &quot;ptr&quot;, &amp;GUID, &quot;ptr*&quot;, texture)   ; IDirect3DDxgiInterfaceAccess::GetInterface
   VarSetCapacity(captured_texture_desc, 44, 0)
   DllCall(NumGet(NumGet(texture+0)+10*A_PtrSize), &quot;ptr&quot;, texture, &quot;ptr&quot;, &amp;captured_texture_desc)   ; ID3D11Texture2D::GetDesc
   NumPut(D3D11_USAGE_STAGING := 3, captured_texture_desc, 28, &quot;uint&quot;)   ; Usage
   NumPut(0, captured_texture_desc, 32, &quot;uint&quot;)   ; BindFlags
   NumPut(D3D11_CPU_ACCESS_READ := 0x20000, captured_texture_desc, 36, &quot;uint&quot;)   ; CPUAccessFlags
   NumPut(0, captured_texture_desc, 40, &quot;uint&quot;)   ; MiscFlags
   DllCall(NumGet(NumGet(d3d_device+0)+5*A_PtrSize), &quot;ptr&quot;, d3d_device, &quot;ptr&quot;, &amp;captured_texture_desc, &quot;ptr&quot;, 0, &quot;ptr*&quot;, user_texture)   ; ID3D11Device::CreateTexture2D
   init := 1 
}
DllCall(NumGet(NumGet(d3d_context+0)+47*A_PtrSize), &quot;ptr&quot;, d3d_context, &quot;ptr&quot;, user_texture, &quot;ptr&quot;, texture)   ; ID3D11DeviceContext::CopyResource
VarSetCapacity(D3D11_MAPPED_SUBRESOURCE, 8+A_PtrSize, 0)
DllCall(NumGet(NumGet(d3d_context+0)+14*A_PtrSize), &quot;ptr&quot;, d3d_context, &quot;ptr&quot;, user_texture, &quot;uint&quot;, 0, &quot;uint&quot;, D3D11_MAP_READ := 1, &quot;uint&quot;, 0, &quot;ptr&quot;, &amp;D3D11_MAPPED_SUBRESOURCE)   ; ID3D11DeviceContext::Map
pBits := NumGet(D3D11_MAPPED_SUBRESOURCE, 0, &quot;ptr&quot;)
pitch := NumGet(D3D11_MAPPED_SUBRESOURCE, A_PtrSize, &quot;uint&quot;)
DllCall(&quot;gdiplus\GdipCreateBitmapFromScan0&quot;, &quot;int&quot;, width, &quot;int&quot;, height, &quot;int&quot;, pitch, &quot;int&quot;, PixelFormat32bppRGB := 0x22009, &quot;ptr&quot;, pBits, &quot;ptr*&quot;, pBitmap)
DllCall(&quot;gdiplus\GdipSaveImageToFile&quot;, &quot;ptr&quot;, pBitmap, &quot;wstr&quot;, filename &quot;.&quot; extension, &quot;ptr&quot;, pCodec, &quot;uint&quot;, 0)
DllCall(&quot;gdiplus\GdipDisposeImage&quot;, &quot;ptr&quot;, pBitmap)
DllCall(NumGet(NumGet(d3d_context+0)+15*A_PtrSize), &quot;ptr&quot;, d3d_context, &quot;ptr&quot;, user_texture, &quot;uint&quot;, 0)   ; ID3D11DeviceContext::Unmap
Close := ComObjQuery(frame, IClosable := &quot;{30D5A829-7FA4-4026-83BB-D75BAE4EA99E}&quot;)
DllCall(NumGet(NumGet(Close+0)+6*A_PtrSize), &quot;ptr&quot;, Close)   ; Close
ObjRelease(Close)
ObjRelease(frame)
return



CreateClass(string, interface, ByRef Class)
{
   CreateHString(string, hString)
   VarSetCapacity(GUID, 16)
   DllCall(&quot;ole32\CLSIDFromString&quot;, &quot;wstr&quot;, interface, &quot;ptr&quot;, &amp;GUID)
   result := DllCall(&quot;Combase.dll\RoGetActivationFactory&quot;, &quot;ptr&quot;, hString, &quot;ptr&quot;, &amp;GUID, &quot;ptr*&quot;, Class, &quot;uint&quot;)
   if (result != 0)
   {
      if (result = 0x80004002)
         msgbox No such interface supported
      else if (result = 0x80040154)
         msgbox Class not registered
      else
         msgbox error: %result%
      ExitApp
   }
   DeleteHString(hString)
}

CreateHString(string, ByRef hString)
{
    DllCall(&quot;Combase.dll\WindowsCreateString&quot;, &quot;wstr&quot;, string, &quot;uint&quot;, StrLen(string), &quot;ptr*&quot;, hString)
}

DeleteHString(hString)
{
   DllCall(&quot;Combase.dll\WindowsDeleteString&quot;, &quot;ptr&quot;, hString)
}</code></pre></div><p><a href="http://forum.script-coding.com/viewtopic.php?id=16694">Тема для обсуждения</a></p>]]></description>
			<author><![CDATA[null@example.com (Malcev)]]></author>
			<pubDate>Sun, 12 Mar 2023 02:22:34 +0000</pubDate>
			<guid>http://forum.script-coding.com/viewtopic.php?pid=157093#p157093</guid>
		</item>
	</channel>
</rss>
