如何为界面上的一个按钮关联“热键”?

huntzhang 2005-01-17 10:39:09
程序界面上有些按钮,想为它加上个热键的关联,比如“F1”,请问如何实现?
谢谢
...全文
100 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
huntzhang 2005-01-17
  • 打赏
  • 举报
回复
BOOL CRefExeDlg::PreTranslateMessage(MSG* pMsg)
{
if(pMsg->message==WM_KEYDOWN)
{
if(VK_F4)
{
OnHideTaskbarIcoBtn();
}
}
m_tooltip.RelayEvent(pMsg);

return CDialog::PreTranslateMessage(pMsg);
}
程序中还有一个edit box,这段代码加入以后,只要在editbox中输入,也就是keydown,就会关联
onhidetaskbaricobtn这个函数,请达人指教,谢谢
huntzhang 2005-01-17
  • 打赏
  • 举报
回复
多谢楼上,如果按键是组合键呢?
菲斯可儿 2005-01-17
  • 打赏
  • 举报
回复
VK_F1
huntzhang 2005-01-17
  • 打赏
  • 举报
回复
谢谢楼上,请问如何判断按键是否是F1?
鲫鱼跃龙门 2005-01-17
  • 打赏
  • 举报
回复
改写PreTranslateMessage函数,

判断MESSGE是否为WM_KEYDOWN,且按键是F1就调用某按钮的响应函数。
鲫鱼跃龙门 2005-01-17
  • 打赏
  • 举报
回复
WM_KEYDOWN 消息参数:(MSDN)

wParam
Specifies the virtual-key code of the nonsystem key.
lParam
Specifies the repeat count, scan code, extended-key flag, context code, previous key-state flag, and transition-state flag, as shown in the following table.
0-15
Specifies the repeat count for the current message. The value is the number of times the keystroke is autorepeated as a result of the user holding down the key. If the keystroke is held long enough, multiple messages are sent. However, the repeat count is not cumulative.
16-23
Specifies the scan code. The value depends on the OEM.
24
Specifies whether the key is an extended key, such as the right-hand ALT and CTRL keys that appear on an enhanced 101- or 102-key keyboard. The value is 1 if it is an extended key; otherwise, it is 0.
25-28
Reserved; do not use.
29
Specifies the context code. The value is always 0 for a WM_KEYDOWN message.
30
Specifies the previous key state. The value is 1 if the key is down before the message is sent, or it is zero if the key is up.
31
Specifies the transition state. The value is always zero for a WM_KEYDOWN message.
huntzhang 2005-01-17
  • 打赏
  • 举报
回复
up

16,550

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC相关问题讨论
社区管理员
  • 基础类社区
  • Creator Browser
  • encoderlee
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……

试试用AI创作助手写篇文章吧