How to minimize a window by closing it?












0














I want to make a window only be minimized when any act of closing it is initiated (click the close button, Alt+F4). For AutoHotKey I think WinMinimize is needed, but I don't know how to detect a closing event. If you know a solution for PowerShell, please share too.






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










share|improve this question






















  • Why tag this question PowerShell ?
    – Theo
    Nov 21 '18 at 9:30










  • I can accept PowerShell solution too. Is that acceptable?
    – Ooker
    Nov 21 '18 at 12:24
















0














I want to make a window only be minimized when any act of closing it is initiated (click the close button, Alt+F4). For AutoHotKey I think WinMinimize is needed, but I don't know how to detect a closing event. If you know a solution for PowerShell, please share too.






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










share|improve this question






















  • Why tag this question PowerShell ?
    – Theo
    Nov 21 '18 at 9:30










  • I can accept PowerShell solution too. Is that acceptable?
    – Ooker
    Nov 21 '18 at 12:24














0












0








0







I want to make a window only be minimized when any act of closing it is initiated (click the close button, Alt+F4). For AutoHotKey I think WinMinimize is needed, but I don't know how to detect a closing event. If you know a solution for PowerShell, please share too.






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










share|improve this question













I want to make a window only be minimized when any act of closing it is initiated (click the close button, Alt+F4). For AutoHotKey I think WinMinimize is needed, but I don't know how to detect a closing event. If you know a solution for PowerShell, please share too.






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







powershell autohotkey






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 21 '18 at 5:45









OokerOoker

5691527




5691527












  • Why tag this question PowerShell ?
    – Theo
    Nov 21 '18 at 9:30










  • I can accept PowerShell solution too. Is that acceptable?
    – Ooker
    Nov 21 '18 at 12:24


















  • Why tag this question PowerShell ?
    – Theo
    Nov 21 '18 at 9:30










  • I can accept PowerShell solution too. Is that acceptable?
    – Ooker
    Nov 21 '18 at 12:24
















Why tag this question PowerShell ?
– Theo
Nov 21 '18 at 9:30




Why tag this question PowerShell ?
– Theo
Nov 21 '18 at 9:30












I can accept PowerShell solution too. Is that acceptable?
– Ooker
Nov 21 '18 at 12:24




I can accept PowerShell solution too. Is that acceptable?
– Ooker
Nov 21 '18 at 12:24












2 Answers
2






active

oldest

votes


















1














#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("user32GetSystemMenu","UInt",id,"UInt",0)
DllCall("user32DeleteMenu","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("user32GetSystemMenu","UInt",id,"UInt",1)
DllCall("user32DrawMenuBar","UInt",id)
}


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






share|improve this answer





























    1














    This AHK script disables the close button in Notepad and minimizes Notepad by clicking on this button:



    #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("user32GetSystemMenu","UInt",id,"UInt",0)
    DllCall("user32DeleteMenu","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("user32GetSystemMenu","UInt",id,"UInt",1)
    DllCall("user32DrawMenuBar","UInt",id)
    }





    share|improve this answer























    • Perfect, thanks. What if I have a set of programs? Can we declare them at the top of the script?
      – Ooker
      Nov 21 '18 at 12:36












    • Try the next answer.
      – user3419297
      Nov 21 '18 at 13:25










    • umm, why don't you just edit the old answer instead of posting a new one?
      – Ooker
      Nov 21 '18 at 13:34










    • May confuse other users who want a solution for only one app.
      – user3419297
      Nov 21 '18 at 13:44










    • but they can just simply add one app in the Classes?
      – Ooker
      Nov 21 '18 at 16:26











    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53405915%2fhow-to-minimize-a-window-by-closing-it%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    1














    #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("user32GetSystemMenu","UInt",id,"UInt",0)
    DllCall("user32DeleteMenu","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("user32GetSystemMenu","UInt",id,"UInt",1)
    DllCall("user32DrawMenuBar","UInt",id)
    }


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






    share|improve this answer


























      1














      #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("user32GetSystemMenu","UInt",id,"UInt",0)
      DllCall("user32DeleteMenu","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("user32GetSystemMenu","UInt",id,"UInt",1)
      DllCall("user32DrawMenuBar","UInt",id)
      }


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






      share|improve this answer
























        1












        1








        1






        #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("user32GetSystemMenu","UInt",id,"UInt",0)
        DllCall("user32DeleteMenu","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("user32GetSystemMenu","UInt",id,"UInt",1)
        DllCall("user32DrawMenuBar","UInt",id)
        }


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






        share|improve this answer












        #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("user32GetSystemMenu","UInt",id,"UInt",0)
        DllCall("user32DeleteMenu","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("user32GetSystemMenu","UInt",id,"UInt",1)
        DllCall("user32DrawMenuBar","UInt",id)
        }


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







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 21 '18 at 13:25









        user3419297user3419297

        4,4442613




        4,4442613

























            1














            This AHK script disables the close button in Notepad and minimizes Notepad by clicking on this button:



            #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("user32GetSystemMenu","UInt",id,"UInt",0)
            DllCall("user32DeleteMenu","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("user32GetSystemMenu","UInt",id,"UInt",1)
            DllCall("user32DrawMenuBar","UInt",id)
            }





            share|improve this answer























            • Perfect, thanks. What if I have a set of programs? Can we declare them at the top of the script?
              – Ooker
              Nov 21 '18 at 12:36












            • Try the next answer.
              – user3419297
              Nov 21 '18 at 13:25










            • umm, why don't you just edit the old answer instead of posting a new one?
              – Ooker
              Nov 21 '18 at 13:34










            • May confuse other users who want a solution for only one app.
              – user3419297
              Nov 21 '18 at 13:44










            • but they can just simply add one app in the Classes?
              – Ooker
              Nov 21 '18 at 16:26
















            1














            This AHK script disables the close button in Notepad and minimizes Notepad by clicking on this button:



            #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("user32GetSystemMenu","UInt",id,"UInt",0)
            DllCall("user32DeleteMenu","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("user32GetSystemMenu","UInt",id,"UInt",1)
            DllCall("user32DrawMenuBar","UInt",id)
            }





            share|improve this answer























            • Perfect, thanks. What if I have a set of programs? Can we declare them at the top of the script?
              – Ooker
              Nov 21 '18 at 12:36












            • Try the next answer.
              – user3419297
              Nov 21 '18 at 13:25










            • umm, why don't you just edit the old answer instead of posting a new one?
              – Ooker
              Nov 21 '18 at 13:34










            • May confuse other users who want a solution for only one app.
              – user3419297
              Nov 21 '18 at 13:44










            • but they can just simply add one app in the Classes?
              – Ooker
              Nov 21 '18 at 16:26














            1












            1








            1






            This AHK script disables the close button in Notepad and minimizes Notepad by clicking on this button:



            #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("user32GetSystemMenu","UInt",id,"UInt",0)
            DllCall("user32DeleteMenu","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("user32GetSystemMenu","UInt",id,"UInt",1)
            DllCall("user32DrawMenuBar","UInt",id)
            }





            share|improve this answer














            This AHK script disables the close button in Notepad and minimizes Notepad by clicking on this button:



            #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("user32GetSystemMenu","UInt",id,"UInt",0)
            DllCall("user32DeleteMenu","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("user32GetSystemMenu","UInt",id,"UInt",1)
            DllCall("user32DrawMenuBar","UInt",id)
            }






            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited Nov 21 '18 at 12:24

























            answered Nov 21 '18 at 11:56









            user3419297user3419297

            4,4442613




            4,4442613












            • Perfect, thanks. What if I have a set of programs? Can we declare them at the top of the script?
              – Ooker
              Nov 21 '18 at 12:36












            • Try the next answer.
              – user3419297
              Nov 21 '18 at 13:25










            • umm, why don't you just edit the old answer instead of posting a new one?
              – Ooker
              Nov 21 '18 at 13:34










            • May confuse other users who want a solution for only one app.
              – user3419297
              Nov 21 '18 at 13:44










            • but they can just simply add one app in the Classes?
              – Ooker
              Nov 21 '18 at 16:26


















            • Perfect, thanks. What if I have a set of programs? Can we declare them at the top of the script?
              – Ooker
              Nov 21 '18 at 12:36












            • Try the next answer.
              – user3419297
              Nov 21 '18 at 13:25










            • umm, why don't you just edit the old answer instead of posting a new one?
              – Ooker
              Nov 21 '18 at 13:34










            • May confuse other users who want a solution for only one app.
              – user3419297
              Nov 21 '18 at 13:44










            • but they can just simply add one app in the Classes?
              – Ooker
              Nov 21 '18 at 16:26
















            Perfect, thanks. What if I have a set of programs? Can we declare them at the top of the script?
            – Ooker
            Nov 21 '18 at 12:36






            Perfect, thanks. What if I have a set of programs? Can we declare them at the top of the script?
            – Ooker
            Nov 21 '18 at 12:36














            Try the next answer.
            – user3419297
            Nov 21 '18 at 13:25




            Try the next answer.
            – user3419297
            Nov 21 '18 at 13:25












            umm, why don't you just edit the old answer instead of posting a new one?
            – Ooker
            Nov 21 '18 at 13:34




            umm, why don't you just edit the old answer instead of posting a new one?
            – Ooker
            Nov 21 '18 at 13:34












            May confuse other users who want a solution for only one app.
            – user3419297
            Nov 21 '18 at 13:44




            May confuse other users who want a solution for only one app.
            – user3419297
            Nov 21 '18 at 13:44












            but they can just simply add one app in the Classes?
            – Ooker
            Nov 21 '18 at 16:26




            but they can just simply add one app in the Classes?
            – Ooker
            Nov 21 '18 at 16:26


















            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.





            Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


            Please pay close attention to the following guidance:


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53405915%2fhow-to-minimize-a-window-by-closing-it%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Costa Masnaga

            Fotorealismo

            Sidney Franklin