win api怎么设置全局热键

win api如何设置全局热键
想做个全局热键,比如按下F5,某个程序能响应这个消息,此时焦点可能不再某个程序上

------解决方案--------------------
RegisterHotKey(NULL, id, 0, VK_F5);
------解决方案--------------------
探讨

RegisterHotKey(NULL, id, 0, VK_F5);

------解决方案--------------------
RegisterHotKey/UnRegisterHotKey
------解决方案--------------------
VC下简易实现全局热键--无DLL无钩子(Register HotKey)

使用RegisterHotKey()函数即可.
MSDN:The RegisterHotKey function defines a system-wide hot key.
//函数原型:
BOOL RegisterHotKey(
HWND hWnd, // window to receive hot-key notification
int id, // identifier of hot key
UINT fsModifiers, // key-modifier flags
UINT vk // virtual-key code
);

具体实现: 1.首先加入函数
BOOL CMyDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// Set the icon for this dialog. The framework does this automatically
// when the application's main window is not a dialog
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon
// TODO: Add extra initialization here
//注册热键(Ctrl+W,标识9999)
RegisterHotKey(this->m_hWnd,9999,MOD_CONTROL,'W');
return TRUE; // return TRUE unless you set the focus to a control
}
2.加入相应全局热键函数
//相应WindowProc消息,加入函数
LRESULT CMyCatchScreenDlg::WindowProc(UINT message, WPARAM wParam, LPARAM lParam)
{
switch(message)
{
///////////////
//热键操作
case WM_HOTKEY:
if(wParam==9999)
{
if(!IsWindowVisible())
{
//ShowMyWindow(); // 实现代码
}
else
{
//HideMyWindow(); //实现代码
}
}
break;
}
return CDialog::WindowProc(message, wParam, lParam);
}