VC下简易实现全局热键--无DLL无钩子(Register HotKey)
2008-02-17 17:37
435 查看
使用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);
}
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);
}
相关文章推荐
- VC++实现监视系统的键盘操作 创建记录键盘动作的全局钩子DLL
- VC++实现监视系统的键盘操作(2) 创建记录键盘动作的全局钩子DLL
- Java设置全局热键钩子——第三方包jintellitype实现
- VC中调用系统全局的钩子实现(附注释)
- VC++实现监视系统的键盘操作(3)调用键盘钩子DLL
- VC++实现全局钩子勾住消息对话框
- delphi——自定义dll,全局钩子的实现
- VC中调用系统全局的钩子实现(附注释)
- VC++实现全局钩子勾住textout金山快译的原理实现
- VC全局热键的实现
- VC实现的全局键盘钩子
- 使用钩子技术实现QT中的全局热键
- VC++实现全局钩子勾住textout金山快译的原理实现
- 接触DLL编写并实现线程注入和全局钩子
- VC++截取输入法输入信息钩子dll实现
- Win32全局钩子在VC中的实现
- VC++截取输入法输入信息钩子dll实现
- Win7环境使用VC2008编写DLL实现键盘钩子
- 鼠标函数VC++全局钩子实现鼠标坐标值实时捕获
- VC++截取输入法输入信息钩子dll实现