<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
	<channel>
		<title><![CDATA[Серый форум &mdash; AHK: Захват монитора с помощью лупы Magnification API]]></title>
		<link>http://forum.script-coding.com/viewtopic.php?id=17699</link>
		<atom:link href="http://forum.script-coding.com/extern.php?action=feed&amp;tid=17699&amp;type=rss" rel="self" type="application/rss+xml" />
		<description><![CDATA[Недавние сообщения в теме «AHK: Захват монитора с помощью лупы Magnification API».]]></description>
		<lastBuildDate>Sat, 18 Mar 2023 14:39:19 +0000</lastBuildDate>
		<generator>PunBB</generator>
		<item>
			<title><![CDATA[AHK: Захват монитора с помощью лупы Magnification API]]></title>
			<link>http://forum.script-coding.com/viewtopic.php?pid=157226#p157226</link>
			<description><![CDATA[<p><a href="https://learn.microsoft.com/en-us/previous-versions/windows/desktop/magapi/entry-magapi-sdk">https://learn.microsoft.com/en-us/previ … magapi-sdk</a><br />Алгоритм кода был сделан ранее <strong>serzh82saratov</strong> с небольшой моей помощью.<br />Я немного модифицировал его для сохранения рабочего стола в jpg.<br />Это может быть полезно для сохранения реального рабочего стола при использовании оверлеев с аппаратным ускорением, таких как виндовская лупа.<br /></p><div class="codebox"><pre><code>; global captureCursor := true   ; раскомментировать если нужен захват курсора.
; global hwndExclude := [0x1111, 0x2222]   ; массив hwnd окон, исключенных из захвата
OnExit, Uninitialize
setbatchlines -1
return

f11::
savedesktop(&quot;temp&quot;)
return

savedesktop(name)
{
   static hChildMagnifier, RECT, this
   varsetcapacity(this, StrLen(name)+1, 0)
   StrPut(name, &amp;this, &quot;utf-8&quot;)
   if !hChildMagnifier
   {
      Gui, Magnifier: +HWNDhMagnifier +toolwindow -Caption +E0x00080000 +E0x20 ; WS_EX_LAYERED := E0x00080000 WS_EX_TRANSPARENT := E0x20
      DllCall(&quot;LoadLibrary&quot;, &quot;str&quot;, &quot;magnification.dll&quot;)
      DllCall(&quot;magnification.dll\MagInitialize&quot;)
      if (captureCursor = &quot;&quot;)
         captureCursor := 0
      hChildMagnifier := DllCall(&quot;CreateWindowEx&quot;, &quot;uint&quot;, 0, &quot;str&quot;, &quot;Magnifier&quot;, &quot;str&quot;, &quot;MagnifierWindow&quot;, &quot;uint&quot;, (WS_CHILD := 0x40000000)|captureCursor, &quot;int&quot;, 0, &quot;int&quot;, 0, &quot;int&quot;, A_ScreenWidth, &quot;int&quot;, A_ScreenHeight, &quot;uptr&quot;, hMagnifier, &quot;uint&quot;, 0, &quot;ptr&quot;, DllCall(&quot;GetWindowLong&quot; (A_PtrSize=8 ? &quot;Ptr&quot; : &quot;&quot;), &quot;uptr&quot;, hMagnifier, &quot;int&quot;, GWL_HINSTANCE := -6 , &quot;ptr&quot;), &quot;uint&quot;, 0, &quot;ptr&quot;)
      if hwndExclude
      {
         VarSetCapacity(HWNDlist, hwndExclude.Count() * A_PtrSize, 0)
         loop % hwndExclude.Count()
            NumPut(hwndExclude[A_Index], HWNDlist, (A_Index - 1) * A_PtrSize, &quot;ptr&quot;)
         DllCall(&quot;magnification.dll\MagSetWindowFilterList&quot;, &quot;uptr&quot;, hChildMagnifier, &quot;int&quot;, MW_FILTERMODE_EXCLUDE := 0, &quot;int&quot;, hwndExclude.Count(), &quot;ptr&quot;, &amp;HWNDlist)
      }
      matrix := &quot;1|0|0|0|1|0|0|0|1&quot;  
      VarSetCapacity(MAGTRANSFORM, 36, 0)
      loop, parse, matrix, |
         NumPut(A_LoopField, MAGTRANSFORM, (A_Index-1)*4, &quot;float&quot;)
      DllCall(&quot;magnification.dll\MagSetWindowTransform&quot;, &quot;uptr&quot;, hChildMagnifier, &quot;ptr&quot;, &amp;MAGTRANSFORM)
      DllCall(&quot;magnification.dll\MagSetImageScalingCallback&quot;, &quot;uptr&quot;, hChildMagnifier, &quot;ptr&quot;, RegisterCallback(&quot;MagImageScalingCallback&quot;, &quot;Fast&quot;,, &amp;this))
      if (A_PtrSize = 8)
      {
         VarSetCapacity(RECT, 16, 0)
         NumPut(0, RECT, 0, &quot;int&quot;)
         NumPut(0, RECT, 4, &quot;int&quot;)
         NumPut(A_ScreenWidth, RECT, 8, &quot;int&quot;)
         NumPut(A_ScreenHeight, RECT, 12, &quot;int&quot;)
      }
   }
   if (A_PtrSize = 8)
      DllCall(&quot;magnification.dll\MagSetWindowSource&quot;, &quot;uptr&quot;, hChildMagnifier, &quot;ptr&quot;, &amp;RECT)
   else
      DllCall(&quot;magnification.dll\MagSetWindowSource&quot;, &quot;uptr&quot;, hChildMagnifier, &quot;int&quot;, 0, &quot;int&quot;, 0, &quot;int&quot;, A_ScreenWidth, &quot;int&quot;, A_ScreenHeight)
   return
}

MagImageScalingCallback(hwnd, srcdata, srcheader, destdata, destheader, unclipped, clipped, dirty)
{
   static hDC, BITMAPV5HEADER, BITMAPINFO, pCodec, extension := &quot;jpg&quot;
   if !hDC
   {  
      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;)
      VarSetCapacity(BITMAPV5HEADER, 124, 0)
      NumPut(124, BITMAPV5HEADER, 0, &quot;uint&quot;)   ; bV5Size
      NumPut(A_ScreenWidth, BITMAPV5HEADER, 4, &quot;uint&quot;)   ; bV5Width
      NumPut(-A_ScreenHeight, BITMAPV5HEADER, 8, &quot;uint&quot;)   ; bV5Height
      NumPut(1, BITMAPV5HEADER, 12, &quot;short&quot;)   ; bV5Planes
      NumPut(32, BITMAPV5HEADER, 14, &quot;short&quot;)   ; bV5BitCount
      VarSetCapacity(BITMAPINFO, 44, 0)
      NumPut(44, BITMAPINFO, 0, &quot;uint&quot;)   ; biSize
      NumPut(A_ScreenWidth, BITMAPINFO, 4, &quot;uint&quot;)   ; biWidth
      NumPut(-A_ScreenHeight, BITMAPINFO, 8, &quot;UInt&quot;)   ; biHeight
      NumPut(1, BITMAPINFO, 12, &quot;short&quot;)   ; biPlanes
      NumPut(32, BITMAPINFO, 14, &quot;short&quot;)   ; biBitCount
      hDC := DllCall(&quot;GetDC&quot;, &quot;uptr&quot;, hwnd)
   }
   hBitmap := DllCall(&quot;CreateDIBitmap&quot;, &quot;ptr&quot;, hDC, &quot;ptr&quot;, &amp;BITMAPV5HEADER, &quot;uint&quot;, CBM_INIT := 6, &quot;ptr&quot;, srcdata, &quot;ptr&quot;, &amp;BITMAPINFO, &quot;uint&quot;, DIB_RGB_COLORS := 0, &quot;ptr&quot;)
   DllCall(&quot;gdiplus\GdipCreateBitmapFromHBITMAP&quot;, &quot;ptr&quot;, hBitmap, &quot;ptr&quot;, 0, &quot;ptr*&quot;, pBitmap)
   DllCall(&quot;gdiplus\GdipSaveImageToFile&quot;, &quot;ptr&quot;, pBitmap, &quot;wstr&quot;, strget(A_EventInfo, &quot;utf-8&quot;) &quot;.&quot; extension, &quot;ptr&quot;, pCodec, &quot;uint&quot;, 0)
   DllCall(&quot;gdiplus\GdipDisposeImage&quot;, &quot;ptr&quot;, pBitmap)
   DllCall(&quot;DeleteObject&quot;, &quot;ptr&quot;, hBitmap)
   return
}

Uninitialize: 	
DllCall(&quot;magnification.dll\MagUninitialize&quot;)
ExitApp</code></pre></div><p><a href="http://forum.script-coding.com/viewtopic.php?id=17700">Тема для обсуждения</a></p>]]></description>
			<author><![CDATA[null@example.com (Malcev)]]></author>
			<pubDate>Sat, 18 Mar 2023 14:39:19 +0000</pubDate>
			<guid>http://forum.script-coding.com/viewtopic.php?pid=157226#p157226</guid>
		</item>
	</channel>
</rss>
