代码之家  ›  专栏  ›  技术社区  ›  Ooker

如何通过关闭窗口最小化窗口?

  •  0
  • Ooker  · 技术社区  · 7 年前

    我想使一个窗口在任何关闭动作启动时最小化(点击关闭按钮, ALT+F4 )对于自动热键,我想 WinMinimize 需要,但我不知道如何检测关闭事件。如果您知道PowerShell的解决方案,请也分享。


    相关: Is it possible to catch the close button and minimize the window instead?

    2 回复  |  直到 7 年前
        1
  •  1
  •   Relax    7 年前
    #NoEnv
    #SingleInstance Force
    
    ; Add the ahk_class of the windows you want  minimize by clicking on the close button in this array:
    Classes := "Notepad,CabinetWClass,IEFrame" ; ...
    Loop, parse, Classes, `,
        GroupAdd, GroupName, ahk_class %A_LoopField%
    
    SetTimer CheckMouse, -300
    return
    
    CheckMouse:
        CoordMode, Mouse, Screen
        MouseGetPos, mX, mY, WindowUnderMouse
        WinGetPos, wX, wY, wW, wH, ahk_id %WindowUnderMouse%
            CloseButton := (mY > wY and mY < wY+50 and (mX > wX + (wW-50) and mX < wX+wW))
        SetTimer CheckMouse, -300
    return
    
    #If (CloseButton)
    
        ~LButton::
            MouseGetPos,,, WindowUnderMouse
            WinGetClass, Class, ahk_id %WindowUnderMouse%
            If Class in %Classes%
            {
                WinGet, id, ID, ahk_id %WindowUnderMouse%
                DISABLE_CloseButton(id)
                WinMinimize, ahk_id %WindowUnderMouse%
            }
        return
    
    
    #If WinActive("ahk_group GroupName")
    
        !F4:: WinMinimize, A
    
    #If ; turn off context sensitivity
    
    
    DISABLE_CloseButton(id){ ;By RealityRipple at http://www.xtremevbtalk.com/archive/index.php/t-258725.html   
      menu:=DllCall("user32\GetSystemMenu","UInt",id,"UInt",0)
      DllCall("user32\DeleteMenu","UInt",menu,"UInt",0xF060,"UInt",0x0)
      WinGetPos,x,y,w,h,ahk_id %id%
      WinMove,ahk_id %id%,,%x%,%y%,%w%,% h-1
      WinMove,ahk_id %id%,,%x%,%y%,%w%,% h+1
    }
    
    ENABLE_CloseButton(id){ ;By Mosaic1 at http://www.xtremevbtalk.com/archive/index.php/t-258725.html  
      menu:=DllCall("user32\GetSystemMenu","UInt",id,"UInt",1)
      DllCall("user32\DrawMenuBar","UInt",id)
    }
    

    https://autohotkey.com/docs/commands/_If.htm

        2
  •  1
  •   Relax    7 年前

    此ahk脚本禁用记事本中的“关闭”按钮,并通过单击此按钮最小化记事本:

    #NoEnv
    #SingleInstance Force
    
    SetTimer CheckMouse, -300
    return
    
    CheckMouse:
        CoordMode, Mouse, Screen
        WinGet, id, ID, ahk_class Notepad
            DISABLE_CloseButton(id)
        MouseGetPos, mX, mY, WindowUnderMouse
        WinGetPos, wX, wY, wW, wH, ahk_id %WindowUnderMouse%
            CloseButton := (mY > wY and mY < wY+50 and (mX > wX + (wW-50) and mX < wX+wW))
        SetTimer CheckMouse, -300
    return
    
    #If (CloseButton)
    
        ~LButton Up::
            MouseGetPos,,, WindowUnderMouse
            WinGetClass, Class, ahk_id %WindowUnderMouse%
            If (Class="Notepad")
                WinMinimize, ahk_id %WindowUnderMouse%
        return
    
    #If WinActive("ahk_class Notepad")
    
        !F4:: WinMinimize, A
    
    #If
    
    
    DISABLE_CloseButton(id){ ;By RealityRipple at http://www.xtremevbtalk.com/archive/index.php/t-258725.html   
      menu:=DllCall("user32\GetSystemMenu","UInt",id,"UInt",0)
      DllCall("user32\DeleteMenu","UInt",menu,"UInt",0xF060,"UInt",0x0)
      WinGetPos,x,y,w,h,ahk_id %id%
      WinMove,ahk_id %id%,,%x%,%y%,%w%,% h-1
      WinMove,ahk_id %id%,,%x%,%y%,%w%,% h+1
    }
    
    ENABLE_CloseButton(id){ ;By Mosaic1 at http://www.xtremevbtalk.com/archive/index.php/t-258725.html  
      menu:=DllCall("user32\GetSystemMenu","UInt",id,"UInt",1)
      DllCall("user32\DrawMenuBar","UInt",id)
    }
    
    推荐文章