<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
	<channel>
		<title><![CDATA[Серый форум &mdash; Отображение картинки - если окно неактивно, но впереди других окон]]></title>
		<link>https://forum.script-coding.com/viewtopic.php?id=15589</link>
		<atom:link href="https://forum.script-coding.com/extern.php?action=feed&amp;tid=15589&amp;type=rss" rel="self" type="application/rss+xml" />
		<description><![CDATA[Недавние сообщения в теме «Отображение картинки - если окно неактивно, но впереди других окон».]]></description>
		<lastBuildDate>Sun, 09 Aug 2020 23:19:34 +0000</lastBuildDate>
		<generator>PunBB</generator>
		<item>
			<title><![CDATA[Отображение картинки - если окно неактивно, но впереди других окон]]></title>
			<link>https://forum.script-coding.com/viewtopic.php?pid=141586#p141586</link>
			<description><![CDATA[<p>Здравствуйте, форумчане.<br />Помогите поправить скрипт.</p><p>Если запустить скрипт, когда окно блокнота неактивно, но видимо - то картинка не будет отображаться на нем.<br />Как сделать так, чтобы картинка отображалась бы на окне блокнота - даже если окно неактивно, но стоит впереди всех других окон ?<br /></p><div class="codebox"><pre><code>
#NoEnv
SetBatchLines, -1

sFile := A_ScriptDir . &quot;\рисунок 1.jpg&quot;


pictureWidth := 150

hGui := CreatePicture(sFile, pictureWidth)
BindToWindow(hGui, &quot;Notepad&quot;)

CreatePicture(sFile, winWidth)  {
   static WS_EX_LAYERED := 0x80000, WS_EX_TRANSPARENT := 0x20

   Gui, New, % &quot;-Caption +AlwaysOnTop +ToolWindow +hwndhGui +E&quot; . Format(&quot;{:#x}&quot;, WS_EX_LAYERED|WS_EX_TRANSPARENT)
   Gui, Show, Hide

   pToken := GDIp.Gdip_Startup()

   pBitmap := GDIp.Gdip_CreateBitmapFromFile(sFile)
   width := GDIp.Gdip_GetImageWidth(pBitmap)
   height := GDIp.Gdip_GetImageHeight(pBitmap)
   hbm := GDIp.CreateDIBSection(winWidth, winHeight := winWidth/width*height)
   hdc := GDIp.CreateCompatibleDC()
   obm := GDIp.SelectObject(hdc, hbm)

   G := GDIp.Gdip_GraphicsFromHDC(hdc)
   GDIp.Gdip_SetInterpolationMode(G, 7)
   GDIp.Gdip_DrawImage(G, pBitmap, 0, 0, winWidth, winHeight, 0, 0, width, height)

   GDIp.UpdateLayeredWindow(hGui, hdc, 0, 0, winWidth, winHeight)

   GDIp.SelectObject(hdc, obm), GDIp.DeleteObject(hbm), GDIp.DeleteDC(hdc)
   GDIp.Gdip_DeleteGraphics(G), GDIp.Gdip_DisposeImage(pBitmap)
   GDIp.Gdip_Shutdown(pToken)
   
   Return hGui
}

BindToWindow(bound, winClass)  {
   static EVENT_OBJECT_LOCATIONCHANGE := 0x800B, hHook, oInfo := {}
   
   DllCall(&quot;RegisterShellHookWindow&quot;, Ptr, A_ScriptHwnd) 
   OnMessage( DllCall(&quot;RegisterWindowMessage&quot;, Str, &quot;SHELLHOOK&quot;), Func(&quot;ShellProc&quot;).Bind(bound, winClass) )
   
   oInfo.bound := bound, oInfo.parentWinClass := winClass
   pInfo := Object(oInfo)
   hHook := SetWinEventHook( EVENT_OBJECT_LOCATIONCHANGE, EVENT_OBJECT_LOCATIONCHANGE, 0
                           , RegisterCallback(&quot;HookProc&quot;, &quot;F&quot;, 3, pInfo), 0, 0, 0 )
   ObjRelease(pInfo)
   OnExit( Func(&quot;Exit&quot;).Bind(A_ScriptHwnd, hHook) )
}

ShellProc(bound, parentWinClass, nCode, wParam)  {
   if (nCode = 4)  {  ; HSHELL_WINDOWACTIVATED := 4
      hwnd := wParam
      WinGetClass, winClass, ahk_id %hwnd%
      if (winClass != parentWinClass)
         Gui, %bound%:Show, Hide
      else  {
         VarSetCapacity(WINDOWPLACEMENT, size := 4*11, 0)
         NumPut(size, WINDOWPLACEMENT)
         DllCall(&quot;GetWindowPlacement&quot;, Ptr, hwnd, Ptr, &amp;WINDOWPLACEMENT)
         for k, v in [&quot;x&quot;, &quot;y&quot;]
            %v% := NumGet(WINDOWPLACEMENT, 4*(k + 6), &quot;Int&quot;)
         Gui, %bound%:Show, % &quot;NA x&quot; . (x + 5) . &quot; y&quot; (y + 5)
      }
   }
}

SetWinEventHook(eventMin, eventMax, hmodWinEventProc, lpfnWinEventProc, idProcess, idThread, dwFlags)  {
   return DllCall(&quot;SetWinEventHook&quot;, UInt, eventMin, UInt, eventMax
                                   , Ptr, hmodWinEventProc, Ptr, lpfnWinEventProc
                                   , UInt, idProcess , UInt, idThread, UInt, dwFlags, Ptr)
}

HookProc(hWinEventHook, event, hwnd)  {
   oInfo := Object(A_EventInfo)
   parentWinClass := oInfo.parentWinClass, bound := oInfo.bound
   WinGetClass, winClass, ahk_id %hwnd%
   if (winClass != parentWinClass)
      Return
   
   WinGetPos, x, y,,, ahk_id %hwnd%
   Gui, %bound%:Show, % &quot;NA x&quot; . (x + 5) . &quot; y&quot; (y + 5)
}

Exit(shellHookWindow, winEventHook)  {
   DllCall(&quot;DeregisterShellHookWindow&quot;, Ptr, shellHookWindow)
   DllCall(&quot;UnhookWinEvent&quot;, Ptr, winEventHook)
}

class GDIp   {
   Gdip_Startup()  {
      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)
      return pToken
   }

   Gdip_CreateBitmapFromFile(sFile)  {
      DllCall(&quot;gdiplus\GdipCreateBitmapFromFile&quot;, WStr, sFile, PtrP, pBitmap)
      return pBitmap
   }

   Gdip_GetImageWidth(pBitmap)  {
      DllCall(&quot;gdiplus\GdipGetImageWidth&quot;, Ptr, pBitmap, UIntP, Width)
      return Width
   }
   
   Gdip_GetImageHeight(pBitmap)  {
      DllCall(&quot;gdiplus\GdipGetImageHeight&quot;, Ptr, pBitmap, UIntP, Height)
      return Height
   }

   CreateDIBSection(w, h, hdc=&quot;&quot;, bpp=32, ByRef ppvBits=0)  {
      hdc2 := hdc ? hdc : this.GetDC()
      VarSetCapacity(bi, 40, 0)
      
      NumPut(w, bi, 4, &quot;UInt&quot;), NumPut(h, bi, 8, &quot;UInt&quot;), NumPut(40, bi, 0, &quot;UInt&quot;)
      NumPut(1, bi, 12, &quot;ushort&quot;), NumPut(0, bi, 16, &quot;uInt&quot;), NumPut(bpp, bi, 14, &quot;ushort&quot;)
      
      hbm := DllCall(&quot;CreateDIBSection&quot;, Ptr, hdc2, Ptr, &amp;bi, UInt, 0, PtrP, ppvBits, Ptr, 0, UInt, 0, Ptr)

      if !hdc
         this.ReleaseDC(hdc2)
      return hbm
   }

   GetDC(hwnd=0)  {
      return DllCall(&quot;GetDC&quot;, Ptr, hwnd)
   }
   
   CreateCompatibleDC(hdc=0)  {
      return DllCall(&quot;CreateCompatibleDC&quot;, Ptr, hdc)
   }

   SelectObject(hdc, hgdiobj)  {
      return DllCall(&quot;SelectObject&quot;, Ptr, hdc, Ptr, hgdiobj)
   }

   Gdip_GraphicsFromHDC(hdc)  {
       DllCall(&quot;gdiplus\GdipCreateFromHDC&quot;, Ptr, hdc, PtrP, pGraphics)
       return pGraphics
   }

   Gdip_SetInterpolationMode(pGraphics, InterpolationMode)  {
      return DllCall(&quot;gdiplus\GdipSetInterpolationMode&quot;, Ptr, pGraphics, Int, InterpolationMode)
   }
   
   Gdip_DrawImage(pGraphics, pBitmap, dx, dy, dw, dh, sx, sy, sw, sh)  {
      Return DllCall(&quot;gdiplus\GdipDrawImageRectRect&quot;, Ptr, pGraphics, Ptr, pBitmap
                                                    , Float, dx, Float, dy, Float, dw, Float, dh
                                                    , Float, sx, Float, sy, Float, sw, Float, sh
                                                    , Int, 2, Ptr, 0, Ptr, 0, Ptr, 0)
   }
   
   UpdateLayeredWindow(hwnd, hdc, x=&quot;&quot;, y=&quot;&quot;, w=&quot;&quot;, h=&quot;&quot;, Alpha=255)  {
      if ((x != &quot;&quot;) &amp;&amp; (y != &quot;&quot;))
         VarSetCapacity(pt, 8), NumPut(x, pt, 0, &quot;UInt&quot;), NumPut(y, pt, 4, &quot;UInt&quot;)

      if (w = &quot;&quot;) ||(h = &quot;&quot;)
         WinGetPos,,, w, h, ahk_id %hwnd%
      
      return DllCall(&quot;UpdateLayeredWindow&quot;, Ptr, hwnd, Ptr, 0, Ptr, ((x = &quot;&quot;) &amp;&amp; (y = &quot;&quot;)) ? 0 : &amp;pt
                                          , Int64P, w|h&lt;&lt;32, Ptr, hdc, Int64P, 0, UInt, 0
                                          , &quot;UInt*&quot;, Alpha&lt;&lt;16|1&lt;&lt;24, UInt, 2)
   }

   ReleaseDC(hdc, hwnd=0)  {
      return DllCall(&quot;ReleaseDC&quot;, Ptr, hwnd, Ptr, hdc)
   }

   DeleteDC(hdc)  {
      return DllCall(&quot;DeleteDC&quot;, Ptr, hdc)
   }

   DeleteObject(hObject)  {
      return DllCall(&quot;DeleteObject&quot;, Ptr, hObject)
   }

   Gdip_DeleteGraphics(pGraphics)  {
      return DllCall(&quot;gdiplus\GdipDeleteGraphics&quot;, Ptr, pGraphics)
   }

   Gdip_DisposeImage(pBitmap)  {
      return DllCall(&quot;gdiplus\GdipDisposeImage&quot;, Ptr, pBitmap)
   }
   
   Gdip_Shutdown(pToken)  {
      DllCall(&quot;gdiplus\GdiplusShutdown&quot;, Ptr, pToken)
      if hModule := DllCall(&quot;GetModuleHandle&quot;, Str, &quot;gdiplus&quot;, Ptr)
         DllCall(&quot;FreeLibrary&quot;, Ptr, hModule)
   }
}
</code></pre></div>]]></description>
			<author><![CDATA[null@example.com (ttt480)]]></author>
			<pubDate>Sun, 09 Aug 2020 23:19:34 +0000</pubDate>
			<guid>https://forum.script-coding.com/viewtopic.php?pid=141586#p141586</guid>
		</item>
	</channel>
</rss>
