Advertisement
Guest User

Untitled

a guest
Jul 18th, 2020
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.47 KB | None | 0 0
  1. /*
  2. タスクトレイアイコン操作 by流行らせるページ管理人
  3.  
  4. Tray_GetCount()
  5. トレイアイコンの数を取得する
  6. 返り値
  7. トレイアイコンの数
  8.  
  9. Tray_HideButton(hwnd,uid,hide=1)
  10. トレイアイコンを非表示にする
  11. 引数
  12. hwnd
  13. Tray_GetInfoで取得されるhwndを指定
  14. uid
  15. Tray_GetInfoで取得されるuidを指定
  16. hide
  17. 0にすると再表示、1にすると非表示
  18.  
  19. Tray_MoveIcon(from,to)
  20. トレイアイコンの順番を入れ替える
  21. 引数
  22. from
  23. アイコンの位置を指定する。タスクトレイの一番左のアイコンが1
  24. to
  25. 移動先の位置を指定する
  26.  
  27. Tray_GetText(idx)
  28. トレイアイコンのツールチップテキストを取得する
  29. 引数
  30. idx
  31. アイコンの番号を指定する。タスクトレイの一番左のアイコンが1
  32. 返り値
  33. ツールチップテキスト
  34.  
  35. Tray_GetInfo(idx,ByRef hwnd,ByRef uid,ByRef msg)
  36. トレイアイコンの情報を取得する
  37. 引数
  38. idx
  39. アイコンの番号を指定する。タスクトレイの一番左のアイコンが1
  40. ByRef hwnd
  41. トレイアイコンに関連づけられたウィンドウのハンドルを格納する変数を指定する
  42. ByRef uid
  43. ウィンドウがアイコンを見分けるための固有IDを格納する変数を指定する
  44. ByRef msg
  45. トレイを操作したときにウィンドウに送るメッセージ番号を格納する変数を指定する
  46. ByRef hicon
  47. アイコンハンドルを格納する変数を指定する
  48. 取得した情報を元に、アプリケーションにトレイアイコンを操作したかのように振る舞わせるには、
  49. 以下のようにメッセージを送信する
  50. PostMessage,%msg%,%uid%,%act%,,ahk_id %hwnd%
  51.  
  52. %act%には、以下のどれかを指定する
  53. 0x200:カーソルが通過した
  54. 0x201:左ボタンを押した
  55. 0x202:左ボタンを放した
  56. 0x203:左ダブルクリック
  57. 0x204:右ボタンを押した
  58. 0x205:右ボタンを放した
  59. 0x206:右ダブルクリック
  60. 0x207:中ボタンを押した
  61. 0x208:中ボタンを放した
  62. 0x209:中ダブルクリック
  63.  
  64. ○使用上の注意
  65. トレイアイコンに関連づけられたhwndのウィンドウは、多くの場合非表示になっているので、
  66. 「DetectHiddenWindows,On」で非表示ウィンドウを操作できるようにしておく必要がある
  67.  
  68. ○使用例
  69. ;既に起動しているAutoHotkeyのトレイアイコンを(全て)ダブルクリックする
  70. #NoTrayIcon
  71. name=AutoHotkey.exe
  72. action=0x203
  73.  
  74. cnt:=Tray_GetCount()
  75. DetectHiddenWindows,On
  76. Loop,%cnt%{
  77. Tray_GetInfo(A_Index,hwnd,uid,msg)
  78. WinGet,pn,ProcessName,ahk_id %hwnd%
  79. if(pn=name){
  80. PostMessage,%msg%,%uid%,%action%,,ahk_id %hwnd%
  81. }
  82. }
  83. DetectHiddenWindows,Off
  84. */
  85.  
  86. Tray_GetCount(){
  87. SendMessage,0x418,0,0,ToolbarWindow321,ahk_class Shell_TrayWnd
  88. return ErrorLevel
  89. }
  90. Tray_GetInfo(idx,ByRef hwnd,ByRef uid,ByRef msg,ByRef hicon){
  91. WinGet,pid,pid,ahk_class Shell_TrayWnd
  92. hp:=DllCall("OpenProcess",UInt,0x001F0FFF,UInt,0,UInt,pid,UInt)
  93. lpTB:=DllCall("VirtualAllocEx",UInt,hp,UInt,0,UInt,20,UInt,0x1000,UInt,0x4,UInt)
  94. SendMessage,0x417,% idx-1,%lpTB%,ToolbarWindow321,ahk_class Shell_TrayWnd
  95.  
  96. DllCall("ReadProcessMemory",UInt,hp,UInt,lpTB+12,UIntP,dwData,UInt,4,UInt,0)
  97. DllCall("ReadProcessMemory",UInt,hp,UInt,dwData ,UIntP,hwnd,UInt,4,UInt,0)
  98. DllCall("ReadProcessMemory",UInt,hp,UInt,dwData+4,UIntP,uid ,UInt,4,UInt,0)
  99. DllCall("ReadProcessMemory",UInt,hp,UInt,dwData+8,UIntP,msg ,UInt,4,UInt,0)
  100. DllCall("ReadProcessMemory",UInt,hp,UInt,dwData+20,UIntP,hicon ,UInt,4,UInt,0)
  101.  
  102. DllCall("VirtualFreeEx", UInt,lpTB, UInt,0, UInt,0x8000)
  103. DllCall("psapi\CloseProcess",UInt,hp)
  104. }
  105. Tray_GetText(idx){
  106. WinGet,pid,pid,ahk_class Shell_TrayWnd
  107. hp:=DllCall("OpenProcess",UInt,0x001F0FFF,UInt,0,UInt,pid,UInt)
  108. lpStr:=DllCall("VirtualAllocEx",UInt,hp,UInt,0,UInt,512,UInt,0x1000,UInt,0x4,UInt)
  109.  
  110. SendMessage,0x417,% idx-1,%lpStr%,ToolbarWindow321,ahk_class Shell_TrayWnd
  111.  
  112. DllCall("ReadProcessMemory",UInt,hp,UInt,lpStr+4,UIntP,idButton,UInt,4,UInt,0)
  113.  
  114. SendMessage,0x42D,%idButton%,%lpStr%,ToolbarWindow321,ahk_class Shell_TrayWnd
  115. length=%ErrorLevel%
  116. VarSetCapacity(res,length)
  117. DllCall("ReadProcessMemory",UInt,hp,UInt,lpStr,Str,res,UInt,length+1,UInt,0)
  118.  
  119. DllCall("VirtualFreeEx", UInt,lpStr, UInt,0, UInt,0x8000)
  120. DllCall("psapi\CloseProcess",UInt,hp)
  121. return res
  122. }
  123. SAlloc(size){
  124. return DllCall("GlobalAlloc",UInt,0x40,UInt,size,UInt)
  125. }
  126. SFree(pStruct){
  127. DllCall("GlobalFree",UInt,pStruct,UInt)
  128. }
  129. SSetInt(pStruct,offset,val){
  130. DllCall("RtlMoveMemory", UInt,pStruct+offset, UIntP,val, Int,4)
  131. }
  132. Tray_HideButton(hwnd,uid,hide=1){
  133. pnid:=SAlloc(504)
  134. SSetInt(pnid,0,504)
  135. SSetInt(pnid,4,hwnd)
  136. SSetInt(pnid,8,uid)
  137. SSetInt(pnid,12,0x8)
  138. SSetInt(pnid,152,hide=1)
  139. SSetInt(pnid,156,0x1)
  140. DllCall("Shell32.dll\Shell_NotifyIcon",UInt,1,UInt,pnid,UInt)
  141. SFree(pnid)
  142. }
  143. Tray_MoveButton(from,to){
  144. PostMessage,0x452,% from-1,% to-1,ToolbarWindow321,ahk_class Shell_TrayWnd
  145. }
  146.  
  147.  
  148.  
  149.  
  150. #NoTrayIcon
  151. name=AutoHotkey.exe
  152. action=0x203
  153.  
  154. cnt:=Tray_GetCount()
  155. DetectHiddenWindows,On
  156. Loop,%cnt%{
  157. Tray_GetInfo(A_Index,hwnd,uid,msg,hicon)
  158. WinGet,pn,ProcessName,ahk_id %hwnd%
  159. if(pn=name){
  160. PostMessage,%msg%,%uid%,%action%,,ahk_id %hwnd%
  161. }
  162. }
  163. DetectHiddenWindows,Off
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement