<?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="https://forum.script-coding.com/extern.php?action=feed&amp;tid=17306&amp;type=atom" />
	<updated>2022-08-13T17:22:32Z</updated>
	<generator>PunBB</generator>
	<id>https://forum.script-coding.com/viewtopic.php?id=17306</id>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Не получается вставить переменную времени]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=154383#p154383" />
			<content type="html"><![CDATA[<p><strong>Clannad5</strong> Огромное тебе спасибо.</p>]]></content>
			<author>
				<name><![CDATA[alex16uk]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=42526</uri>
			</author>
			<updated>2022-08-13T17:22:32Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=154383#p154383</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Не получается вставить переменную времени]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=154370#p154370" />
			<content type="html"><![CDATA[<p><strong>alex16uk</strong></p><p>Если путаешься внутри функции, то можешь упаковать вначале переменную полностью:<br /></p><div class="codebox"><pre><code>
F1::
Gosub skr
return

skr:
time := A_NowUTC
time += 3, H
FormatTime, vDate,% time, HH_mm_ss ; запрещено использовать двоеточие, поэтому я заменил на нижнее подчеркивание.
vDate := &quot;\&quot; vDate &quot;.png&quot; ; упакуем сразу путь, можно сюда же и A_ScriptDir засунуть, тогда внутри функции нужно будет указать только vDate.
msgbox, % vDate ; Это просто даёт тебе полное представление о том, как будет выглядить твой путь, если ты его упакуешь таким образом. Удали эту строчку когда понадобиться.
screenshot:=(A_ScriptDir . vDate) ; Указываем упакованный путь.
SaveScreenshotToFile(0, 0, A_ScreenWidth, A_ScreenHeight, screenshot)

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)
{
	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
}

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
	}
	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)
	}
}
Return
</code></pre></div>]]></content>
			<author>
				<name><![CDATA[Clannad5]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=39853</uri>
			</author>
			<updated>2022-08-13T00:16:14Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=154370#p154370</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Не получается вставить переменную времени]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=154360#p154360" />
			<content type="html"><![CDATA[<p>Изучите <a href="https://www.autohotkey.com/docs/Variables.htm#Intro">Variables and Expressions</a>, там есть примеры вставки переменной в строку.</p>]]></content>
			<author>
				<name><![CDATA[Phoenixxx_Czar]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=34426</uri>
			</author>
			<updated>2022-08-12T17:33:18Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=154360#p154360</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[AHK: Не получается вставить переменную времени]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=154357#p154357" />
			<content type="html"><![CDATA[<p>У меня не получается подставить вместо screenshot переменную времени, я уже несколько вариантов пробывал но ничего не получается:</p><p>Это 1 из вариантов которые я пробывал но он не работает: <br /></p><div class="codebox"><pre><code>time := A_NowUTC
time += 3, H
FormatTime, vDate,% time, HH:mm:ss
screenshot:=(A_ScriptDir . &quot;\%vDate%.png&quot;)
SaveScreenshotToFile(0, 0, A_ScreenWidth, A_ScreenHeight, screenshot)</code></pre></div><p>Вот сам код:<br /></p><div class="codebox"><pre><code>F1::
Gosub skr
return

skr:
screenshot:=(A_ScriptDir . &quot;\screenshot.png&quot;)
SaveScreenshotToFile(0, 0, A_ScreenWidth, A_ScreenHeight, screenshot)

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)
{
	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
}

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
	}
	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)
	}
}
Return</code></pre></div>]]></content>
			<author>
				<name><![CDATA[alex16uk]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=42526</uri>
			</author>
			<updated>2022-08-12T14:22:04Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=154357#p154357</id>
		</entry>
</feed>
