热键的注册函数:
BOOL RegisterHotKey(
HWND hWnd, // handle to window
int id, // hot key identifier
UINT fsModifiers, // key-modifier options
UINT vk // virtual-key code
);
应用例子:
RegisterHotKey(this->m_hWnd,100,MOD_CONTROL,VK_F12);
热键释放函数:
BOOL UnregisterHotKey(
HWND hWnd, // handle to window
int id // hot key identifier
);
应用例子:
UnregisterHotKey(this->m_hWnd,100);
消息响应函数:
LRESULT ChootKeyDlg::OnHotKey(WPARAM wParam,LPARAM lParam)
{
typedef void (WINAPI *PROCSWITCHTOTHISWINDOW) (HWND, BOOL);
PROCSWITCHTOTHISWINDOW SwitchToThisWindow;
HMODULE hUser32 = GetModuleHandle(_T("user32"));
SwitchToThisWindow = ( PROCSWITCHTOTHISWINDOW)GetProcAddress(hUser32, "SwitchToThisWindow");
SwitchToThisWindow(this->m_hWnd,TRUE);
MessageBox(_T("热键注册成功-恭喜!"));
return 0;
}
本文介绍了Windows环境下热键的注册与释放方法,包括使用RegisterHotKey和UnregisterHotKey函数的具体步骤,并提供了实例代码。此外,还展示了如何在收到热键消息时执行特定操作。
6982

被折叠的 条评论
为什么被折叠?



