[英]Notify icon working fine in windows XP but not in windows server 2003
[英]RegisterHotkey only working in WIndows 7, not in XP, server 2003
我在 Windows 中设置全局快捷键,使用 RegisterHotKey 方法
public static int MOD_CONTROL = 0x2;
public static int WM_HOTKEY = 0x312;
RegisterHotKey(this.Handle, 0, MOD_CONTROL | MOD_NOREPEAT, 96);
// ctrl numpad0
处理这个的代码是:
[DllImport("user32.dll")]
public static extern bool RegisterHotKey(IntPtr hWnd, int id, int fsModifiers, int vlc);
protected override void WndProc(ref Message m)
{
if (m.Msg == WM_HOTKEY)
{
MessageBox.Show("a hotkey is pressed"); //this also only shows in win7
if (m.WParam.ToInt32() == 0) //ctrl numpad0
{
MessageBox.Show("Hotkey ctrl numpad0 pressed");
// works fine in win7
}
}
base.WndProc(ref m);
}
在我的 windows 7 PC 上,这是可行的,但在 XP 或 Windows Server 2003 上却不行。 有什么想法会出错吗?
查看RegisterHotKey的文档,它指出 Vista/XP/2K 不支持 MOD_NOREPEAT 标志。 我怀疑这是你的问题。
您应该检查返回值,它会立即告诉您有问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.