Ctrl+X、Ctrl+C 和 Ctrl+V 的 Windows 常量
我写了一些旧的 MFC 代码,我正在“刷新”一下。我在窗口类的 OnChar() 处理程序中有以下代码。
我真的不喜欢使用像 0x18 这样的常量。我想让代码更具可读性。我知道我可以声明自己的值,但是没有用于这些值的 Windows 宏吗?我在网上找不到任何关于此的信息。
// Check for clipboard commands
switch (nChar)
{
case 0x18: // Ctrl+X - Cut
OnEditCut();
break;
case 0x03: // Ctrl+C - Copy
OnEditCopy();
break;
case 0x16: // Ctrl+V - Paste
OnEditPaste();
break;
}
I've got some older MFC code I wrote that I'm "freshening up" a bit. I have the following code in a window class' OnChar() handler.
I really don't like using constants like 0x18. I'd like to make the code more readable. I know I can declare my own, but are there no Windows macros for these values? I couldn't find anything about this on the web.
// Check for clipboard commands
switch (nChar)
{
case 0x18: // Ctrl+X - Cut
OnEditCut();
break;
case 0x03: // Ctrl+C - Copy
OnEditCopy();
break;
case 0x16: // Ctrl+V - Paste
OnEditPaste();
break;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
上面有一些从 nChar 中减去偏移量的代码吗?
这些值是字母在字母表中的位置,但我不认为字符代码通常是这样工作的。 (自从我使用这些以来已经很长时间了,所以也许我只是记错了。)
无论如何,您拥有的代码片段实际上是这样的(至少在使用 ASCII 字符排序(即字母顺序)的体系结构上):
正如我在其他评论中提到的,我希望还有一些其他代码检查 Ctrl 是否被按下。
Do you have some code above there which is subtracting an offset from nChar?
Those values are the letters' places in the alphabet, but I don't think character codes normally work like that. (It has been a long time since I used any of this so maybe I'm just mis-remembering.)
Anyway, the code fragment you have is effectively this (at least on architectures that use the ASCII character ordering, i.e. alphabetic):
As mentioned in my other comment, I'd expect there to be some other code checking for Ctrl being held down.