Processing Ajax...

Title

Message

Confirm

Confirm

Confirm

Confirm

Are you sure you want to delete this item?

Confirm

Are you sure you want to delete this item?

Confirm

Are you sure?

User Image
Felix Honda
2 discussion posts
Hello, just wondering if there was a way to disable the windows close button (X) in the upper right corner of a window similar to Actual Window Manager? Trying to find a way to prevent specific programs from accidentally closing. Thanks!
Jul 5, 2018  • #1
Alan Wade's profile on WallpaperFusion.com
There is a terrific free little app that can do this for you called NoClose
Read More/Download Here:
http://www.dcmembers.com/skrommel/download/noclose/
Jul 6, 2018  • #2
PabloMartinez's profile on WallpaperFusion.com
Searching in Google and PInvoke.net i was able to find a simple solution. Create trigger on the desired application (window created, focus, or what else) and use the following script as an action. I hope from the code it is clear that you can both disable and enable the button, just commenting\uncommenting the desired line in the code.

Code

using System;
using System.Drawing;
using System.Runtime.InteropServices;

public static class DisplayFusionFunction
{
    [DllImport("user32.dll")] private static extern IntPtr GetSystemMenu(IntPtr hWnd, bool bRevert);
    [DllImport("user32.dll")] private static extern int EnableMenuItem(IntPtr hMenu, uint uIDEnableItem, uint uEnable);
    
    private const uint Close = 0xF060;
    private const uint Enabled = 0x00000000;
    private const uint Disabled = 0x00000002;

    public static void Run(IntPtr windowHandle)
    {
        EnableMenuItem(GetSystemMenu(windowHandle, false), Close, Disabled);
        // EnableMenuItem(GetSystemMenu(windowHandle, false), Close, Enabled);
    }
}
Jul 7, 2018  • #3
User Image
Felix Honda
2 discussion posts
Quote:
Searching in Google and PInvoke.net i was able to find a simple solution. Create trigger on the desired application (window created, focus, or what else) and use the following script as an action. I hope from the code it is clear that you can both disable and enable the button, just commenting\uncommenting the desired line in the code.

Code

using System;
using System.Drawing;
using System.Runtime.InteropServices;

public static class DisplayFusionFunction
{
    [DllImport("user32.dll")] private static extern IntPtr GetSystemMenu(IntPtr hWnd, bool bRevert);
    [DllImport("user32.dll")] private static extern int EnableMenuItem(IntPtr hMenu, uint uIDEnableItem, uint uEnable);
    
    private const uint Close = 0xF060;
    private const uint Enabled = 0x00000000;
    private const uint Disabled = 0x00000002;

    public static void Run(IntPtr windowHandle)
    {
        EnableMenuItem(GetSystemMenu(windowHandle, false), Close, Disabled);
        // EnableMenuItem(GetSystemMenu(windowHandle, false), Close, Enabled);
    }
}


Brilliant! Script works perfectly! Thanks!
Jul 7, 2018  • #4
PabloMartinez's profile on WallpaperFusion.com
I think it's not always convenient to use triggers. And a little bit changed the script to use it with hot keys. Works as a switch, with a single hotkey.

Code

using System;
using System.Drawing;
using System.Runtime.InteropServices;

public static class DisplayFusionFunction
{
    [DllImport("user32.dll")]
    private static extern IntPtr GetSystemMenu(IntPtr hWnd, bool bRevert);
    [DllImport("user32.dll")]
    private static extern int EnableMenuItem(IntPtr hMenu, uint uIDEnableItem, uint uEnable);
    
    private const uint CloseButton = 0xF060;
    private const uint Enabled = 0x00000000;
    private const uint Disabled = 0x00000002;

    public static void Run(IntPtr windowHandle)
    {
        if(!BFS.ScriptSettings.ReadValueBool("CloseButtonState"))
        {
            EnableMenuItem(GetSystemMenu(windowHandle, false), CloseButton, Enabled);
            BFS.ScriptSettings.WriteValueBool("CloseButtonState", true);
        }
        else
        {
            EnableMenuItem(GetSystemMenu(windowHandle, false), CloseButton, Disabled);
            BFS.ScriptSettings.WriteValueBool("CloseButtonState", false);
        }
    }
}
Jul 9, 2018  • #5
Subscribe to this discussion topic using RSS
Was this helpful?  Login to Vote(1)  Login to Vote(-)