如何获取命令ID的键盘快捷键
How to get keyboard accelerators for a command ID?
MFC功能包似乎神奇地将资源键盘快捷键打印到菜单项的工具提示中。如何找到任何给定命令ID的组合键(如果我只有
HACCEL
句柄?(。
您可以使用CopyAcceleratorTable()
函数来检索给定HACCEL
句柄的加速器列表。
首先,用nullptr
和0
作为第二个和第三个参数调用该函数,以获得列表的大小(即加速器的数量(,然后分配适当大小的ACCEL
结构的缓冲区。
然后,您可以使用指向该缓冲区的指针和之前返回的计数再次调用CopyAcceleratorTable
。
现在,您可以遍历该缓冲区,使用每个结构的三个字段来确定加速器键是什么、它有什么标志以及它代表什么命令。
HACCEL hAcc; // Assuming this is a valid handle ...
int nAcc = CopyAcceleratorTable(hAcc, nullptr, 0); // Get number of accelerators
ACCEL *pAccel = new ACCEL[nAcc]; // Allocate the required buffer
CopyAcceleratorTable(hAcc, pAccel, nAcc); // Now copy to that buffer
for (int a = 0; a < nAcc; ++a) {
DWORD cmd = pAccel[a].cmd; // The command ID
WORD key = pAccel[a].key; // The key code - such as 0x41 for the "A" key
WORD flg = pAccel[a].fVirt; // The 'flags' (things like FCONTROL, FALT, etc)
//...
// Format and display the data, as required
//...
}
delete[] pAccel; // Don't forget to free the data when you're done!
您可以在此页面上看到ACCEL
结构的三个数据字段的值和格式的描述。
相关文章:
- 物理键盘上的触发器按键
- 如何使用C/C++在MacOSX中获得键盘布局
- 从函数角度看ID到文件路径的内部与外部映射
- 通过组合不同的类型来创建唯一的id
- 我不断收到 [错误] ID 返回 1 退出状态错误,但看不到问题所在
- FFMPEG配置文件级别id大小无效
- 方法内部但循环仍得到预期的不合格id错误C++
- 如何获取 GLFW 窗口 ID?
- 视窗键盘输入 c++
- 当简单捕获中的标识符显示为参数的声明符 ID 时,没有编译器诊断
- 显示数组中的学生 ID 和最高分
- C++:"("令牌"之前有预期的非限定 id 指向类中成员函数的指针
- 在PostgreSQL中根据它们的ID选择大量行的最快方法是什么?
- Xcode 9.4.1 中的 Apple Mach-O 链接器 (id) 错误
- 错误:令牌 { '{' 之前应存在非限定 ID
- 将鼠标和键盘输入发送到 unity3d 游戏 (Rust)
- C ++异步键盘输入(标准方式)
- 键盘不起作用 - Arduino Uno - 与变量有关的多个错误
- 断言"id < 0"在Qt ActiveX中失败
- C++部分概念 id:显式模板规范顺序/第一个参数的特殊状态的原因是什么?