日期:2014-05-17  浏览次数:20991 次

C# 写屏幕保护程序怎么屏蔽ALT 和 F4组合
我写的屏幕保护需要密码才可以退出。。。

.net 4.5的框架。

最近发现一个bug


一直按着ALT键,再按几次F4就可以把我的输入密码对话框和屏保都关闭了。


这个太绝了。。。


我要封杀ALT + F4组合。。。


怎么屏蔽之?谢谢、、、

网上搜的代码都不行。下面就是。

protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
{
    return (keyData & Keys.Alt) != 0;
}




public class TestForm : Form
{
    protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
    {
        return (keyData & Keys.Alt) != 0;
    }
    protected override void OnLoad(EventArgs e)
    {
        base.OnLoad(e);
        TextBox tx = new TextBox();
        this.Controls.Add(tx);
        tx.Text = "你尝试按Alt+F4?";
        tx.SelectionStart = tx.Text.Length;
    }
}



谁有办法啊
C# 屏幕保护 屏蔽ALT?和?F4组合

------解决方案--------------------
我也试过了,是关不掉的,不知道是什么原因,再提供一个建议:
在程序中注册 alt-f4快捷键,这样可以屏蔽系统的alt-f4
要使用以下一些API:
RegisterHotKey, UnRegisterHotKey, GlobalAddAtom,
下面是DELPHI写的,供参考
Cardinal hotkey := GlobalAddAtom('No Alt-F4')-$C000;
boolean hotkeyok := RegisterHotKey(handle, hotkey, MOD_ALT, VK_F4);
if hotkeyok then
    UnRegisterHotKey(handle,hotkey);
------解决方案--------------------
   protected override void WndProc(ref Message m)
        {
            const int WM_SYSCOMMAND = 0x112;
            const int SC_CLOSE = 0xF060;
            if (m.Msg == WM_SYSCOMMAND && m.WParam == (IntPtr)SC_CLOSE && m.LParam == IntPtr.Zero)
                return;
            base.WndProc(ref m);
        }

------解决方案--------------------
 protected override void WndProc(ref Message m)
        {