如何获得用于命令ID的键盘加速器?

问题描述

MFC功能包似乎神奇地将资源键盘加速器快捷方式打印到菜单项的工具提示。 我该如何找到给定命令ID的组合键(如果我只有HACCEL句柄?)。

解决方法

您可以使用CopyAcceleratorTable() function来获取给定HACCEL句柄的加速器列表。

首先,使用nullptr0作为第二个和第三个参数调用该函数以获取列表的大小(即加速器的数量),然后分配{{1}的缓冲区}大小合适的结构。

然后,您可以再次使用指向该缓冲区的指针和先前返回的计数来调用ACCEL

现在,您可以遍历该缓冲区,使用每个结构的三个字段来确定加速键是什么,其具有的标志以及它代表的命令。

CopyAcceleratorTable

您可以在this page上看到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! 结构的三个数据字段的值和格式的描述。

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...