Vc添加快捷键

内容整理自网络,记录备忘。

快捷键的作用范围为当前程序,热键的作用范围为系统。

1、添加快捷键 

// 定义变量

HACCEL m_hAccel; // handle to accelerator table

// 初始化快捷键

m_hAccel = LoadAccelerators(AfxGetInstanceHandle(), MAKEINTRESOURCE(IDR_ACCELERATOR1)); // 在资源中添加快捷键资源

if (m_hAccel == NULL)

{

    MessageBox(L"load accelerator fail");

    return FALSE;

}

// 在PreTranslateMessage中添加代码

BOOL CMyDlg::PreTranslateMessage(MSG* pMsg)

{

    if (m_hAccel)

    {

        if (::TranslateAccelerator(m_hWnd, m_hAccel, pMsg))

        {

            return(TRUE);

        }

    }

}

// 释放快捷键 Destroys an accelerator table.

If (m_hAccel)

    DestroyAcceleratorTable(m_hAccel);

 2、添加热键

可参考:http://blog.csdn.net/hityct1/article/details/3853666
 

原文地址:https://www.cnblogs.com/ant-wjf/p/3214375.html