<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
	<channel>
		<title><![CDATA[Серый форум &mdash; AHK: Создание нового файла с выделенным текстом]]></title>
		<link>http://forum.script-coding.com/viewtopic.php?id=12423</link>
		<atom:link href="http://forum.script-coding.com/extern.php?action=feed&amp;tid=12423&amp;type=rss" rel="self" type="application/rss+xml" />
		<description><![CDATA[Недавние сообщения в теме «AHK: Создание нового файла с выделенным текстом».]]></description>
		<lastBuildDate>Tue, 07 Apr 2020 00:41:51 +0000</lastBuildDate>
		<generator>PunBB</generator>
		<item>
			<title><![CDATA[Re: AHK: Создание нового файла с выделенным текстом]]></title>
			<link>http://forum.script-coding.com/viewtopic.php?pid=138939#p138939</link>
			<description><![CDATA[<div class="codebox"><pre><code>SCI_POSITIONRELATIVE := 2670
SCI_GETCODEPAGE := 2137 
SCI_SETSEL := 2160

Pos := 4

1::
	ControlGetFocus, ControlNN, A
	SendMessage, SCI_POSITIONRELATIVE, 0, Pos, %ControlNN%, A
    Pos := ErrorLevel
	SendMessage, SCI_SETSEL, Pos, Pos, %ControlNN%, A
	Return</code></pre></div>]]></description>
			<author><![CDATA[null@example.com (teadrinker)]]></author>
			<pubDate>Tue, 07 Apr 2020 00:41:51 +0000</pubDate>
			<guid>http://forum.script-coding.com/viewtopic.php?pid=138939#p138939</guid>
		</item>
		<item>
			<title><![CDATA[Re: AHK: Создание нового файла с выделенным текстом]]></title>
			<link>http://forum.script-coding.com/viewtopic.php?pid=138938#p138938</link>
			<description><![CDATA[<p>Пока такой костыль вышел.<br />Но SubStr тут плохо смотрится.<br /></p><div class="codebox"><pre><code>
SCI_GETCODEPAGE = 2137 
SCI_SETSEL = 2160
Pos := 4

1::
	ControlGetFocus, ControlNN, A 
	ControlGetText, Text, %ControlNN%, A 
	SendMessage, SCI_GETCODEPAGE, , , %ControlNN%, A
	p := StrPut(SubStr(Text, 1, Pos - 1), &quot;CP&quot; Errorlevel)
	SendMessage, SCI_SETSEL, p, p, %ControlNN%, A
	Return	
</code></pre></div>]]></description>
			<author><![CDATA[null@example.com (serzh82saratov)]]></author>
			<pubDate>Mon, 06 Apr 2020 23:06:20 +0000</pubDate>
			<guid>http://forum.script-coding.com/viewtopic.php?pid=138938#p138938</guid>
		</item>
		<item>
			<title><![CDATA[Re: AHK: Создание нового файла с выделенным текстом]]></title>
			<link>http://forum.script-coding.com/viewtopic.php?pid=138935#p138935</link>
			<description><![CDATA[<p>Как перейти например на четвёртый символ в тексте если есть символы юникода?<br />Если в начале Scintilla прописать четыре русских буквы, то перейдёт на вторую.<br /></p><div class="codebox"><pre><code>
1::
	Pos := 4
	SCI_SETSEL = 2160  
	ControlGetFocus, ControlNN, A 
	SendMessage, SCI_SETSEL, Pos, Pos, %ControlNN%, A
	Return	
</code></pre></div>]]></description>
			<author><![CDATA[null@example.com (serzh82saratov)]]></author>
			<pubDate>Mon, 06 Apr 2020 21:37:29 +0000</pubDate>
			<guid>http://forum.script-coding.com/viewtopic.php?pid=138935#p138935</guid>
		</item>
		<item>
			<title><![CDATA[Re: AHK: Создание нового файла с выделенным текстом]]></title>
			<link>http://forum.script-coding.com/viewtopic.php?pid=112305#p112305</link>
			<description><![CDATA[<p><strong>Malcev</strong><br />По поводу последнего примера не в теме, по поводу первого — проблема инжекта dll в том, что внедряемой функции можно передать только один аргумент, и если нужно больше, то приведённым способом не получится. По идее нужно писать свою dll, которой будет передаваться указатель на структуру с аргументами для системных api-функций. Для AHK этот вариант не годится. Также можно вместо этого передать аргументы внедрённой функции, используя команды ассемблера. С этим и попытаюсь разобраться, как время будет.</p>]]></description>
			<author><![CDATA[null@example.com (teadrinker)]]></author>
			<pubDate>Sun, 12 Feb 2017 20:54:04 +0000</pubDate>
			<guid>http://forum.script-coding.com/viewtopic.php?pid=112305#p112305</guid>
		</item>
		<item>
			<title><![CDATA[Re: AHK: Создание нового файла с выделенным текстом]]></title>
			<link>http://forum.script-coding.com/viewtopic.php?pid=112148#p112148</link>
			<description><![CDATA[<p><strong>svoboden</strong>, мне не нужны. Мне нужна была вещь, что часть выделенного мной в notepad кода будет записывать в новый файл, чтобы я не создавал сто тысяч раз новый файл. А то мне вечно в скайпе пишут: &quot;Белка, скинь это&quot;, &quot;Скинь это&quot; и т.д <img src="//forum.script-coding.com/img/smilies/big_smile.png" width="15" height="15" />.</p>]]></description>
			<author><![CDATA[null@example.com (belyankin12)]]></author>
			<pubDate>Sat, 11 Feb 2017 08:09:44 +0000</pubDate>
			<guid>http://forum.script-coding.com/viewtopic.php?pid=112148#p112148</guid>
		</item>
		<item>
			<title><![CDATA[Re: AHK: Создание нового файла с выделенным текстом]]></title>
			<link>http://forum.script-coding.com/viewtopic.php?pid=112144#p112144</link>
			<description><![CDATA[<p>Отлично. Спасибо!<br />Может в коллекцию?<br />Если бы ты потом, когда сам разберёшься, объяснил как инжектить dll на этом примере:<br /><a href="http://forum.script-coding.com/viewtopic.php?pid=109142#p109142">http://forum.script-coding.com/viewtopi … 42#p109142</a><br />И заодно, показал бы, что и как заинжектить тут:<br /><a href="http://forum.script-coding.com/viewtopic.php?pid=111032#p111032">http://forum.script-coding.com/viewtopi … 32#p111032</a></p>]]></description>
			<author><![CDATA[null@example.com (Malcev)]]></author>
			<pubDate>Sat, 11 Feb 2017 00:53:38 +0000</pubDate>
			<guid>http://forum.script-coding.com/viewtopic.php?pid=112144#p112144</guid>
		</item>
		<item>
			<title><![CDATA[Re: AHK: Создание нового файла с выделенным текстом]]></title>
			<link>http://forum.script-coding.com/viewtopic.php?pid=112140#p112140</link>
			<description><![CDATA[<div class="quotebox"><cite>Malcev пишет:</cite><blockquote><p>Вот если б ты на свой класс RemoteBuffer дал комментарии, то было бы отлично.</p></blockquote></div><p>Вот подправленный RemoteBuffer с примером использования для Notepad++:<br /></p><div class="codebox"><pre><code>if hNPP := WinExist(&quot;ahk_class Notepad++&quot;)
   WinGet, PID, PID
else  {
   try Run, notepad++,,, PID
   catch e  {
      MsgBox, % e.Message &quot;`n`n&quot; e.Extra
      ExitApp
   }
   WinWait, ahk_pid %PID%
}
WinActivate

; создаём удалённый буфер в адресном пространстве процесса Notepad++.exe
buff := new RemoteBuffer(PID, 512)  ; размер 512 байт, с запасом
; созданный буфер находится теперь в адресном пространстве Notepad++.exe по адресу buff.ptr

; открываем наш скрипт в Notepad++
filePath := A_ScriptFullPath

; чтобы передать путь к файлу в сообщении, он должен находиться в АП Notepad++.exe
; Сначала запишем его в локальный буфер. Кодировка должна быть UTF-16.
VarSetCapacity(var, size := StrPut(filePath, &quot;UTF-16&quot;)*2)
StrPut(filePath, &amp;var, &quot;UTF-16&quot;)

; теперь наш локальный буфер можно записать в удалённый через метод Write()
buff.Write(&amp;var, size)
; сейчас путь к файлу находится в адресном пространстве Notepad++.exe по адресу buff.ptr
; передаём его окну сообщением:
SendMessage, NPPM_DOOPEN := 2101,, buff.ptr
if (ErrorLevel != 1)  {
   MsgBox, не удалось открыть файл
   ExitApp
}

; получаем строку текста с номером LineNumber
LineNumber := 52

ControlGetFocus, focused
SendMessage, SCI_GETLINE := 2153, LineNumber - 1,, % focused
szBuff := ErrorLevel  ; сколько места займёт строка

; подставляем buff.ptr в качестве буфера-получателя
SendMessage, SCI_GETLINE, LineNumber - 1, buff.ptr, % focused
; сейчас строка находится в адресном пространстве Notepad++.exe по адресу buff.ptr
; считываем её в локальный буфер, он будет создан автоматически
pStr := buff.Read(szBuff)
line := StrGet(pStr, szBuff, &quot;UTF-8&quot;)

buff := &quot;&quot;  ; уничтожаем удалённый буфер
MsgBox,, %LineNumber%-я строка:, % line

class RemoteBuffer
{
   __New(PID, size)  {
      static PROCESS_VM_OPERATION := 0x8, PROCESS_VM_WRITE := 0x20
           , PROCESS_VM_READ := 0x10, MEM_COMMIT := 0x1000, PAGE_READWRITE := 0x4
         
      if !(this.hProc := DllCall(&quot;OpenProcess&quot;, UInt, PROCESS_VM_OPERATION|PROCESS_VM_READ|PROCESS_VM_WRITE, Int, 0, UInt, PID, Ptr))
         Return
      
      if !(this.ptr := DllCall(&quot;VirtualAllocEx&quot;, Ptr, this.hProc, Ptr, 0, Ptr, size, UInt, MEM_COMMIT, UInt, PAGE_READWRITE, Ptr))
         Return, &quot;&quot;, DllCall(&quot;CloseHandle&quot;, Ptr, this.hProc)
      
      this.hHeap := DllCall(&quot;GetProcessHeap&quot;, Ptr)
   }
   
   __Delete()  {
      DllCall(&quot;VirtualFreeEx&quot;, Ptr, this.hProc, Ptr, this.ptr, UInt, 0, UInt, MEM_RELEASE := 0x8000)
      DllCall(&quot;CloseHandle&quot;, Ptr, this.hProc)
      DllCall(&quot;HeapFree&quot;, Ptr, this.hHeap, UInt, 0, Ptr, this.pHeap)
   }
   
   Read(size, offset = 0)  {
      (this.pHeap &amp;&amp; DllCall(&quot;HeapFree&quot;, Ptr, this.hHeap, UInt, 0, Ptr, this.pHeap))
      this.pHeap := DllCall(&quot;HeapAlloc&quot;, Ptr, this.hHeap, UInt, HEAP_ZERO_MEMORY := 0x8, Ptr, size, Ptr)
      if !DllCall(&quot;ReadProcessMemory&quot;, Ptr, this.hProc, Ptr, this.ptr + offset, Ptr, this.pHeap, Ptr, size, Int, 0)
         Return, 0, DllCall(&quot;MessageBox&quot;, Ptr, 0, Str, &quot;Не удалось прочитать данные`nОшибка &quot; A_LastError, Str, &quot;&quot;, UInt, 0)
      Return this.pHeap
   }
   
   Write(pLocalBuff, size, offset = 0)  {
      if !res := DllCall(&quot;WriteProcessMemory&quot;, Ptr, this.hProc, Ptr, this.ptr + offset, Ptr, pLocalBuff, Ptr, size, PtrP, writtenBytes)
         DllCall(&quot;MessageBox&quot;, Ptr, 0, Str, &quot;Не удалось записать данные`nОшибка &quot; A_LastError, Str, &quot;&quot;, UInt, 0)
      Return writtenBytes
   }
}</code></pre></div>]]></description>
			<author><![CDATA[null@example.com (teadrinker)]]></author>
			<pubDate>Fri, 10 Feb 2017 19:40:38 +0000</pubDate>
			<guid>http://forum.script-coding.com/viewtopic.php?pid=112140#p112140</guid>
		</item>
		<item>
			<title><![CDATA[Re: AHK: Создание нового файла с выделенным текстом]]></title>
			<link>http://forum.script-coding.com/viewtopic.php?pid=112136#p112136</link>
			<description><![CDATA[<p>Странно, а почему в &quot;SciTE4AutoHotkey&quot; в кодировки &quot;code.page=65001&quot; все работает, это же вроде и есть UTF-8? А что, начавшему тему пользователю обязательно нужны кириллические символы?</p>]]></description>
			<author><![CDATA[null@example.com (svoboden)]]></author>
			<pubDate>Fri, 10 Feb 2017 19:28:16 +0000</pubDate>
			<guid>http://forum.script-coding.com/viewtopic.php?pid=112136#p112136</guid>
		</item>
		<item>
			<title><![CDATA[Re: AHK: Создание нового файла с выделенным текстом]]></title>
			<link>http://forum.script-coding.com/viewtopic.php?pid=112103#p112103</link>
			<description><![CDATA[<p><strong>teadrinker</strong>, проверил, работает, вам тоже спасибо!</p>]]></description>
			<author><![CDATA[null@example.com (belyankin12)]]></author>
			<pubDate>Fri, 10 Feb 2017 09:49:07 +0000</pubDate>
			<guid>http://forum.script-coding.com/viewtopic.php?pid=112103#p112103</guid>
		</item>
		<item>
			<title><![CDATA[Re: AHK: Создание нового файла с выделенным текстом]]></title>
			<link>http://forum.script-coding.com/viewtopic.php?pid=112102#p112102</link>
			<description><![CDATA[<p><strong>belyankin12</strong>, не обиделись. А мой код у вас не работает? Или опять не запускали?</p>]]></description>
			<author><![CDATA[null@example.com (teadrinker)]]></author>
			<pubDate>Fri, 10 Feb 2017 09:41:50 +0000</pubDate>
			<guid>http://forum.script-coding.com/viewtopic.php?pid=112102#p112102</guid>
		</item>
		<item>
			<title><![CDATA[Re: AHK: Создание нового файла с выделенным текстом]]></title>
			<link>http://forum.script-coding.com/viewtopic.php?pid=112099#p112099</link>
			<description><![CDATA[<p><strong>Malcev</strong>, ваш код работает на ура, спасибо. Проблема решена.</p>]]></description>
			<author><![CDATA[null@example.com (belyankin12)]]></author>
			<pubDate>Fri, 10 Feb 2017 09:09:18 +0000</pubDate>
			<guid>http://forum.script-coding.com/viewtopic.php?pid=112099#p112099</guid>
		</item>
		<item>
			<title><![CDATA[Re: AHK: Создание нового файла с выделенным текстом]]></title>
			<link>http://forum.script-coding.com/viewtopic.php?pid=112098#p112098</link>
			<description><![CDATA[<p><strong>teadrinker</strong>, это же не значит, что я не стремлюсь обучаться, или вы обиделись на меня xD?</p>]]></description>
			<author><![CDATA[null@example.com (belyankin12)]]></author>
			<pubDate>Fri, 10 Feb 2017 09:04:21 +0000</pubDate>
			<guid>http://forum.script-coding.com/viewtopic.php?pid=112098#p112098</guid>
		</item>
		<item>
			<title><![CDATA[Re: AHK: Создание нового файла с выделенным текстом]]></title>
			<link>http://forum.script-coding.com/viewtopic.php?pid=112091#p112091</link>
			<description><![CDATA[<p>Нет, чтение памяти чужого процесса и инжект dll в чужой процесс — разные вещи. Да там и не совсем корректный код, я с ним ещё не окончательно разобрался.</p>]]></description>
			<author><![CDATA[null@example.com (teadrinker)]]></author>
			<pubDate>Fri, 10 Feb 2017 06:05:01 +0000</pubDate>
			<guid>http://forum.script-coding.com/viewtopic.php?pid=112091#p112091</guid>
		</item>
		<item>
			<title><![CDATA[Re: AHK: Создание нового файла с выделенным текстом]]></title>
			<link>http://forum.script-coding.com/viewtopic.php?pid=112090#p112090</link>
			<description><![CDATA[<p>Может стоит дополнить этот класс:<br /></p><div class="codebox"><pre><code>Class RemoteBuffer
{
   __New(PID, size)
   {
      static PROCESS_VM_OPERATION := 0x8, PROCESS_VM_WRITE := 0x20, PROCESS_VM_READ := 0x10
         , MEM_COMMIT := 0x1000, PAGE_READWRITE := 0x4
         
      if !(this.hProc := DllCall(&quot;OpenProcess&quot;, UInt, PROCESS_VM_OPERATION|PROCESS_VM_READ|PROCESS_VM_WRITE, Int, 0, UInt, PID, Ptr))
         Return
      
      if !(this.ptr := DllCall(&quot;VirtualAllocEx&quot;, UInt, this.hProc, UInt, 0, UInt, size, UInt, MEM_COMMIT, UInt, PAGE_READWRITE, Ptr))
         Return, &quot;&quot;, DllCall(&quot;CloseHandle&quot;, Ptr, this.hProc)
   }
   
   __Delete()
   {
      DllCall(&quot;VirtualFreeEx&quot;, Ptr, this.hProc, Ptr, this.ptr, UInt, 0, UInt, MEM_RELEASE := 0x8000)
      DllCall(&quot;CloseHandle&quot;, Ptr, this.hProc)
   }
   
   Read(size, offset = 0)
   {
      static LocalBuff
      VarSetCapacity(LocalBuff, size, 0)
      if !DllCall(&quot;ReadProcessMemory&quot;, Ptr, this.hProc, Ptr, this.ptr + offset, Ptr, &amp;LocalBuff, UInt, size, UInt, 0)
         Return, 0, DllCall(&quot;MessageBox&quot;, Ptr, 0, Str, &quot;Не удалось прочитать данные`nОшибка &quot; A_LastError, Str, &quot;&quot;, UInt, 0)
      
      VarSetCapacity(LocalBuff, -1)
      Return &amp;LocalBuff
   }
   
   Write(pLocalBuff, size, offset = 0)
   {
      res := DllCall(&quot;WriteProcessMemory&quot;, Ptr, this.hProc, Ptr, this.ptr + offset, Ptr, pLocalBuff, UInt, size, UInt, 0)
      Return res ? res : 0, (!res) ? DllCall(&quot;MessageBox&quot;, Ptr, 0, Str, &quot;Не удалось записать данные`nОшибка &quot; A_LastError, Str, &quot;&quot;, UInt, 0)
   }
}</code></pre></div><p>вот этим инджектом?<br /><a href="http://forum.script-coding.com/viewtopic.php?pid=109142#p109142">http://forum.script-coding.com/viewtopi … 42#p109142</a></p>]]></description>
			<author><![CDATA[null@example.com (Malcev)]]></author>
			<pubDate>Fri, 10 Feb 2017 05:57:28 +0000</pubDate>
			<guid>http://forum.script-coding.com/viewtopic.php?pid=112090#p112090</guid>
		</item>
		<item>
			<title><![CDATA[Re: AHK: Создание нового файла с выделенным текстом]]></title>
			<link>http://forum.script-coding.com/viewtopic.php?pid=112088#p112088</link>
			<description><![CDATA[<div class="quotebox"><cite>Malcev пишет:</cite><blockquote><p>Есть ли смысл переделывать готовые скрипты, ради использования ahk 64 бит?</p></blockquote></div><p>Ради использования может и нет, ради понимания есть.</p><div class="quotebox"><cite>Malcev пишет:</cite><blockquote><p>Вот если б ты на свой класс RemoteBuffer дал комментарии, то было бы отлично.</p></blockquote></div><p>Так у меня то же самое, что и тут, просто размерность правильная. Я не знаю, какие именно комментарии нужны, если что-то неясно, лучше спрашивать, потому что у каждого ведь свой уровень понимания.</p><p>Так у меня получает выделенный текст даже из неактивного окна:<br /></p><div class="codebox"><pre><code>F11:: MsgBox, % GetSelTextFromNPP(WinExist(&quot;ahk_class Notepad++&quot;))

GetSelTextFromNPP(hNPP)  {
   if !WinExist(&quot;ahk_id&quot; hNPP)  {
      MsgBox, Окно Notepad++ не найдено
      Return
   }
   WinGet, PID, PID
   ControlGetFocus, focused
   if InStr(focused, &quot;Scintilla&quot;)
      ControlGet, hScintilla, hwnd,, % focused
   else
      hScintilla := GetCurrentScintilla(PID)
   
   if !hScintilla  {
      MsgBox, Не удалось определить текущее поле редактирования
      Return
   }
   WinWait, ahk_id %hScintilla%
   SendMessage, SCI_GETSELTEXT := 2161
   charCount := ErrorLevel
   if (charCount &lt; 2)
      Return
   
   remoteBuff := new RemoteBuffer(PID, charCount)
   SendMessage, SCI_GETSELTEXT,, remoteBuff.ptr
   
   VarSetCapacity(localBuff, charCount, 0)
   remoteBuff.Read(&amp;localBuff, charCount)
   SendMessage, SCI_GETCODEPAGE := 2137
   Return StrGet(&amp;localBuff, &quot;CP&quot; . ErrorLevel)
}

GetCurrentScintilla(PID)  {
   remoteBuff := new RemoteBuffer(PID, 4)
   SendMessage, NPPM_GETCURRENTSCINTILLA := 2028,, remoteBuff.ptr
   VarSetCapacity(localBuff, 4, 0)
   remoteBuff.Read(&amp;localBuff, 4)
   
   if handles := GetScintillaHandles()
      Return handles[ NumGet(localBuff, &quot;Int&quot;) + 1 ]
}

GetScintillaHandles()  {
   WinGet, list, ControlList
   WinGet, listHwnd, ControlListHwnd
   arrClassNN := StrSplit(list, &quot;`n&quot;)
   arrHwnd := StrSplit(listHwnd, &quot;`n&quot;)
   for k, v in arrClassNN  {
      if InStr(prevClass, &quot;Scintilla&quot;) &amp;&amp; InStr(v, &quot;Scintilla&quot;)
         Return [ arrHwnd[k - 1], arrHwnd[k] ]
      prevClass := v
   }
}
   
class RemoteBuffer
{
   __New(PID, size)  {
      static PROCESS_VM_OPERATION := 0x8, PROCESS_VM_WRITE := 0x20, PROCESS_VM_READ := 0x10
           , MEM_COMMIT := 0x1000, PAGE_READWRITE := 0x4
         
      if !(this.hProc := DllCall(&quot;OpenProcess&quot;, UInt, PROCESS_VM_OPERATION|PROCESS_VM_READ|PROCESS_VM_WRITE, Int, 0, UInt, PID, Ptr))
         Return
      
      if !(this.ptr := DllCall(&quot;VirtualAllocEx&quot;, UInt, this.hProc, UInt, 0, UInt, size, UInt, MEM_COMMIT, UInt, PAGE_READWRITE, Ptr))
         Return, &quot;&quot;, DllCall(&quot;CloseHandle&quot;, Ptr, this.hProc)
   }
   
   __Delete()  {
      DllCall(&quot;VirtualFreeEx&quot;, Ptr, this.hProc, Ptr, this.ptr, UInt, 0, UInt, MEM_RELEASE := 0x8000)
      DllCall(&quot;CloseHandle&quot;, Ptr, this.hProc)
   }
   
   Read(pLocalBuff, size, offset = 0)  {
      if !DllCall(&quot;ReadProcessMemory&quot;, Ptr, this.hProc, Ptr, this.ptr + offset, Ptr, pLocalBuff, UInt, size, UInt, 0)
         Return, 0, DllCall(&quot;MessageBox&quot;, Ptr, 0, Str, &quot;Не удалось прочитать данные`nОшибка &quot;&quot;&quot; A_LastError &quot;&quot;&quot;&quot;, Str, &quot;&quot;, UInt, 0)
   }
}</code></pre></div>]]></description>
			<author><![CDATA[null@example.com (teadrinker)]]></author>
			<pubDate>Fri, 10 Feb 2017 05:05:29 +0000</pubDate>
			<guid>http://forum.script-coding.com/viewtopic.php?pid=112088#p112088</guid>
		</item>
	</channel>
</rss>
