<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
	<title type="html"><![CDATA[Серый форум &mdash; AHK: Установить поверх всех окон в Windows 10 с помощью SetWindowBand]]></title>
	<link rel="self" href="http://forum.script-coding.com/extern.php?action=feed&amp;tid=17662&amp;type=atom" />
	<updated>2023-03-12T02:53:42Z</updated>
	<generator>PunBB</generator>
	<id>http://forum.script-coding.com/viewtopic.php?id=17662</id>
		<entry>
			<title type="html"><![CDATA[AHK: Установить поверх всех окон в Windows 10 с помощью SetWindowBand]]></title>
			<link rel="alternate" href="http://forum.script-coding.com/viewtopic.php?pid=157099#p157099" />
			<content type="html"><![CDATA[<p>Вот ссылка на этот api, работа очень хорошего реверс-инженера <strong>ADeltaX</strong>.<br /><a href="https://blog.adeltax.com/window-z-order-in-windows-10/">https://blog.adeltax.com/window-z-order-in-windows-10/</a><br />Чтобы вызвать SetWindowBand, нам нужно заинжектить dll в explorer.exe и либо установить хук на SetWindowBand и показать стартовое меню, либо установить хук на NtUserEnableIAMAccess и перехватить iam ключ.<br /><a href="https://blog.adeltax.com/how-to-call-setwindowband/">https://blog.adeltax.com/how-to-call-setwindowband/</a><br />Вот скрипт, который инжектит autohotkey.dll и устанавливает хук с помощью minhook.dll<br />Нужно скачать minhook враппер от <strong>tmplinshi</strong>.<br /><a href="https://github.com/tmplinshi/MinHook-AHK">https://github.com/tmplinshi/MinHook-AHK</a><br />И запустить следующий код из папки с примерами.<br />Нажатие f11 установит самый высокий window band в активное окно, равный osk или окну лупы.<br /></p><div class="codebox"><pre><code>SetWorkingDir %A_ScriptDir%
#NoEnv
#Persistent
#SingleInstance Force
if (A_Is64bitOS &amp;&amp; A_PtrSize = 4)
{
   Run, %A_AhkPath%\..\AutoHotkeyU64.exe &quot;%A_ScriptFullPath%&quot;, %A_ScriptDir%
   ExitApp
}

f11::
ourHwnd := WinExist(&quot;A&quot;)
ourBand := 2   ; ZBID_UIACCESS

code =
(LTrim
   SetWorkingDir, %A_ScriptDir%
   #Include %A_ScriptDir%\Lib\MinHook.ahk
   address_SetWindowBand := DllCall(&quot;GetProcAddress&quot;, Ptr, DllCall(&quot;GetModuleHandle&quot;, Str, &quot;user32&quot;, &quot;Ptr&quot;), AStr, &quot;SetWindowBand&quot;, &quot;Ptr&quot;)
   hook1 := New MinHook(&quot;&quot;, address_SetWindowBand, &quot;SetWindowBand_Hook&quot;)
   hook1.Enable()
   return

   SetWindowBand_Hook(hWnd, hwndInsertAfter, dwBand)
   {
      global hook1
      return DllCall(hook1.original, &quot;ptr&quot;, %ourHwnd%, &quot;ptr&quot;, 0, &quot;uint&quot;, %ourBand%)
   }
)
codeUnhook =
(LTrim
   hook1.Disable()
   hook1 := &quot;&quot;
)

shellHwnd := DllCall(&quot;GetShellWindow&quot;, &quot;ptr&quot;)
WinGet, pid, PID, ahk_id %shellHwnd%
dllFile := FileExist(&quot;AutoHotkeyMini.dll&quot;) ? A_ScriptDir &quot;\AutoHotkeyMini.dll&quot;
          : (A_PtrSize = 8)                  ? A_ScriptDir &quot;\ahkDll\x64\AutoHotkeyMini.dll&quot;
          : A_ScriptDir &quot;\ahkDll\x32\AutoHotkeyMini.dll&quot;
rThread := InjectAhkDll(pid, dllFile, &quot;&quot;)
rThread.Exec(code)
AppVisibility := ComObjCreate(CLSID_AppVisibility := &quot;{7E5FE3D9-985F-4908-91F9-EE19F9FD1514}&quot;, IID_IAppVisibility := &quot;{2246EA2D-CAEA-4444-A3C4-6DE827E44313}&quot;)
loop 2
{
   if (A_Index = 1)
      visible := 1
   else
      visible := 0
   loop
   {
      send {LWin down}
      sleep 50
      send {LWin up}
      loop 200   ; wait no more than 2 seconds
      {
         if (DllCall(NumGet(NumGet(AppVisibility+0)+4*A_PtrSize), &quot;Ptr&quot;, AppVisibility, &quot;Int*&quot;, fVisible) = 0)
         {
            if (fVisible = visible)
               break 2
            sleep 10
         }
      }
   }
}
ObjRelease(AppVisibility)
rThread.Exec(codeUnhook)
rThread:=&quot;&quot;
return</code></pre></div><p>Пример c перехватом iam ключа.<br />После запуска скрипта следует дождаться сообщения iam key received.<br />После чего понажимать f11, f12, которые меняют band активного окна:<br /></p><div class="codebox"><pre><code>SetWorkingDir %A_ScriptDir%
#NoEnv
#SingleInstance Force
setbatchlines -1
OnExit, ExitSub
if (A_Is64bitOS &amp;&amp; A_PtrSize = 4)
{
   Run, %A_AhkPath%\..\AutoHotkeyU64.exe &quot;%A_ScriptFullPath%&quot;, %A_ScriptDir%
   ExitApp
}
global g_iam_key, NtUserEnableIAMAccess
MsgNum := DllCall(&quot;RegisterWindowMessage&quot;, &quot;str&quot;, &quot;NewAHKScript&quot;)
OnMessage(MsgNum, &quot;dataReceived&quot;)
SetWindowBand := DllCall(&quot;GetProcAddress&quot;, &quot;ptr&quot;, DllCall(&quot;GetModuleHandle&quot;, &quot;str&quot;, &quot;user32&quot;, &quot;ptr&quot;), &quot;astr&quot;, &quot;SetWindowBand&quot;, &quot;ptr&quot;)
Gui, temp:-Caption +ToolWindow +hwndhTemphwnd
Gui, temp:show, % &quot;x&quot; A_ScreenWidth/2 &quot; y&quot; A_ScreenHeight/2 &quot; w1 h1&quot;
code =
(LTrim
   SetWorkingDir, %A_ScriptDir%
   #Include %A_ScriptDir%\Lib\MinHook.ahk
   address_NtUserEnableIAMAccess := DllCall(&quot;GetProcAddress&quot;, &quot;ptr&quot;, DllCall(&quot;GetModuleHandle&quot;, &quot;str&quot;, &quot;user32&quot;, &quot;ptr&quot;), &quot;ptr&quot;, 2510, &quot;ptr&quot;)
   hook := New MinHook(&quot;&quot;, address_NtUserEnableIAMAccess, &quot;NtUserEnableIAMAccess_Hook&quot;)
   hook.Enable()
   return

   NtUserEnableIAMAccess_Hook(key, enable)
   {
      global hook
      static g_iam_key
      hr := DllCall(hook.original, &quot;uint64&quot;, key, &quot;int&quot;, enable)
      if hr and !g_iam_key
      {
         g_iam_key := key
         DllCall(&quot;PostMessage&quot;, &quot;uptr&quot;, %A_ScriptHwnd%, &quot;uint&quot;, %MsgNum%, &quot;ptr&quot;, hook.original, &quot;ptr&quot;, g_iam_key)
      }
   }
)
shellHwnd := DllCall(&quot;GetShellWindow&quot;, &quot;ptr&quot;)
WinGet, pid, PID, ahk_id %shellHwnd%
dllFile := FileExist(&quot;AutoHotkeyMini.dll&quot;) ? A_ScriptDir &quot;\AutoHotkeyMini.dll&quot;
          : (A_PtrSize = 8)                  ? A_ScriptDir &quot;\ahkDll\x64\AutoHotkeyMini.dll&quot;
          : A_ScriptDir &quot;\ahkDll\x32\AutoHotkeyMini.dll&quot;
rThread := InjectAhkDll(pid, dllFile, &quot;&quot;)
rThread.Exec(code)
loop
{
   WinActivate, ahk_id %hTemphwnd%
   WinWaitActive, ahk_id %hTemphwnd%,, 1
   WinActivate, ahk_class Shell_TrayWnd
   WinWaitActive, ahk_class Shell_TrayWnd,, 1
   if (g_iam_key != &quot;&quot;)
      break
   sleep 10
}
code =
(LTrim
   hook.Disable()
   hook := &quot;&quot;
)
rThread.Exec(code)
OnMessage(MsgNum, &quot;&quot;)
Gui, temp:destroy
msgbox iam key received
return

dataReceived(wParam, lParam, msg, hwnd)
{
   NtUserEnableIAMAccess := wParam
   g_iam_key := lParam
}

ExitSub:
if isObject(rThread)
   rThread := &quot;&quot;
ExitApp

f11::
hwnd := WinExist(&quot;A&quot;)
code = 
(
DllCall(%NtUserEnableIAMAccess%, &quot;uint64&quot;, %g_iam_key%, &quot;int&quot;, 1)
DllCall(%SetWindowBand%, &quot;uptr&quot;, %hwnd%, &quot;ptr&quot;, 0, &quot;uint&quot;, ZBID_UIACCESS := 2)
DllCall(%NtUserEnableIAMAccess%, &quot;uint64&quot;, %g_iam_key%, &quot;int&quot;, 0)
)
rThread.Exec(code)
return

f12::
hwnd := WinExist(&quot;A&quot;)
code = 
(
DllCall(%NtUserEnableIAMAccess%, &quot;uint64&quot;, %g_iam_key%, &quot;int&quot;, 1)
DllCall(%SetWindowBand%, &quot;uptr&quot;, %hwnd%, &quot;ptr&quot;, 0, &quot;uint&quot;, ZBID_DESKTOP := 1)
DllCall(%NtUserEnableIAMAccess%, &quot;uint64&quot;, %g_iam_key%, &quot;int&quot;, 0)
)
rThread.Exec(code)
return</code></pre></div><p><a href="http://forum.script-coding.com/viewtopic.php?id=16540">Тема для обсуждения</a></p>]]></content>
			<author>
				<name><![CDATA[Malcev]]></name>
				<uri>http://forum.script-coding.com/profile.php?id=26930</uri>
			</author>
			<updated>2023-03-12T02:53:42Z</updated>
			<id>http://forum.script-coding.com/viewtopic.php?pid=157099#p157099</id>
		</entry>
</feed>
