您的位置:首页 > 其它

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

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: