2

我用 C++ 尝试过,似乎需要将代码注入另一个进程以禁用其主窗口的关闭按钮。但我很好奇,因为我实际上需要它来用于 .NET 程序,我可以用 C# 将其主窗口的关闭按钮变灰吗?

PS。同样,我正在做的过程不是我的。我可以这样找到它:

Process[] processes = Process.GetProcessesByName("Notepad");
foreach (Process p in processes)
{
    IntPtr pFoundWindow = p.MainWindowHandle;

    //Now how to disable it's close button?
}
4

1 回答 1

6

我想我明白了:

[DllImport("user32.dll")]
static extern IntPtr GetSystemMenu(IntPtr hWnd, bool bRevert);

[DllImport("user32.dll")]
static extern bool DeleteMenu(IntPtr hMenu, uint uPosition, uint uFlags);


const uint SC_CLOSE = 0xF060;
const uint MF_BYCOMMAND = 0x00000000;

Process[] processes = Process.GetProcessesByName("Notepad");
foreach (Process p in processes)
{
    IntPtr pFoundWindow = p.MainWindowHandle;

    IntPtr nSysMenu = GetSystemMenu(pFoundWindow, false);
    if (nSysMenu != IntPtr.Zero)
    {
        if (DeleteMenu(nSysMenu, SC_CLOSE, MF_BYCOMMAND))
        {
            //Done!
        }
    }
}
于 2013-05-30T01:48:05.283 回答