Win10仿QQ右键菜单

测试环境为:Win10 x64,依赖系统自带窗口阴影开启,在Win7下会走样。

Win10仿QQ右键菜单

; 测试环境为:Win10 x64,依赖系统自带窗口阴影开启,在Win7下会走样。
#SingleInstance Force
SetBatchLines -1

新建类菜单 := new Win10RMenu(164, 214)

新建类菜单.Text("复制(&C)", "按钮标签跳转")
; 新建类菜单.Picture("imageres.dll", 331, "w16 h16")  ; 第3个参数可以输入更多Gui, Picture的参数

新建类菜单.Text("转发", "按钮标签跳转")
新建类菜单.Line()

新建类菜单.Text("翻译", "按钮标签跳转")

新建类菜单.Text("回复", "按钮标签跳转")
新建类菜单.Picture("imageres.dll", 326)

新建类菜单.Text("全部选择(&A)", "按钮标签跳转")

新建类菜单.Text("多选", "按钮标签跳转")
新建类菜单.Picture("imageres.dll", 330)
新建类菜单.Line()

新建类菜单.Text("添加到我的收藏", "按钮标签跳转")
新建类菜单.Picture("imageres.dll", 333)
Return

RButton::新建类菜单.Show()

; 清空类变量即销毁右键菜单
F1::新建类菜单 := ""


按钮标签跳转:
ToolTip % Trim(A_GuiControl)
Return

class Win10RMenu
{
    __New(WinMenuW:="", WinMenuH:="") {
        Gui MenuWindowGuiLabel: +HwndMenuHwnd -Caption +AlwaysOnTop +Owner
        Gui MenuWindowGuiLabel: Margin, 0, 0
        Gui MenuWindowGuiLabel: Color, FFFFFF
        Gui MenuWindowGuiLabel: Font, s10 c212121 Q5, Microsoft YaHei UI
        this.MenuHwnd := MenuHwnd
        , this.WinMenuW := WinMenuW
        , this.WinMenuH := WinMenuH
        , this.LButtonHK := ObjBindMethod(this , "HideGui")
        , this.MonitorMenu := ObjBindMethod(this, "WM_MOUSEMOVE")
        , this.styles := (SS_CENTERIMAGE := 0x200) | (SS_NOTIFY := 0x100)
    }

    __Delete() {
		Gui MenuWindowGuiLabel: Destroy
    }

    Show() {
        CoordMode Mouse
        MouseGetPos, RButtonX, RButtonY
        Gui MenuWindowGuiLabel: Show, % "NA x" RButtonX " y" RButtonY " w" this.WinMenuW " h" this.WinMenuH
        WinSet, Region, % "w" this.WinMenuW*A_ScreenDPI//96 " h" this.WinMenuH*A_ScreenDPI//96 " 0-0 r4-4", % "ahk_id " this.MenuHwnd
        Loop % this.LineHwnd.Length()
            WinSet, Transparent, 50, % "ahk_id " this.LineHwnd[A_Index]
        WinSet, Transparent, 240, % "ahk_id " this.MenuHwnd
        this.FrameShadow(this.MenuHwnd)
        , OnMessage(0x200, this.MonitorMenu)
        , HK := this.LButtonHK
        Hotkey, IfWinNotActive, ahk_pid 12345678
        Hotkey, ~LButton, % HK, On
    }

    Line() {
        Static Total := 0
        Gui MenuWindowGuiLabel: Add, Text, % "xs h1 0x10 HwndLineHwnd" ++Total " w" this.WinMenuW+50 " " this.styles
        this.LineHwnd[Total] := LineHwnd%Total%
    }

    Text(Name, Label, Params:="") {
        Static Buttons := 0
        (this.ButtonHwnd.Length()>this.IconHwnd.Length() && this.Picture(""))

        Gui MenuWindowGuiLabel: Add, Text, % "xs Section h30 BackgroundTrans g" Label " Hwnd" (ButtonHwndVar := "ButtonHwnd" ++Buttons) " w" this.WinMenuW " " this.styles " " Params, % "          " . Name

        this.ButtonHwnd[Buttons] := %ButtonHwndVar%
    }

    Picture(IconFile, IconNumber:="", Params:="") {
        Static Icons := 0

        Gui MenuWindowGuiLabel: Add, Picture, % "xs+12 ys+5 w20 h20 BackgroundTrans " this.styles " Hwnd" (IconHwndVar := "IconHwnd" ++Icons) (IconNumber="" ? "" : " Icon" IconNumber) " " Params, %IconFile%

        this.IconHwnd[Icons] := %IconHwndVar%
    }

    HideGui(s:="") {
        if !s {   ; Asynchronous delayed execution of 50 milliseconds
            WinSet, Region, % "w" this.WinMenuW*A_ScreenDPI//96 " h" this.WinMenuH*A_ScreenDPI//96 " 0-0 r4-4", % "ahk_id " this.MenuHwnd
            s := ObjBindMethod(this, "HideGui", "Asynchronous")
            SetTimer % s, -50
            Return
        }
        OnMessage(0x200, this.MonitorMenu, 0)
        , HK := this.LButtonHK
        Hotkey, ~LButton, % HK , Off
        Gui MenuWindowGuiLabel: Cancel
    }

    WM_MOUSEMOVE(wParam, lParam, Msg, Hwnd) {
        Static hover
        MouseGetPos, , , WinHwnd, hControl, 2
        if (WinHwnd = this.MenuHwnd)
            if (wParam = "timer") {
                if (hControl != Msg)
                    if (hControl != Hwnd) {
                        SetTimer,, Delete
                        hover := false
                        , this.Set(Hwnd)
                        GuiControl, MoveDraw, %Hwnd%
                    }
            } else {
                if !hover {
                    hover := true
                    Loop % this.ButtonHwnd.Length()
                        if (Hwnd = this.ButtonHwnd[A_Index]) {
                            this.Set(this.IconHwnd[A_Index])
                            , IconHwndArg := this.IconHwnd[A_Index]
                            Break
                        }
                    this.Set(Hwnd, 0xF1F1F1)
                    , timer := ObjBindMethod(this, "WM_MOUSEMOVE", "timer", "", IconHwndArg, Hwnd)
                    SetTimer, % timer, 15
                }
            }
    }

    ; https://www.autohotkey.com/boards/viewtopic.php?f=76&t=101730#p452171
    Set(hStatic, b_color := "", f_color := "") {
        ( !this.arr && (this.arr := []) && this.msg := ObjBindMethod(this, "WM_CTLCOLORSTATIC") )
        if (b_color = "" && f_color = "")
            this.arr.Delete(hStatic), ( !this.arr.Count() && init := false )
         else
            ( !this.arr.Count() && init := true )
            , b_color := b_color >> 16 | b_color & 0xFF00 | (b_color & 0xFF) << 16
            , f_color := f_color >> 16 | f_color & 0xFF00 | (f_color & 0xFF) << 16
            , this.arr[hStatic] := {b: b_color, f: f_color}

        ( init != "" && OnMessage(WM_CTLCOLORSTATIC := 0x138, this.msg, init) )
        , DllCall("InvalidateRect", "Ptr", hStatic, "Ptr", 0, "Int", true)
    }

    WM_CTLCOLORSTATIC(hDC, hStatic) {
        static TRANSPARENT := 1, NULL_BRUSH := 5, DC_BRUSH := 18
        if !clr := this.arr[hStatic]
            Return
        ( clr.f != "" && DllCall("SetTextColor", "Ptr", hDC, "UInt", clr.f) )
        if (clr.b = "")
            DllCall("SetBkMode", "Ptr", hDC, "UInt", TRANSPARENT)
         else
            DllCall("SetBkColor", "Ptr", hDC, "UInt", clr.b)
            , DllCall("SetDCBrushColor", "Ptr", hDC, "UInt", clr.b)

        Return DllCall("GetStockObject", "UInt", clr.b = "" ? NULL_BRUSH : DC_BRUSH, "Ptr")
    }

    ; https://www.autohotkey.com/boards/viewtopic.php?f=6&t=29117
    FrameShadow(HGui) {
        DllCall("dwmapi\DwmIsCompositionEnabled","IntP",_ISENABLED) ; Get if DWM Manager is Enabled
        if !_ISENABLED ; if DWM is not enabled, Make Basic Shadow
            DllCall("SetClassLong","UInt",HGui,"Int",-26,"Int",DllCall("GetClassLong","UInt",HGui,"Int",-26)|0x20000)
        else
            VarSetCapacity(_MARGINS,16)
            , NumPut(0,&_MARGINS,0,"UInt")
            , NumPut(0,&_MARGINS,4,"UInt")
            , NumPut(1,&_MARGINS,8,"UInt")
            , NumPut(0,&_MARGINS,12,"UInt")
            , DllCall("dwmapi\DwmSetWindowAttribute", "Ptr", HGui, "UInt", 2, "Int*", 2, "UInt", 4)
            , DllCall("dwmapi\DwmExtendFrameIntoClientArea", "Ptr", HGui, "Ptr", &_MARGINS)
    }
}

给TA捐赠
共{{data.count}}人
人已捐赠
其他教程

AHK调用opencv(十九)图像金字塔 – ahk_v2_beta3

2022-4-3 14:13:28

其他教程

AHK调用opencv(二十)opencv中的轮廓 – ahk_v2_beta3

2022-4-5 17:15:43

4 条回复 A文章作者 M管理员
  1. AHK中文社区

    感谢分享!

  2. jfdfaf

    感谢分享

  3. Tmz

    感谢分享

    • dbgba

      有bug的,懒得修了。还是别用了吧

个人中心
购物车
优惠劵
有新私信 私信列表
搜索