15,472
社区成员
发帖
与我相关
我的任务
分享
if(GlobalFindAtom("Hotkey") == 0)
{
// 如果没有存在于原子列表,则创建一个原子
m_nHotKeyID_S = GlobalAddAtom("Hotkey");
// 注册全局热键Ctrl + Alt + R
RegisterHotKey(handle, m_nHotKeyID_S, CONTROL + ALT, R);
}
else // 如果HotKey已经存在于原子列表,则终止程序运行
PostQuitMessage(0);
LRESULT CTDlg::OnHotKey(WPARAM wp, LPARAM lp)//respond to the hotkey
{
if(wp == m_nHotKeyID_S )
{
CenterWindow();
ShowWindow(SW_SHOW);
}
return 0;
}
BOOL CTDlg::MyRegisterHotKey(LPCTSTR lpString, int id, UINT
fsModifiers, UINT vk)
{
// 寻找HotKey对应的原子是否存在于原子列表
if(GlobalFindAtom(lpString) == 0) // 返回0说明未注册此键
{
id = GlobalAddAtom(lpString); // 把strHotKeyShow
加入原子列表
BOOL bIsKeyRegistered = RegisterHotKey(this-
>m_hWnd, id, fsModifiers, vk);
ASSERT(bIsKeyRegistered);
return TRUE;
}else{
MessageBox(_T("热键已经存在!"));
PostQuitMessage(0);
}
return FALSE;
}
BOOL CTDlg::MyUnregisterHotKey(int id)
{
BOOL bIskeyUnregistered = UnregisterHotKey(this->m_hWnd,
id);
ASSERT(bIskeyUnregistered);
GlobalDeleteAtom(id);
return 0;
}
protected:
HICON m_hIcon ; //the Notify Icon
ATOM m_nHotKeyID_S; // 创建全局原子列表
LRESULT CTshutDlg::OnHotKey(WPARAM wp, LPARAM lp)//respond to the hotkey
{
if(wp == m_nHotKeyID_K){
ShowFace();
}else if(wp == m_nHotKeyID_H){
OnButtonHide();
}else if(wp == m_nHotKeyID_R){
SystemShutdown(1);
}else if(wp == m_nHotKeyID_S) {
SystemShutdown(2);
}else if(wp == m_nHotKeyID_Q) {
OnButtonQuit();
}else if(wp == m_nHotKeyID_L) {
OnMenuLock();
}
return 0;
}