Post by tmplinshi » 12 Oct 2018, 03:26
方法1: 使用 acc.ahk
Code: Select all
MsgBox % ss_isPacMode()
ss_isPacMode() {
TrayIcon_Button("Shadowsocks.exe", "R") ; 点击托盘图标右键
WinWait, ahk_class #32768 ahk_exe Shadowsocks.exe,, 2
if ErrorLevel
throw "没有找到菜单窗口"
oAcc := Acc_ObjectFromWindow( WinExist() )
WinClose
for i, child in Acc_Children(oAcc)
{
if ( child.accName(0) ~= "^(系统代理模式|系統代理模式|Mode)$" )
return !!(child.accChild(1).accState(1) & 0x10) ; 0x10=STATE_SYSTEM_CHECKED
}
}
获取菜单项及勾选状态:
Code: Select all
SetBatchLines -1
TrayIcon_Button("Shadowsocks.exe", "R") ; 点击托盘图标右键
WinWait, ahk_class #32768 ahk_exe Shadowsocks.exe,, 2
oAcc := Acc_ObjectFromWindow( WinExist() )
for i, child in Acc_Children(oAcc)
{
if ( child.accName(0) = "系统代理模式" ) {
Loop, % child.accChild(1).accChildCount
{
itemName := child.accChild(1).accName(A_Index)
itemState := child.accChild(1).accState(A_Index)
sChecked := (itemState & 0x10) ? " √" : "" ; 0x10=STATE_SYSTEM_CHECKED
MenuList .= itemName sChecked "`n"
}
WinClose ; 关闭菜单
MsgBox, % MenuList
ExitApp
}
}
方法2:
Code: Select all
SetBatchLines -1
TrayIcon_Button("Shadowsocks.exe", "R") ; 点击托盘图标右键
WinWait, ahk_class #32768 ahk_exe Shadowsocks.exe,, 2
SendMessage, 0x1E1, 0, 0 ; MN_GETHMENU
MenuGetAll_sub(ErrorLevel, "", sContents)
MsgBox, % sContents
ExitApp
; https://autohotkey.com/boards/viewtopic.php?f=6&t=8085
MenuGetAll_sub(menu, prefix, ByRef cmds)
{
Loop % DllCall("GetMenuItemCount", "ptr", menu)
{
VarSetCapacity(itemString, 2000)
if !DllCall("GetMenuString", "ptr", menu, "int", A_Index-1, "str", itemString, "int", 1000, "uint", 0x400)
continue
itemString := StrReplace(itemString, "&")
itemID := DllCall("GetMenuItemID", "ptr", menu, "int", A_Index-1)
if (itemID = -1)
if subMenu := DllCall("GetSubMenu", "ptr", menu, "int", A_Index-1, "ptr")
{
MenuGetAll_sub(subMenu, prefix itemString " > ", cmds)
continue
}
sChecked := MI_isChecked(menu, A_Index-1) ? " √" : ""
cmds .= itemID "`t" prefix RegExReplace(itemString, "`t.*") sChecked "`n"
}
}
MI_isChecked(hMenu, position){
nState := DllCall("GetMenuState", "ptr", hMenu, "uint", position, "uint", 0x00000400)
return !!(nState & 0x00000008) ; MF_CHECKED = 0x00000008
}
TrayIcon:
https://autohotkey.com/boards/viewtopic.php?t=1229
Acc:
https://autohotkey.com/boards/viewtopic.php?t=26201
[b]方法1: 使用 acc.ahk[/b]
[code]MsgBox % ss_isPacMode()
ss_isPacMode() {
TrayIcon_Button("Shadowsocks.exe", "R") ; 点击托盘图标右键
WinWait, ahk_class #32768 ahk_exe Shadowsocks.exe,, 2
if ErrorLevel
throw "没有找到菜单窗口"
oAcc := Acc_ObjectFromWindow( WinExist() )
WinClose
for i, child in Acc_Children(oAcc)
{
if ( child.accName(0) ~= "^(系统代理模式|系統代理模式|Mode)$" )
return !!(child.accChild(1).accState(1) & 0x10) ; 0x10=STATE_SYSTEM_CHECKED
}
}[/code]
获取菜单项及勾选状态:
[code]SetBatchLines -1
TrayIcon_Button("Shadowsocks.exe", "R") ; 点击托盘图标右键
WinWait, ahk_class #32768 ahk_exe Shadowsocks.exe,, 2
oAcc := Acc_ObjectFromWindow( WinExist() )
for i, child in Acc_Children(oAcc)
{
if ( child.accName(0) = "系统代理模式" ) {
Loop, % child.accChild(1).accChildCount
{
itemName := child.accChild(1).accName(A_Index)
itemState := child.accChild(1).accState(A_Index)
sChecked := (itemState & 0x10) ? " √" : "" ; 0x10=STATE_SYSTEM_CHECKED
MenuList .= itemName sChecked "`n"
}
WinClose ; 关闭菜单
MsgBox, % MenuList
ExitApp
}
}[/code]
[b]方法2:[/b]
[code]SetBatchLines -1
TrayIcon_Button("Shadowsocks.exe", "R") ; 点击托盘图标右键
WinWait, ahk_class #32768 ahk_exe Shadowsocks.exe,, 2
SendMessage, 0x1E1, 0, 0 ; MN_GETHMENU
MenuGetAll_sub(ErrorLevel, "", sContents)
MsgBox, % sContents
ExitApp
; https://autohotkey.com/boards/viewtopic.php?f=6&t=8085
MenuGetAll_sub(menu, prefix, ByRef cmds)
{
Loop % DllCall("GetMenuItemCount", "ptr", menu)
{
VarSetCapacity(itemString, 2000)
if !DllCall("GetMenuString", "ptr", menu, "int", A_Index-1, "str", itemString, "int", 1000, "uint", 0x400)
continue
itemString := StrReplace(itemString, "&")
itemID := DllCall("GetMenuItemID", "ptr", menu, "int", A_Index-1)
if (itemID = -1)
if subMenu := DllCall("GetSubMenu", "ptr", menu, "int", A_Index-1, "ptr")
{
MenuGetAll_sub(subMenu, prefix itemString " > ", cmds)
continue
}
sChecked := MI_isChecked(menu, A_Index-1) ? " √" : ""
cmds .= itemID "`t" prefix RegExReplace(itemString, "`t.*") sChecked "`n"
}
}
MI_isChecked(hMenu, position){
nState := DllCall("GetMenuState", "ptr", hMenu, "uint", position, "uint", 0x00000400)
return !!(nState & 0x00000008) ; MF_CHECKED = 0x00000008
}[/code]
TrayIcon: https://autohotkey.com/boards/viewtopic.php?t=1229
Acc: https://autohotkey.com/boards/viewtopic.php?t=26201