Advertisement
RiDeag

Change Window Title

Aug 20th, 2013
321
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #NoTrayIcon
  2.  
  3. ; EVENT_OBJECT_NAMECHANGE = 0x800C
  4. ; WINEVENT_OUTOFCONTEXT = 0x0000
  5. hook := DllCall("SetWinEventHook", "uint", 0x800C, "uint", 0x800C
  6.     , "uint", 0, "uint", RegisterCallback("ObjectNameChange")
  7.     , "uint", 0, "uint", 0, "uint", 0)
  8. OnExit, UnHook
  9.  
  10. #t::
  11.     active := WinExist("A")+0
  12.     WinGetTitle, title
  13.     InputBox, newtitle, Enter new title:,,,600,100,,,,, %title% ; yay commas
  14.     If !ErrorLevel {
  15.         WinSetTitle, %newtitle%
  16.         Win_%active% := newtitle
  17.     }
  18. return
  19.  
  20. ObjectNameChange(hWinEventHook, event, hwnd, idObject, idChild, thread, time){
  21.     ; If the object is a window (OBJID_WINDOW), is not hidden, and is not a child window,
  22.     if (idObject=0) && WinExist("ahk_id " hwnd) && DllCall("GetAncestor","uint",hwnd,"uint",1)=DllCall("GetDesktopWindow")
  23.         If(newtitle := Win_%hwnd%)!=""{
  24.             WinGetTitle, title, ahk_id %hwnd%
  25.             If(title != newtitle)
  26.                 WinSetTitle, ahk_id %hwnd%,, %newtitle%
  27.         }
  28. }
  29. UnHook:
  30.     ExitApp, DllCall("UnhookWinEvent", "uint", hook) ; Yes, this works.
  31. Return
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement