一、添加函數聲明
LRESULT OnHotKey(WPARAM wParam, LPARAM lParam);
ON_MESSAGE(WM_HOTKEY,OnHotKey)函數
二、添加函數實現
LRESULT CMainFrame::OnHotKey(WPARAM wParam, LPARAM lParam)
{
ShowWindow(SW_SHOW);
if (m_settings.IsEQ())
{
CInputScanEQ inputEQ(this);
if (IDOK == inputEQ.DoModal())
{
CFormShow formShow(inputEQ.GetNum(), inputEQ.GetText(), this);
formShow.DoModal();
}
}
else
{
SYSTEMTIME st;
GetSystemTime(&st);
CString preSN;
preSN.Format("%s-%d%d%d-", GetSettings().GetNetId(), st.wYear-2014, st.wMonth, st.wDay);
CInputFormSN inputSN(GetSettings().GetDBSource(), preSN, this);
if (IDOK == inputSN.DoModal())
{
CFormShow formShow(inputSN.GetNum(), inputSN.GetText(), this);
formShow.DoModal();
}
}
ShowWindow(SW_HIDE);this
return 1;
}orm
三、在合適的地方加入註冊代碼:
int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CFrameWnd::OnCreate(lpCreateStruct) == -1)
return -1;
//註冊系統熱鍵
RegisterHotKey(GetSafeHwnd(), 0x2015, MOD_CONTROL, 'Q');
//RegisterHotKey(Handle, hotkeyid, MOD_ALT, VK_F8);
return 0;
}
或者是對話框的OnInitialDialog()函數也能夠。input
四、在銷燬窗口前銷燬系統熱鍵註冊
BOOL CMainFrame::DestroyWindow()
{
UnregisterHotKey(GetSafeHwnd(), 0x2015);
return CFrameWnd::DestroyWindow();
}it
//根據配置設置熱鍵
//首先判斷是否設置了F1~F12鍵
BOOL bSetFunCall = FALSE;
CString strFunc = m_settings.GetFunction();
for (int i=0; i<12; i++)
{
CString curFunc;
curFunc.Format("F%d", i+1);
if (curFunc == strFunc)
{
RegisterHotKey(GetSafeHwnd(), SHORTCUTKEY, 0, VK_F1+i);
bSetFunCall = TRUE;
break;
}
}io
//註冊非功能鍵
if (!bSetFunCall)
{
UINT mod = 0;
if (m_settings.IsAlt()) mod |= MOD_ALT;
if (m_settings.IsCtrl()) mod |= MOD_CONTROL;
if (m_settings.IsShift()) mod |= MOD_SHIFT;
if (m_settings.GetLetter().GetLength() > 0) {
RegisterHotKey(GetSafeHwnd(), SHORTCUTKEY, mod, m_settings.GetLetter().GetAt(0));
}
}form