clawe

Run ETS2 FreeTrack Xpadder v2 (better tray clear function)

Aug 13th, 2014
290
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #Persistent
  2. #SingleInstance, Force
  3. SetTitleMatchMode, RegEx
  4.  
  5. ets2_path := "D:\Steam\steamapps\common\Euro Truck Simulator 2\bin\win_x86\"
  6. freetrack_path := "C:\Program Files (x86)\FreeTrack\"
  7. xpadder_path := "D:\"
  8.  
  9. xpadder:
  10. IfWinExist, ^Xpadder$
  11. {
  12.     goto facetrack
  13. }
  14. else
  15. {
  16.     Run, Xpadder.exe ETS2, %xpadder_path%
  17.     sleep, 1000
  18.     goto facetrack
  19. }
  20.  
  21. facetrack:
  22. IfWinExist, ^FaceTrackNoIR.*ETS2.ini$
  23. {
  24.     goto ets2
  25. }
  26. else
  27. {
  28.     Run, FaceTrackNoIR.exe, %freetrack_path%
  29.     sleep, 1000
  30.     goto ets2
  31. }
  32.  
  33. ets2:
  34. IfWinExist, ^Euro Truck Simulator 2$
  35. {
  36.     goto looping
  37. }
  38. else
  39. {
  40.     Run, eurotrucks2.exe, %ets2_path%
  41.     sleep, 5000
  42.     goto looping
  43. }
  44.  
  45. looping:
  46. Loop
  47. {
  48.     IfWinNotExist, ^Euro Truck Simulator 2$
  49.     {
  50.         Process,close,FaceTrackNoIR.exe
  51.         Process,close,Xpadder.exe
  52.         NoTrayOrphans()        
  53.         ExitApp
  54.     }
  55. }
  56. return
  57.  
  58. ; http://www.autohotkey.com/board/topic/80624-notrayorphans/
  59. NoTrayOrphans() {
  60.     TrayInfo:= TrayIcons(sExeName,"ahk_class Shell_TrayWnd","ToolbarWindow32" . GetTrayBar()) "`n"
  61.         . TrayIcons(sExeName,"ahk_class NotifyIconOverflowWindow","ToolbarWindow321")
  62.     Loop, Parse, TrayInfo, `n
  63.         {
  64.         ProcessName:= StrX(A_Loopfield, "| Process: ", " |")
  65.         ProcesshWnd:= StrX(A_Loopfield, "| hWnd: ", " |")
  66.         ProcessuID := StrX(A_Loopfield, "| uID: ", " |")
  67.         If !ProcessName && ProcesshWnd
  68.             RemoveTrayIcon(ProcesshWnd, ProcessuID)
  69.         }
  70.     }
  71. RemoveTrayIcon(hWnd, uID, nMsg = 0, hIcon = 0, nRemove = 2) {
  72.     NumPut(VarSetCapacity(ni,444,0), ni)
  73.     NumPut(hWnd , ni, 4)
  74.     NumPut(uID  , ni, 8)
  75.     NumPut(1|2|4, ni,12)
  76.     NumPut(nMsg , ni,16)
  77.     NumPut(hIcon, ni,20)
  78.     Return    DllCall("shell32\Shell_NotifyIconA", "Uint", nRemove, "Uint", &ni)
  79.     }
  80. TrayIcons(sExeName,traywindow,control) {
  81.     DetectHiddenWindows, On
  82.     WinGet,   pidTaskbar, PID, %traywindow%
  83.     hProc:=   DllCall("OpenProcess", "Uint", 0x38, "int", 0, "Uint", pidTaskbar)
  84.     pProc:=   DllCall("VirtualAllocEx", "Uint", hProc, "Uint", 0, "Uint", 32, "Uint", 0x1000, "Uint", 0x4)
  85.     SendMessage, 0x418, 0, 0, %control%, %traywindow%
  86.     Loop,   %ErrorLevel%
  87.     {
  88.     SendMessage, 0x417, A_Index-1, pProc, %control%, %traywindow%
  89.     VarSetCapacity(btn,32,0), VarSetCapacity(nfo,32,0)
  90.     DllCall("ReadProcessMemory", "Uint", hProc, "Uint", pProc, "Uint", &btn, "Uint", 32, "Uint", 0)
  91.     iBitmap   := NumGet(btn, 0)
  92.     idn   := NumGet(btn, 4)
  93.     Statyle := NumGet(btn, 8)
  94.     If   dwData   := NumGet(btn,12)
  95.     iString   := NumGet(btn,16)
  96.     Else   dwData   := NumGet(btn,16,"int64"), iString:=NumGet(btn,24,"int64")
  97.     DllCall("ReadProcessMemory", "Uint", hProc, "Uint", dwData, "Uint", &nfo, "Uint", 32, "Uint", 0)
  98.     If   NumGet(btn,12)
  99.     hWnd   := NumGet(nfo, 0)
  100.     ,   uID   := NumGet(nfo, 4)
  101.     ,   nMsg   := NumGet(nfo, 8)
  102.     ,   hIcon   := NumGet(nfo,20)
  103.     Else   hWnd   := NumGet(nfo, 0,"int64"), uID:=NumGet(nfo, 8), nMsg:=NumGet(nfo,12), hIcon := NumGet(nfo,24)
  104.     WinGet, pid, PID,             ahk_id %hWnd%
  105.     WinGet, sProcess, ProcessName, ahk_id %hWnd%
  106.     WinGetClass, sClass,           ahk_id %hWnd%
  107.     If !sExeName || (sExeName = sProcess) || (sExeName = pid)
  108.     VarSetCapacity(sTooltip,128), VarSetCapacity(wTooltip,128*2)
  109.     ,   DllCall("ReadProcessMemory", "Uint", hProc, "Uint", iString, "Uint", &wTooltip, "Uint", 128*2, "Uint", 0)
  110.     ,   DllCall("WideCharToMultiByte", "Uint", 0, "Uint", 0, "str", wTooltip, "int", -1, "str", sTooltip, "int", 128, "Uint", 0, "Uint", 0)
  111.     ,   sTrayIcons .= "idx: " . A_Index-1 . " | idn: " . idn . " | Pid: " . pid . " | uID: " . uID . " | MessageID: " . nMsg . " | hWnd: " . hWnd . " | Class: " . sClass . " | Process: " . sProcess . " | Icon: " . hIcon . " | Tooltip: " . wTooltip . "`n"
  112.     }
  113.     DllCall("VirtualFreeEx", "Uint", hProc, "Uint", pProc, "Uint", 0, "Uint", 0x8000)
  114.     DllCall("CloseHandle", "Uint", hProc)
  115.     return   sTrayIcons
  116.     }
  117. GetTrayBar() {
  118.     ControlGet, hParent, hWnd,, TrayNotifyWnd1  , ahk_class Shell_TrayWnd
  119.     ControlGet, hChild , hWnd,, ToolbarWindow321, ahk_id %hParent%
  120.     Loop {
  121.         ControlGet, hWnd, hWnd,, ToolbarWindow32%A_Index%, ahk_class Shell_TrayWnd
  122.         If  Not    hWnd
  123.         Break
  124.         Else If    hWnd = %hChild%
  125.             {
  126.             idxTB := A_Index
  127.             Break
  128.             }
  129.         }
  130.     Return    idxTB
  131.     }
  132.  
  133. StrX( H,BS="",ES="",Tr=1,ByRef OS=1) {
  134.     return,(SP := InStr(H,BS,0,OS)) && (L := InStr(H,ES,0,SP+StrLen(BS))) && (OS := L + StrLen(ES)) ? SubStr(H,SP := Tr ? SP + StrLen(BS) : SP ,(Tr ? L : L + StrLen(ES))-SP) : ""
  135.     }
Add Comment
Please, Sign In to add comment