Advertisement
Enlight432

Untitled

Mar 10th, 2025
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #Requires AutoHotkey v2
  2. #SingleInstance Force
  3. Persistent
  4.  
  5. Run("notepad++")
  6. Sleep(1000)
  7. WinMaximize "A"
  8. while (!WinExist("ahk_exe notepad++.exe"))
  9.     Sleep(3000)
  10. WinIds := []
  11. CurrWindow := WinGetID("ahk_exe notepad++.exe")
  12. WinSetStyle("-0xC00000", "ahk_exe notepad++.exe")
  13. WinIds.Push(CurrWindow)
  14. EVENT_OBJECT_LOCATIONCHANGE := 0x800B
  15. hook := WinEventHook(LocationChangeEventHandler, EVENT_OBJECT_LOCATIONCHANGE, EVENT_OBJECT_LOCATIONCHANGE, CurrWindow)
  16.  
  17. LocationChangeEventHandler(hWinEventHook, event, hwnd, idObject, idChild, idEventThread, dwmsEventTime) {
  18.     Critical -1
  19.     idObject := idObject << 32 >> 32, idChild := idChild << 32 >> 32, event &= 0xFFFFFFFF, idEventThread &= 0xFFFFFFFF, dwmsEventTime &= 0xFFFFFFFF ; convert to INT/UINT
  20.     InList := false
  21.     for WinId in WinIds {
  22.         InList := (WinId = Hwnd) ? true : InList
  23.     }
  24.     if (!InList) {
  25.         return
  26.     }
  27.     if (WinGetMinMax(Hwnd) = 1) {
  28.         WinGetPos(&X, &Y, &Width, &Height, Hwnd)
  29.         WinGetPos(&TaskbarX, &TaskbarY, &TaskbarW, &TaskbarH, "ahk_class Shell_TrayWnd")
  30.         WinRestore(Hwnd)
  31.         WinMove(X, Y, Width, Height - TaskBarH, Hwnd)
  32.     }
  33.     return
  34. }
  35.  
  36. class WinEventHook {
  37.     __New(callback, eventMin?, eventMax?, winTitle := 0, PID := 0, skipOwnProcess := false) {
  38.         if !HasMethod(callback)
  39.             throw ValueError("The callback argument must be a function", -1)
  40.         if !IsSet(eventMin)
  41.             eventMin := 0x00000001, eventMax := IsSet(eventMax) ? eventMax : 0x7fffffff
  42.         else if !IsSet(eventMax)
  43.             eventMax := eventMin
  44.         this.callback := callback, this.winTitle := winTitle, this.flags := skipOwnProcess ? 2 : 0, this.eventMin := eventMin, this.eventMax := eventMax, this.threadId := 0
  45.         if winTitle != 0 {
  46.             if !(this.winTitle := WinExist(winTitle))
  47.                 throw TargetError("Window not found", -1)
  48.             this.threadId := DllCall("GetWindowThreadProcessId", "Int", this.winTitle, "UInt*", &PID)
  49.         }
  50.         this.pCallback := CallbackCreate(callback, "C Fast", 7)
  51.         , this.hHook := DllCall("SetWinEventHook", "UInt", eventMin, "UInt", eventMax, "Ptr", 0, "Ptr", this.pCallback, "UInt", this.PID := PID, "UInt", this.threadId, "UInt", this.flags)
  52.     }
  53.     Stop() => this.__Delete()
  54.     __Delete() {
  55.         if (this.pCallback)
  56.             DllCall("UnhookWinEvent", "Ptr", this.hHook), CallbackFree(this.pCallback), this.hHook := 0, this.pCallback := 0
  57.     }
  58. }
  59.  
  60.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement