热键的注册于释放

来源:互联网 发布:梦想编程现实 编辑:程序博客网 时间:2024/05/06 10:17

热键的注册函数:

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;
}

原创粉丝点击