<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
	<title type="html"><![CDATA[Серый форум &mdash; AHK: Скриншот активного/неактивного окна в полноэкранном режиме]]></title>
	<link rel="self" href="http://forum.script-coding.com/extern.php?action=feed&amp;tid=14473&amp;type=atom" />
	<updated>2019-01-07T21:49:53Z</updated>
	<generator>PunBB</generator>
	<id>http://forum.script-coding.com/viewtopic.php?id=14473</id>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Скриншот активного/неактивного окна в полноэкранном режиме]]></title>
			<link rel="alternate" href="http://forum.script-coding.com/viewtopic.php?pid=130909#p130909" />
			<content type="html"><![CDATA[<p><a href="http://forum.script-coding.com/viewtopic.php?id=12962">http://forum.script-coding.com/viewtopic.php?id=12962</a></p>]]></content>
			<author>
				<name><![CDATA[Malcev]]></name>
				<uri>http://forum.script-coding.com/profile.php?id=26930</uri>
			</author>
			<updated>2019-01-07T21:49:53Z</updated>
			<id>http://forum.script-coding.com/viewtopic.php?pid=130909#p130909</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[AHK: Скриншот активного/неактивного окна в полноэкранном режиме]]></title>
			<link rel="alternate" href="http://forum.script-coding.com/viewtopic.php?pid=130883#p130883" />
			<content type="html"><![CDATA[<p>Делаю скриншот таким способом:<br /></p><div class="codebox"><pre><code>SaveScreenshotToFile(x, y, w, h, filePath)  {
   hBitmap := GetHBitmapFromScreen(x, y, w, h)
   gdip := new GDIplus
   pBitmap := gdip.BitmapFromHBitmap(hBitmap)
   DllCall(&quot;DeleteObject&quot;, Ptr, hBitmap)
   gdip.SaveBitmapToFile(pBitmap, filePath)
   gdip.DisposeImage(pBitmap)
}

GetHBitmapFromScreen(x, y, w, h)  {
   ; hDC1 := DllCall(&quot;GetForegroundWindow&quot;)
   ; hDC1 := DllCall(&quot;FindWindowA&quot;, )
   ; hDC := DllCall(&quot;GetDC&quot;, Ptr, hDC1, Ptr)
   hDC := DllCall(&quot;GetDC&quot;, Ptr, 0, Ptr)
   hBM := DllCall(&quot;CreateCompatibleBitmap&quot;, Ptr, hDC, Int, w, Int, h, Ptr)
   pDC := DllCall(&quot;CreateCompatibleDC&quot;, Ptr, hDC, Ptr)
   oBM := DllCall(&quot;SelectObject&quot;, Ptr, pDC, Ptr, hBM, Ptr)
   DllCall(&quot;BitBlt&quot;, Ptr, pDC, Int, 0, Int, 0, Int, w, Int, h, Ptr, hDC, Int, x, Int, y, UInt, 0x00CC0020)
   DllCall(&quot;SelectObject&quot;, Ptr, pDC, Ptr, oBM)
   DllCall(&quot;DeleteDC&quot;, Ptr, pDC)
   DllCall(&quot;ReleaseDC&quot;, Ptr, 0, Ptr, hDC)
   Return hBM  ; should be deleted with DllCall(&quot;DeleteObject&quot;, Ptr, hBM)
}

class GDIplus   {
   __New()  {
      if !DllCall(&quot;GetModuleHandle&quot;, Str, &quot;gdiplus&quot;, Ptr)
         DllCall(&quot;LoadLibrary&quot;, Str, &quot;gdiplus&quot;)
      VarSetCapacity(si, A_PtrSize = 8 ? 24 : 16, 0), si := Chr(1)
      DllCall(&quot;gdiplus\GdiplusStartup&quot;, PtrP, pToken, Ptr, &amp;si, Ptr, 0)
      this.token := pToken
   }
   
   __Delete()  {
      DllCall(&quot;gdiplus\GdiplusShutdown&quot;, Ptr, this.token)
      if hModule := DllCall(&quot;GetModuleHandle&quot;, Str, &quot;gdiplus&quot;, Ptr)
         DllCall(&quot;FreeLibrary&quot;, Ptr, hModule)
   }
   
   BitmapFromHBitmap(hBitmap, Palette := 0)  {
      DllCall(&quot;gdiplus\GdipCreateBitmapFromHBITMAP&quot;, Ptr, hBitmap, Ptr, Palette, PtrP, pBitmap)
      return pBitmap  ; should be deleted with this.DisposeImage(pBitmap)
   }
   
   SaveBitmapToFile(pBitmap, sOutput, Quality=75)  {
      SplitPath, sOutput,,, Extension
      if Extension not in BMP,DIB,RLE,JPG,JPEG,JPE,JFIF,GIF,TIF,TIFF,PNG
         return -1

      DllCall(&quot;gdiplus\GdipGetImageEncodersSize&quot;, UIntP, nCount, UIntP, nSize)
      VarSetCapacity(ci, nSize)
      DllCall(&quot;gdiplus\GdipGetImageEncoders&quot;, UInt, nCount, UInt, nSize, Ptr, &amp;ci)
      if !(nCount &amp;&amp; nSize)
         return -2
      
      Loop, % nCount  {
         sString := StrGet(NumGet(ci, (idx := (48+7*A_PtrSize)*(A_Index-1))+32+3*A_PtrSize), &quot;UTF-16&quot;)
         if !InStr(sString, &quot;*.&quot; Extension)
            continue
         
         pCodec := &amp;ci+idx
         break
      }
      
      if !pCodec
         return -3

      if RegExMatch(Extension, &quot;i)^J(PG|PEG|PE|FIF)$&quot;) &amp;&amp; Quality != 75  {
         DllCall(&quot;gdiplus\GdipGetEncoderParameterListSize&quot;, Ptr, pBitmap, Ptr, pCodec, UintP, nSize)
         VarSetCapacity(EncoderParameters, nSize, 0)
         DllCall(&quot;gdiplus\GdipGetEncoderParameterList&quot;, Ptr, pBitmap, Ptr, pCodec, UInt, nSize, Ptr, &amp;EncoderParameters)
         Loop, % NumGet(EncoderParameters, &quot;UInt&quot;)  {
            elem := (24+A_PtrSize)*(A_Index-1) + 4 + (pad := A_PtrSize = 8 ? 4 : 0)
            if (NumGet(EncoderParameters, elem+16, &quot;UInt&quot;) = 1) &amp;&amp; (NumGet(EncoderParameters, elem+20, &quot;UInt&quot;) = 6)  {
               p := elem+&amp;EncoderParameters-pad-4
               NumPut(Quality, NumGet(NumPut(4, NumPut(1, p+0)+20, &quot;UInt&quot;)), &quot;UInt&quot;)
               break
            }
         }      
      }
      
      if A_IsUnicode
         pOutput := &amp;sOutput
      else  {
         VarSetCapacity(wOutput, StrPut(sOutput, &quot;UTF-16&quot;)*2, 0)
         StrPut(sOutput, &amp;wOutput, &quot;UTF-16&quot;)
         pOutput := &amp;wOutput
      }
      E := DllCall(&quot;gdiplus\GdipSaveImageToFile&quot;, Ptr, pBitmap, Ptr, pOutput, Ptr, pCodec, UInt, p ? p : 0)
      return E ? -5 : 0
   }
   
   DisposeImage(pBitmap)  {
      return DllCall(&quot;gdiplus\GdipDisposeImage&quot;, Ptr, pBitmap)
   }
}</code></pre></div><p><strong>В чем проблема?</strong> Данный способ работает не на всех PC. На определенных PC скриншот получается рабочего стола, когда активное окно - игра(SAMP). При использовании <em>GetForegroundWindow</em> и вовсе не работает(Чёрный экран).<br /> </p><div class="codebox"><pre><code>GetHBitmapFromScreen(x, y, w, h)  {
...
 hWnd := DllCall(&quot;GetForegroundWindow&quot;)
 hDC := DllCall(&quot;GetDC&quot;, Ptr, hWnd, Ptr)
...
}</code></pre></div>]]></content>
			<author>
				<name><![CDATA[Leonmisha]]></name>
				<uri>http://forum.script-coding.com/profile.php?id=39874</uri>
			</author>
			<updated>2019-01-06T09:02:29Z</updated>
			<id>http://forum.script-coding.com/viewtopic.php?pid=130883#p130883</id>
		</entry>
</feed>
