JLMoss

Launcher

Sep 10th, 2021 (edited)
178
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ; Title: Launcher.ahk
  2. ; Version: 1.0.2
  3. ; Site: https://www.jameslmoss.com/2021/08/28/poe-launcher/
  4. ; Credits: Autohotkey docs and other's mentioned in the code
  5. #NoEnv
  6. #SingleInstance ignore
  7. #Persistent
  8. SetTitleMatchMode, 1
  9.  
  10. SetWorkingDir, %A_ScriptDir%
  11.  
  12. ; Config File
  13. global INI_FILE := "config.ini"
  14.  
  15. ; Default settings
  16. ; Abbreviated Title of the app being launched
  17. global notifyShow := 0
  18. IniRead, notifyShow, %INI_FILE%, Defaults, notifyShow, "PoE"   
  19. global launcherTitle := "PoE"
  20. IniRead, launcherTitle, %INI_FILE%, Defaults, launcherTitle, "PoE"
  21. ; Limit the number of times the process can run
  22. global processMax := 0
  23. IniRead, processMax, %INI_FILE%, Defaults, processMax, 0
  24. ; Delay to wait for the process to load
  25. global loadDelay := 3500
  26. IniRead, loadDelay, %INI_FILE%, Defaults, loadDelay, 3500
  27. ; Set to 1 to load POE when this program starts
  28. global loadOnStart := 0
  29. IniRead, loadOnStart, %INI_FILE%, Defaults, loadOnStart, 0
  30. ; Set to 1 to close when you click exit to close the program
  31. global closeOnExit := 0
  32. IniRead, closeOnExit, %INI_FILE%, Defaults, closeOnExit, 0
  33. ; Set to 1 to auto tweak the window when this program starts (play around with it see other settings)
  34. global setResOnStart := 0
  35. IniRead, setResOnStart, %INI_FILE%, Defaults, setResOnStart, 0
  36. ; Set to 1 to auto tweak the process level when the program starts, it will change it from normal to the value of defaultLevel
  37. global setLevelOnStart := 0
  38. IniRead, setLevelOnStart, %INI_FILE%, Defaults, setLevelOnStart, 0
  39. ; Generally lave this alone, it's the same values from the details pain in your taskmanager if you click -> Set Priority on a program
  40. global defaultLevel := "Normal"
  41. IniRead, defaultLevel, %INI_FILE%, Defaults, defaultLevel, "Normal"
  42.  
  43.  
  44. ; Path and WindowClass settings
  45. global programPath := "C:\Program Files (x86)\Grinding Gear Games\Path of Exile\"
  46. IniRead, programPath, %INI_FILE%, Paths, programPath, "C:\Program Files (x86)\Grinding Gear Games\Path of Exile\"
  47. global programFile := "PathOfExile_x64.exe"
  48. IniRead, programFile, %INI_FILE%, Paths, programFile, "PathOfExile_x64.exe"
  49. global windowTitle := "Path of Exile"
  50. IniRead, windowTitle, %INI_FILE%, Paths, windowTitle, "Path of Exile"
  51. global windowClass := "POEWindowClass"
  52. IniRead, windowClass, %INI_FILE%, Paths, windowClass, "POEWindowClass"
  53.  
  54. ; Internal variable
  55. ;global loadDelay := 3500 ; Play with this value
  56. global hWndCount := 0
  57.    
  58. ; Delete the standard tray menu items
  59. Menu,Tray,NoStandard
  60.  
  61. global assetDir := A_ScriptDir . "\Assets\"
  62.  
  63. I_Icon = %assetDir%launcher.ico
  64. ICON [I_Icon]
  65. if I_Icon <>
  66. IfExist, %I_Icon%
  67.     Menu, Tray, Icon, %I_Icon%   ;Changes menu tray icon
  68.    
  69. FileURL_Icon =  %assetDir%FileURL-3.ico
  70. ICON [FileURL_Icon]
  71. if FileURL_Icon <>
  72.  
  73. ;Menu, Tray, Add, &Path of Exile, :Submenu1
  74. Menu, Tray, Add, &Launch %launcherTitle%, TrayMenu
  75. Menu, Tray, Icon, &Launch %launcherTitle%, %I_Icon%,,
  76. Menu, Tray, Add
  77. Menu, Tray, Add, &Close %launcherTitle%, TrayMenu
  78. Menu, Tray, Add, &TweakWindow, TrayMenu
  79.  
  80. ; Setup the Quicklinks Directory
  81. global quicklinkDir := A_ScriptDir . "\QuickLinks\"
  82. ; Variable to know if the quick links directory exists or not
  83. global hasQuickLinks := 0
  84. ; Set the above variable if the directory exists
  85. IfExist, %quicklinkDir%
  86.     hasQuickLinks = 1
  87. ; If the quick links directory exists dive in
  88. if(hasQuickLinks == 1){
  89.     ;MsgBox, Found: %quicklinkDir%
  90.     ; Quicklinks Array
  91.     global quickLinks := Array()
  92.     ; Fill the QuickLinks Array
  93.     global quickLinksCount := GetQuickLinksArray(quickLinks,quicklinkDir,"*.exe,*.lnk,*.url")
  94.     if(quickLinks.Count() >= 1) {
  95.         tmpFileOut := ""   
  96.         tmpFileDir := ""
  97.         tmpFileExt := ""           
  98.         tmpFileOutnoExt := ""          
  99.         tmpFileArgs := ""
  100.         tmpFileDesc := ""
  101.         tmpFileIcon := ""
  102.         tmpFileIconNum := ""
  103.         tmpFileState := ""     
  104.         ; Loop thru the QuickLinks array to add menu items
  105.         for i, var in quickLinks {
  106.             tmpFileDir := quicklinkDir . var
  107.            
  108.             ; SplitPath, InputVar , OutFileName, OutDir, OutExtension, OutNameNoExt, OutDrive
  109.             SplitPath, var, tmpFileOut, , tmpFileExt, tmpFileOutnoExt,
  110.        
  111.             ; Add Menu Items
  112.             Menu, QuickLinksMenu, Add, %tmpFileOutnoExt%, TrayMenu     
  113.         }
  114.         ; Add the QuickLinks Menu
  115.         Menu, Tray, Add, &QuickLinks, :QuickLinksMenu
  116.         Menu, Tray, Default, &QuickLinks           
  117.     }
  118.  
  119. }
  120.  
  121. Menu, Tray, Add
  122.  
  123. ; Create submenu items that will become menu items under &Set Process Level
  124. ;Menu, Submenu1, Add, High, TrayMenu
  125. Menu, Submenu1, Add, Above Normal, TrayMenu
  126. Menu, Submenu1, Add, Normal, TrayMenu
  127. Menu, Submenu1, Add, Below Normal, TrayMenu
  128.  
  129. ; Create a menu container for the submenu's above
  130. Menu, Tray, Add, Set Process Level, :Submenu1
  131. Menu, Tray, Default, Set Process Level
  132.  
  133. ; Create submenu items that will become menu items under &Settings
  134. Menu, Submenu2, Add, AutoLoad on Start, TrayMenu
  135. Menu, Submenu2, Add, AutoClose on Exit, TrayMenu
  136. Menu, Submenu2, Add, Set Process Level on Start, TrayMenu
  137. Menu, Submenu2, Add, Tweak Window on Start, TrayMenu
  138. Menu, Submenu2, Add
  139. ; Create a menu container for the submenu's above
  140. Menu, Tray, Add, &Settings, :Submenu2
  141. Menu, Tray, Default, &Settings
  142.    
  143. Menu, Tray, Add
  144. Menu, Tray, Add, E&xit, TrayMenu
  145. Menu, Tray, Default, &Launch %launcherTitle%
  146.  
  147. GoSub OnStart
  148. ;OnExit("WriteConfig")
  149. OnExit, ExitSub  
  150. Return
  151.  
  152. ExitSub:
  153.     WriteConfig()
  154. ExitApp
  155.  
  156. TrayMenu:
  157.     if(hasQuickLinks == 1){
  158.         if(quickLinksCount >= 1) {
  159.             for i, var in quickLinks {
  160.                 zMenuItem := ""
  161.                 tmpFileFull := quickLinkDir . var
  162.                 ;MsgBox, FileName: %tmpFileFull%
  163.                 if FileExist(tmpFileFull) {            
  164.                     tmpFileOut := ""
  165.                     tmpFileOut := ""   
  166.                     tmpFileDir := ""
  167.                     tmpFileExt := ""           
  168.                     tmpFileOutnoExt := ""          
  169.                     tmpFileArgs := ""
  170.                     tmpFileDesc := ""
  171.                     tmpFileIcon := ""
  172.                     tmpFileIconNum := ""
  173.                     tmpFileState := ""                     
  174.                     ; SplitPath, InputVar , OutFileName, OutDir, OutExtension, OutNameNoExt, OutDrive
  175.                     SplitPath, tmpFileFull, tmpFileOut, tmpFileDir, tmpFileExt, zMenuItem,
  176.                     if(A_ThisMenuItem=zMenuItem){
  177.                         pID := ""
  178.                         ;Run, Target , WorkingDir, Options, OutputVarPID
  179.                         Run, %tmpFileFull%,%tmpFileDir%,,pID
  180.                         break
  181.                     }              
  182.                 }
  183.             }
  184.         }
  185.     }
  186.    
  187.     If (A_ThisMenuItem="&Launch " launcherTitle) {     
  188.         Launch("ahk_class " windowClass)
  189.     Return
  190.     }
  191.    
  192.     If (A_ThisMenuItem="&TweakWindow") {
  193.         if(notifyShow)
  194.             Notify(launcherTitle " Launcher","Tweaking: " windowTitle, 1,"TS=12 MS=12","")         
  195.         TweakWindow("ahk_class " windowClass)
  196.         Return
  197.     }
  198.    
  199.     If (A_ThisMenuItem="&Close " launcherTitle) {
  200.         ClosePoE("ahk_class " windowClass)
  201.     Return
  202.     }  
  203.    
  204.     If (A_ThisMenuItem="&Settings") {
  205.     Return
  206.     }          
  207.    
  208.     If (A_ThisMenuItem="AutoLoad on Start") {
  209.         Menu, Submenu2, ToggleCheck, AutoLoad on Start
  210.         if(loadOnStart = 1){
  211.             if(notifyShow)
  212.                 Notify(launcherTitle " Launcher","AutoLoad: Off", 1,"TS=12 MS=12","")      
  213.             loadOnStart := 0
  214.         } else {
  215.             if(notifyShow)
  216.                 Notify(launcherTitle " Launcher","AutoLoad: On", 1,"TS=12 MS=12","")                   
  217.             loadOnStart := 1       
  218.         }
  219.         IniWrite, %loadOnStart%, %INI_FILE%, Defaults, loadOnStart
  220.         if (ErrorLevel = 1) {
  221.             MsgBox, Error writing loadOnStart %loadOnStart%
  222.         }
  223.         GoSub OnStart
  224.     Return
  225.     }
  226.    
  227.     If (A_ThisMenuItem="AutoClose on Exit") {
  228.       Menu, Submenu2, ToggleCheck, AutoClose on Exit
  229.         if(closeOnExit = 1){
  230.             if(notifyShow)
  231.                 Notify(launcherTitle " Launcher","AutoClose: Off", 1,"TS=12 MS=12","")                 
  232.             closeOnExit := 0
  233.         } else {
  234.             if(notifyShow)
  235.                 Notify(launcherTitle " Launcher","AutoClose: On", 1,"TS=12 MS=12","")          
  236.             closeOnExit := 1   
  237.         }
  238.         IniWrite, %closeOnExit%, %INI_FILE%, Defaults, closeOnExit
  239.         if (ErrorLevel = 1) {
  240.             MsgBox, Error writing closeOnExit %closeOnExit%
  241.         }
  242.     Return
  243.     }
  244.  
  245.     If (A_ThisMenuItem="Set Process Level on Start") {
  246.       Menu, Submenu2, ToggleCheck, Set Process Level on Start
  247.         if(setLevelOnStart = 1){
  248.             if(notifyShow)
  249.                 Notify(launcherTitle " Launcher","Set Process Level On Start: Off", 1,"TS=12 MS=12","")                
  250.             setLevelOnStart := 0
  251.         } else {
  252.             if(notifyShow)
  253.                 Notify(launcherTitle " Launcher","Set Process Level On Start: On", 1,"TS=12 MS=12","")                             
  254.             setLevelOnStart := 1   
  255.         }
  256.         IniWrite, %setLevelOnStart%, %INI_FILE%, Defaults, setLevelOnStart
  257.         if (ErrorLevel = 1) {
  258.             MsgBox, Error writing setLevelOnStart %setLevelOnStart%
  259.         }        
  260.     Return
  261.     }
  262.    
  263.     If (A_ThisMenuItem="Tweak Window on Start") {
  264.       Menu, Submenu2, ToggleCheck, Tweak Window on Start
  265.         if(setResOnStart = 1){
  266.             if(notifyShow)
  267.                 Notify(launcherTitle " Launcher","Tweak Window on Start: Off", 1,"TS=12 MS=12","")         
  268.             setResOnStart := 0
  269.         } else {
  270.             if(notifyShow)
  271.                 Notify(launcherTitle " Launcher","Tweak Window on Start: On", 1,"TS=12 MS=12","")                      
  272.             setResOnStart := 1         
  273.         }
  274.         IniWrite, %setResOnStart%, %INI_FILE%, Defaults, setResOnStart
  275.         if (ErrorLevel = 1) {
  276.             MsgBox, Error writing setResOnStart %setResOnStart%
  277.         }              
  278.     Return
  279.     }  
  280.  
  281.     If (A_ThisMenuItem="Below Normal") {
  282.         if(notifyShow)
  283.             Notify(launcherTitle " Launcher","Set Process Level: Below Normal", 1,"TS=12 MS=12","")                
  284.         defaultLevel := "BelowNormal"
  285.         ProcessSetCheck(defaultLevel)          
  286.         IniWrite, %defaultLevel%, %INI_FILE%, Defaults, defaultLevel
  287.         if (ErrorLevel = 1) {
  288.             MsgBox, Error writing defaultLevel %defaultLevel%
  289.         }      
  290.         SetProcessLevel("BelowNormal","ahk_class" windowClass)
  291.     Return
  292.     }  
  293.    
  294.     If (A_ThisMenuItem="Normal") {
  295.         if(notifyShow)
  296.             Notify(launcherTitle " Launcher","Set Process Level: Normal", 1,"TS=12 MS=12","")                          
  297.         defaultLevel := "Normal"
  298.         ProcessSetCheck(defaultLevel)          
  299.         IniWrite, %defaultLevel%, %INI_FILE%, Defaults, defaultLevel
  300.         if (ErrorLevel = 1) {
  301.             MsgBox, Error writing defaultLevel %defaultLevel%
  302.         }          
  303.         SetProcessLevel("Normal","ahk_class" windowClass)
  304.     Return
  305.     }  
  306.    
  307.     If (A_ThisMenuItem="Above Normal") {
  308.         if(notifyShow)
  309.             Notify(launcherTitle " Launcher","Set Process Level: Above Normal", 1,"TS=12 MS=12","")                        
  310.         defaultLevel := "AboveNormal"
  311.         ProcessSetCheck(defaultLevel)          
  312.         IniWrite, %defaultLevel%, %INI_FILE%, Defaults, defaultLevel
  313.         if (ErrorLevel = 1) {
  314.             MsgBox, Error writing defaultLevel %defaultLevel%
  315.         }                  
  316.         SetProcessLevel("AboveNormal","ahk_class" windowClass)
  317.     Return
  318.     }  
  319.    
  320.     ;If (A_ThisMenuItem="High") {
  321.     ;   defaultLevel := "High"
  322.     ;   IniWrite, %defaultLevel%, %INI_FILE%, Defaults, defaultLevel       
  323.     ;Return
  324.     ;}             
  325.  
  326.     If (A_ThisMenuItem="E&xit") {
  327.         if(closeOnExit = 1) {
  328.             if(notifyShow)
  329.                 Notify(launcherTitle " Launcher","Bye bye", 1,"TS=12 MS=12","")                
  330.             CloseAll("ahk_class " windowClass)
  331.         }
  332.       ExitApp
  333.     Return
  334.     }
  335.    
  336. Return
  337.  
  338. ; Install hotkeys
  339. ; Disable the left win key
  340. LWin::
  341.     if (WinActive("ahk_class " windowClass))
  342.     {
  343.         Return
  344.     } else {
  345.         SendInput { LWin }
  346.         Return     
  347.     }
  348. Return
  349.  
  350.  
  351. ; Installs hotkey F10: trigger TweakWindow
  352. F10::
  353.     if (WinActive("ahk_class " windowClass))
  354.     {
  355.         TweakWindow("ahk_class " windowClass)
  356.     } else {
  357.         SendInput {F10}
  358.     }      
  359. Return
  360.  
  361. ; Lib includes are loaded from the Lib folder
  362. #Include <Notify>
  363.  
  364. OnStart:
  365.     SetTimer, HeartBeat, 500   
  366.     if(loadOnStart = 1) {
  367.         Menu, Submenu2, Check, AutoLoad on Start
  368.         Launch("ahk_class " windowClass)
  369.     } else {
  370.         Menu, Submenu2, Uncheck, AutoLoad on Start
  371.     }
  372.  
  373.     if(closeOnExit = 1) {
  374.         Menu, Submenu2, Check, AutoClose on Exit
  375.     } else {
  376.         Menu, Submenu2, Uncheck, AutoClose on Exit
  377.     }          
  378.  
  379.     if(setLevelOnStart = 1) {
  380.         Menu, Submenu2, Check, Set Process Level on Start
  381.     } else {
  382.         Menu, Submenu2, Uncheck, Set Process Level on Start
  383.     }  
  384.  
  385.     if(setResOnStart = 1) {
  386.         Menu, Submenu2, Check, Tweak Window on Start
  387.     } else {
  388.         Menu, Submenu2, Uncheck, Tweak Window on Start
  389.     }
  390.        
  391.     ProcessSetCheck(defaultLevel)
  392.     if(hasQuickLinks == 1){
  393.         tmpFileOut := ""   
  394.         tmpFileDir := ""
  395.         tmpFileExt := ""           
  396.         tmpFileOutnoExt := ""          
  397.         tmpFileArgs := ""
  398.         tmpFileDesc := ""
  399.         tmpFileIcon := ""
  400.         tmpFileIconNum := ""
  401.         tmpFileState := ""
  402.         tmpFileURL := url
  403.            
  404.         ; Loop thru the QuickLinks array to add menu items
  405.         for i, var in quickLinks {
  406.             tmpFileFull := quicklinkDir . var
  407.             ; SplitPath, InputVar , OutFileName, OutDir, OutExtension, OutNameNoExt, OutDrive
  408.             SplitPath, var, tmpFileOut, tmpFileDir, tmpFileExt, tmpFileOutnoExt,
  409.             ;MsgBox, %tmpFileOut%`n%tmpFileDir%`n%tmpFileExt%`n%tmpFileOutnoExt%`n
  410.             ; FileGetShortcut, LinkFile , OutTarget, OutDir, OutArgs, OutDescription, OutIcon, OutIconNum, OutRunState         
  411.             FileGetShortcut, %tmpFileFull%,tmpFileOut,tmpFileDir,tmpFileArgs,tmpFileDesc,tmpFileIcon,tmpFileIconNum,tmpFileState
  412.             ;MsgBox, %tmpFileOut%`n%tmpFileDir%`n%tmpFileExt%`n%tmpFileOutnoExt%`n
  413.             if !ErrorLevel {
  414.                 if (tmpFileOut = "") ; Shortcut .lnk
  415.                 {
  416.                     ;IfExist, %FileURL_Icon%
  417.                     Menu, QuickLinksMenu, Icon, %tmpFileOutnoExt%, %tmpFileFull%,%tmpFileIconNum%,
  418.                 }   else {
  419.                     Menu, QuickLinksMenu, Icon, %tmpFileOutnoExt%, %tmpFileOut%,%tmpFileIconNum%,
  420.                 }  
  421.             } else {           
  422.                 if("url" = tmpFileExt) ; URLFile .url
  423.                 {
  424.                     ;MsgBox, FileExt: %tmpFileExt%
  425.                     Menu, QuickLinksMenu, Icon, %tmpFileOutnoExt%, %FileURL_Icon%,,
  426.                 }
  427.                 if("exe" = tmpFileExt) ;ProgramFIle .exe
  428.                 {
  429.                     Menu, QuickLinksMenu, Icon, %tmpFileOutnoExt%, %tmpFileFull%,,
  430.                 }
  431.                 Continue
  432.             }
  433.         }
  434.     }
  435. Return
  436.  
  437. HeartBeat:
  438.     hwndCount := GetProcessCount("ahk_class " windowClass)
  439.     if WinExist("ahk_class " windowClass)
  440.     {
  441.         Menu, Tray, Enable, &Close %launcherTitle%
  442.         Menu, Tray, Enable, &TweakWindow
  443.     } else {
  444.         Menu, Tray, Disable, &Close %launcherTitle%
  445.         Menu, Tray, Disable, &TweakWindow      
  446.     }  
  447.        
  448. Return
  449.  
  450. Launch(hWnd) {
  451.     hwndCount := GetProcessCount(hWnd)
  452.  
  453.     if(hWndCount < processMax) {
  454.         tmpFileFull := programPath . programFile
  455.         StringReplace, tmpFileFull, tmpFileFull, /, \, All
  456.        
  457.         if FileExist(tmpFileFull) {
  458.             if(notifyShow)
  459.                 Notify(launcherTitle " Launcher","Launching: " windowTitle, 1,"TS=12 MS=12","")        
  460.             tmpFile := ""
  461.             tmpWorkingDir := ""
  462.             tmpFileExt := ""
  463.             tmpFileName := ""
  464.             tmpFileDrive := ""
  465.             pID := ""
  466.             this_id := ""
  467.            
  468.             ; SplitPath, InputVar , OutFileName, OutDir, OutExtension, OutNameNoExt, OutDrive
  469.             SplitPath, tmpFileFull, tmpFile, tmpWorkingDir, tmpFileExt, tmpFileName, tmpFileDrive
  470.  
  471.             ;Run, Target , WorkingDir, Options, OutputVarPID
  472.             Run, %tmpWorkingDir%\%tmpFile%,%tmpWorkingDir%,,pID
  473.             Sleep, %loadDelay%
  474.             WinGet, tmpArray, List , %hWnd%
  475.             iCount := tmpArray
  476.             if(iCount >= 1) {
  477.                 Loop, %tmpArray%
  478.                 {
  479.                 this_id := tmpArray%A_Index%   
  480.                 WinGet, pID, PID, ahk_id %this_id%
  481.                 Process, Exist, pID
  482.                     if !ErrorLevel {
  483.                     if(setResOnStart) {
  484.                         TweakWindow("ahk_id " this_id,1)
  485.                     }          
  486.                     if(setLevelOnStart) {
  487.                             ;MsgBox, Set Level - Window Id: %this_id%                      
  488.                             ;WinActivate, ahk_id %this_id%      
  489.                         SetProcessLevel(defaultLevel,"ahk_class " windowClass)
  490.                     }
  491.                   }        
  492.                 }
  493.             }
  494.     }
  495.     }
  496.     Return
  497. }
  498.  
  499. ClosePoE(hWnd) {
  500.     ;WinGet, OutputVar, List , WinTitle, WinText, ExcludeTitle, ExcludeText
  501.     WinGet, hWndArray, List , %hWnd%
  502.     hWndCount := hWndArray
  503.     if(hWndCount >= 1) {
  504.         Loop, %hWndArray%
  505.         {
  506.             this_id := hWndArray%A_Index%  
  507.             WinGet, pID, PID, ahk_id %this_id%
  508.             Process, Exist, pID
  509.               if !ErrorLevel {
  510.                     WinActivate, ahk_id %this_id%
  511.               MsgBox, 4, , Close this Window?              
  512.                 IfMsgBox, Yes              
  513.                     Process, Close, %pID%
  514.                     hWndCount--        
  515.               }
  516.         }          
  517.     }  
  518.     Return
  519. }
  520.  
  521. CloseAll(hWnd) {
  522.     ;WinGet, OutputVar, List , WinTitle, WinText, ExcludeTitle, ExcludeText
  523.     WinGet, hWndArray, List , %hWnd%
  524.     hWndCount := hWndArray
  525.     if(hWndCount >= 1) {       
  526.         Loop, %hWndArray%
  527.         {
  528.             this_id := hWndArray%A_Index%
  529.             WinGet, pID, PID, ahk_id %this_id%
  530.             Process, Exist, pID
  531.               if !ErrorLevel {     
  532.                 Process, Close, %pID%
  533.                 hWndCount--
  534.                 }
  535.         }
  536.     }  
  537.     Return
  538. }
  539.  
  540. SetProcessLevel(pLevel,hWnd) {
  541.     ;WinGet, OutputVar, List , WinTitle, WinText, ExcludeTitle, ExcludeText
  542.     WinGet, hWndArray, List , %hWnd%
  543.     hWndCount := hWndArray
  544.     if(hWndCount >= 1) {   
  545.         Loop, %hWndArray%
  546.         {
  547.             this_id := hWndArray%A_Index%
  548.             WinGet, pID, PID, ahk_id %this_id%
  549.             Process, Exist, pID
  550.               if !ErrorLevel {
  551.                     Process, Priority, %pID%, %pLevel%
  552.                 }
  553.         }
  554.     }
  555.     Return
  556. }
  557.  
  558. GetProcessPID(hWnd) {
  559.     ;SetTitleMatchMode, 1
  560.     if WinExist(hWnd) {
  561.         ;WinWait, %hWnd%,, 15
  562.         WinActivate, %hWnd%
  563.         ;Sleep, 1000   
  564.         WinGet, pID, PID
  565.         Return pID
  566.     }
  567.     Return 0
  568. }
  569.  
  570. ProcessSetCheck(p) {
  571.     if(p="AboveNormal") {
  572.         Menu, Submenu1, Check, Above Normal
  573.         Menu, Submenu1, Default, Above Normal
  574.         Menu, Submenu1, Uncheck, Normal
  575.         Menu, Submenu1, Uncheck, Below Normal
  576.     } else if(p="Normal") {
  577.         Menu, Submenu1, Uncheck, Above Normal
  578.         Menu, Submenu1, Check, Normal
  579.         Menu, Submenu1, Default, Normal
  580.         Menu, Submenu1, Uncheck, Below Normal      
  581.     } else if(p="BelowNormal") {
  582.         Menu, Submenu1, Uncheck, Above Normal
  583.         Menu, Submenu1, Uncheck, Normal
  584.         Menu, Submenu1, Check, Below Normal
  585.         Menu, Submenu1, Default, Below Normal      
  586.     }  
  587.     Return
  588. }
  589.  
  590. WriteConfig() {
  591.     /*
  592.     [Defaults]
  593.     ; Abbreviated Title of the app being launched
  594.     launcherTitle=PoE
  595.     ; Limit the number of times the process can run
  596.     processMax=2
  597.     ; Delay to wait for the process to load
  598.     loadDelay=3500
  599.     ; Load Path of Exile when you run the script, 0=Off, 1=On
  600.     loadOnStart=0
  601.     ; Close Path of Exile when you exit the script, 0=Off, 1=On
  602.     closeOnExit=0
  603.     ; Set a borderless 1080p'ish window adjustment when you launch POE, 0=Off, 1=On
  604.     setResOnStart=0
  605.     ; Set the POE Process level when you launch POE, 0=Off, 1=On
  606.     setLevelOnStart=0
  607.     ; The process priority level values can be : AboveNormal, Normal, BelowNormal
  608.     defaultLevel=Normal
  609.     */
  610.     ;IniWrite, Value, Filename, Section, Key
  611.    
  612.     ; Section Defaults
  613.     IniWrite, %notifyShow%, %INI_FILE%, Defaults, notifyShow
  614.     IniWrite, %launcherTitle%, %INI_FILE%, Defaults, launcherTitle
  615.     IniWrite, %processMax%, %INI_FILE%, Defaults, processMax
  616.     IniWrite, %loadDelay%, %INI_FILE%, Defaults, loadDelay
  617.     IniWrite, %loadOnStart%, %INI_FILE%, Defaults, loadOnStart
  618.     IniWrite, %closeOnExit%, %INI_FILE%, Defaults, closeOnExit
  619.     IniWrite, %setLevelOnStart%, %INI_FILE%, Defaults, setLevelOnStart
  620.     IniWrite, %setResOnStart%, %INI_FILE%, Defaults, setResOnStart
  621.     IniWrite, %defaultLevel%, %INI_FILE%, Defaults, defaultLevel
  622.  
  623.     /*
  624.     [Paths]
  625.     ; Path to the POE folder, default: C:\Program Files (x86)\Grinding Gear Games\Path of Exile\
  626.     programPath=C:\Program Files (x86)\Grinding Gear Games\Path of Exile\
  627.     ; Path to the POE .exe file to launch, default: PathOfExile_x64.exe
  628.     programFile=PathOfExile_x64.exe
  629.     ; Window Class to monitor, use winspy or some tool to figure this out for other games
  630.     windowClass=POEWindowClass
  631.     */
  632.    
  633.     ; Section Paths
  634.     IniWrite, %programPath%, %INI_FILE%, Paths, programPath
  635.     IniWrite, %programFile%, %INI_FILE%, Paths, programFile
  636.     IniWrite, %windowTitle%, %INI_FILE%, Paths, windowTitle
  637.     IniWrite, %windowClass%, %INI_FILE%, Paths, windowClass
  638.  
  639.     Return
  640. }
  641.  
  642. GetProcessCount(hWnd) {
  643.     WinGet, Result, List , %hWnd%
  644.     Return Result
  645. }
  646.  
  647. GetQuickLinksArray(ArrayName,Dir,Ext="*.exe,*.lnk,*.url") {
  648.     ClearArray(ArrayName)
  649.     Loop, Parse, Ext, % ","
  650.     {
  651.         Loop Files, %Dir%\%A_LoopField% ; Top Level do not Recurse into subfolders.
  652.         {
  653.             ;ArrayName.Insert(A_LoopFileName)
  654.             ArrayName.InsertAt(ArrayName.Length() + 1,A_LoopFileName)
  655.         }
  656.     }
  657.     Return ArrayName.Count()
  658. }
  659.  
  660.  
  661. ClearArray(ArrayName) ;needs explicit "" for "ArrayName"
  662. {
  663.     global
  664.     While %ArrayName%0
  665.     {
  666.         local ArrayNumber := %ArrayName%0 ; save the current number in this var
  667.         %ArrayName%%ArrayNumber% := "" ; clear the variable (will not release the memory)
  668.         VarSetCapacity(%ArrayName%%ArrayNumber%, 0) ; release (most of) the memory that the var is using
  669.         %ArrayName%0-- ; decrement the counter
  670.     }
  671.     Return
  672. }
  673.  
  674. ; TweakWindow() Settings
  675. ; Your resolution minus decorations like start bars if you wish to leave those on-screen.
  676. ; The default values are for around 1080p windowless fullscreen minus a little to allow the taskbar to show below the window
  677. ; More information can be found in this video by TriPolar Bear
  678. ; https://www.youtube.com/watch?v=p1BLjmfC6e0
  679. ; Need to find out who the author of the TweakWindow code was for crediting
  680. ; Based on the script talked about in this video by TriPolarBear
  681. ; https://www.youtube.com/watch?v=p1BLjmfC6e0
  682. TweakWindow(hWnd,tweakLimit=0)
  683. {
  684.     ; Window width and  height Settings edit carefully
  685.     w = 1920
  686.     h = 1030
  687.     w_wasted = 6 ; width used by resize bars
  688.     h_wasted = 29 ; width used by caption frame and resize bars
  689.    
  690.     ; Exclude the desktop
  691.     ; Note: Also excludes "My Computer" browsing windows.
  692.     ; Better detection might be needed to differentiate the parent explorer "ahk_id" from child windows.
  693.     ; Also seems to disregard accidental Metro interface clicks (Win 8+)
  694.     ;MsgBox, hWnd: %hWnd%
  695.     if WinExist(hWnd) {
  696.         BlockInput On      
  697.             WinActivate, %hWnd%
  698.             WinWaitActive, %hWnd%,,3
  699.             if (ErrorLevel != 0)
  700.             {
  701.                 MsgBox, WinWait timed out.
  702.                 Return
  703.             }
  704.         BlockInput On      
  705.         WinGet Style, Style, %hWnd%
  706.         ; 0xC40000 = WS_BORDER (0x800000) + WS_DLGFRAME (0x400000) + WS_SIZEBOX aka WS_THICKFRAME (0x040000)
  707.         if(Style & 0xC00000) { ; if has WS_CAPTION. Ignore sizebox value.
  708.           WinGetPos, X, Y, Width, Height, %hWnd%
  709.           WinSet, Style, -0xC40000, %hWnd% ; removes attributes, including sizebox...doesn't do a strict subtraction
  710.           WinMove,%hWnd%,,0,0,w,h    
  711.           ;MsgBox, One
  712.         } else {
  713.             if(tweakLimit = 0) 
  714.             {
  715.             WinSet, Style, +0xC40000, %hWnd%
  716.             ; Note: will set WS_SIZEBOX even if not previously present
  717.             if(Width > w - w_wasted) {
  718.                 Width := %w%-%w_wasted%
  719.             }
  720.             if(Height > h - h_wasted) {
  721.                 Height := %h%-%h_wasted%
  722.             }
  723.             WinMove,%hWnd%,,%X%,%Y%,%Width%,%Height%      
  724.                     ;MsgBox, Two               
  725.             }
  726.         }
  727.         WinSet, Redraw,,%hWnd%
  728.         BlockInput Off
  729.     }
  730.     Return  
  731. }
Add Comment
Please, Sign In to add comment