使用RegisterHotKey()函数即可.
MSDN:The RegisterHotKey function defines a system-wide hot key.
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
-
);
href="http://www.j2megame.org/wupei/plugins/plogeshi/styles/plogeshi.css" type="text/css" rel="stylesheet" />具体实现: 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);
-
}
本文介绍如何使用 RegisterHotKey 函数来定义全局热键,并通过示例展示了如何在对话框初始化时注册热键(如 Ctrl+W),以及如何在 WM_HOTKEY 消息中处理相应的热键操作。

6508

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



