托盘菜单在屏幕中央显示.ahk

; https://www.autohotkey.com/boards/viewtopic.php?f=6&t=81064
#NoEnv
#SingleInstance, Force
CoordMode, Mouse, Screen
MouseMove, A_ScreenWidth/2, A_ScreenHeight/2, 0
ShowMenu( MenuGetHandle("Tray"), False, A_ScreenWidth/2, A_ScreenHeight/2, 0x14 )
Return

; https://www.autohotkey.com/boards/viewtopic.php?f=6&t=81064
; 简介:默认菜单命令没有标志选项来控制菜单的显示。例如。在屏幕的绝对中心显示菜单。
; 我的需求:当我们单击“开始”按钮时,“开始”菜单会很好地停靠在任务栏上。但是,如果我们右键单击 AHK 通知图标,它会部分出现在托盘上方,遮挡其他图标的视图。
; 为了使托盘菜单表现得像“开始”菜单,我需要对齐标志,因此我编写了这个函数。

#NoEnv
#SingleInstance, Force
Menu, Tray, NoStandard
Menu, Tray, Add, Menu, Routine
Menu, Tray, Default, Menu
Menu, Tray, Add
Menu, Tray, Click, 1
Menu, Tray, Standard
Return

F1::
Routine:
  ShowMenu(MenuGetHandle("Tray"), False, TrayMenuParams()*)
Return

ShowMenu(hMenu, MenuLoop:=0, X:=0, Y:=0, Flags:=0) {            ; Ver 0.61 by SKAN on D39F/D39G
Local                                                           ;            @ tiny.cc/showmenu
  If (hMenu="WM_ENTERMENULOOP")
    Return True
  Fn := Func("ShowMenu").Bind("WM_ENTERMENULOOP"), n := MenuLoop=0 ? 0 : OnMessage(0x211,Fn,-1)
  DllCall("SetForegroundWindow","Ptr",A_ScriptHwnd)
  R := DllCall("TrackPopupMenu", "Ptr",hMenu, "Int",Flags, "Int",X, "Int",Y, "Int",0
             , "Ptr",A_ScriptHwnd, "Ptr",0, "UInt"),                     OnMessage(0x211,Fn, 0)
  DllCall("PostMessage", "Ptr",A_ScriptHwnd, "Int",0, "Ptr",0, "Ptr",0)
Return R
}


TrayMenuParams() {      ; Original function is TaskbarEdge() by SKAN @ tiny.cc/taskbaredge
Local    ; This modfied version to be passed as parameter to ShowMenu() @ tiny.cc/showmenu
  VarSetCapacity(var,84,0), v:=&var,   DllCall("GetCursorPos","Ptr",v+76)
  X:=NumGet(v+76,"Int"), Y:=NumGet(v+80,"Int"),  NumPut(40,v+0,"Int64")
  hMonitor := DllCall("MonitorFromPoint", "Int64",NumGet(v+76,"Int64"), "Int",0, "Ptr")
  DllCall("GetMonitorInfo", "Ptr",hMonitor, "Ptr",v)
  DllCall("GetWindowRect", "Ptr",WinExist("ahk_class Shell_SecondaryTrayWnd"), "Ptr",v+68)
  DllCall("SubtractRect", "Ptr",v+52, "Ptr",v+4, "Ptr",v+68)
  DllCall("GetWindowRect", "Ptr",WinExist("ahk_class Shell_TrayWnd"), "Ptr",v+36)
  DllCall("SubtractRect", "Ptr",v+20, "Ptr",v+52, "Ptr",v+36)
  Loop % (8, offset:=0)
    v%A_Index% := NumGet(v+0, offset+=4, "Int")
Return ( v3>v7 ? [v7, Y, 0x18] : v4>v8 ? [X, v8, 0x24]
       : v5>v1 ? [v5, Y, 0x10] : v6>v2 ? [X, v6, 0x04] : [0,0,0] )
}

 

声明:站内资源为整理优化好的代码上传分享与学习研究,如果是开源代码基本都会标明出处,方便大家扩展学习路径。请不要恶意搬运,破坏站长辛苦整理维护的劳动成果。本站为爱好者分享站点,所有内容不作为商业行为。如若本站上传内容侵犯了原著者的合法权益,请联系我们进行删除下架。