Ctrl+X、Ctrl+C 和 Ctrl+V 的 Windows 常量

发布于 2024-10-09 08:56:14 字数 435 浏览 0 评论 0原文

我写了一些旧的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

翻了热茶 2024-10-16 08:56:14

上面有一些从 nChar 中减去偏移量的代码吗?

这些值是字母在字母表中的位置,但我不认为字符代码通常是这样工作的。 (自从我使用这些以来已经很长时间了,所以也许我只是记错了。)

无论如何,您拥有的代码片段实际上是这样的(至少在使用 ASCII 字符排序(即字母顺序)的体系结构上):

// Check for clipboard commands
switch (nChar)
{
    case ('X' - 'A' + 1): // Ctrl+X - Cut
        OnEditCut();
        break;
    case ('C' - 'A' + 1): // Ctrl+C - Copy
        OnEditCopy();
        break;
    case ('V' - 'A' + 1): // Ctrl+V - Paste
        OnEditPaste();
        break;
}

正如我在其他评论中提到的,我希望还有一些其他代码检查 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):

// Check for clipboard commands
switch (nChar)
{
    case ('X' - 'A' + 1): // Ctrl+X - Cut
        OnEditCut();
        break;
    case ('C' - 'A' + 1): // Ctrl+C - Copy
        OnEditCopy();
        break;
    case ('V' - 'A' + 1): // Ctrl+V - Paste
        OnEditPaste();
        break;
}

As mentioned in my other comment, I'd expect there to be some other code checking for Ctrl being held down.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文