PageRenderTime 45ms CodeModel.GetById 27ms RepoModel.GetById 0ms app.codeStats 0ms

/res/ahk/windows.ahk

http://github.com/Skiouros/Macro
AutoHotKey | 70 lines | 60 code | 9 blank | 1 comment | 8 complexity | 02bdd6144012b5fbbdd6c58e08fe882f MD5 | raw file
  1. class Windows extends CGUI
  2. {
  3. __New(mainGui, Owner)
  4. {
  5. this.windowsLV := this.AddControl("ListView", "windowsLV", "w500 h300 NoSortHdr -Multi -LV0x10", "Title |Class |Exe")
  6. this.windowsLV.IndependentSorting := true
  7. this.AddControl("Button", "btnCancel", "x435 w75 h23", "Cancel")
  8. this.Title := "Select Program"
  9. this.gui := mainGui
  10. this.Owner := owner, this.OwnerAutoClose := 1, this.MinimizeBox := 0
  11. }
  12. Load() {
  13. this.AddWindows()
  14. this.Show()
  15. this.windowsLV.Modify()
  16. }
  17. windowsLV_DoubleClick(RowItem) {
  18. class := this.windowsLV.Items[RowItem][2]
  19. ; No item was selected
  20. if (!class)
  21. return
  22. WinGet, exe, ProcessPath, % "ahk_class " . class
  23. this.gui.Profile.edtExe.Text := exe
  24. this.btnCancel_Click()
  25. }
  26. AddWindows() {
  27. windows := GetWindows()
  28. for index, window in windows
  29. {
  30. for key, value in window
  31. %key% := value
  32. this.windowsLV.Items.Add("", title, class, exe)
  33. }
  34. }
  35. btnCancel_Click() {
  36. this.gui.Profile.Enabled := true
  37. this.Hide()
  38. Loop % this.windowsLV.Items.Count
  39. this.windowsLV.Items.Delete(1)
  40. }
  41. PreClose() {
  42. this.gui.Profile.Enabled := true
  43. }
  44. }
  45. GetWindows() {
  46. DetectHiddenWindows, Off
  47. WinGet, id, list,,, Program Manager
  48. Windows := []
  49. Loop % id
  50. {
  51. id := id%A_Index%
  52. WinGetClass, class, ahk_id %id%
  53. WinGet, exe, ProcessName, ahk_id %id%
  54. WinGetTitle, title, ahk_id %id%
  55. if((!title && exe != "Explorer.exe") || InStr(class, "Tooltip") || InStr(class, "SysShadow")) ;Filter some windows
  56. continue
  57. tmpArray := { title: title, class: class, exe: exe}
  58. Windows.Insert(tmpArray)
  59. }
  60. return Windows
  61. }