注册热键 与 线程的创建和停止
MFC:
RegisterHotKey(this->GetSafeHwnd(), 1000, 0, VK_HOME);
RegisterHotKey(this->GetSafeHwnd(), 1001, 0, VK_END);
View - ClassWizard - Message Maps - Class Name 选中 当前工程主要的 CxxxDlg
Messages 选中 PreTranslateMessage
Add Function
BOOL CMyxxxDlg::PreTranslateMessage(MSG* pMsg)
{
// TODO: Add your specialized code here and/or call the base class
if (pMsg->message == WM_HOTKEY)
{
if (pMsg->wParam == 1000)
{
OutputDebugString("push home");
if (hThread == NULL)
{
OutputDebugString("do home");
hThread = ::CreateThread(0, 0, (LPTHREAD_START_ROUTINE)MyThread, (LPVOID)NULL, 0, 0);// 创建线程
}
}
else if (pMsg->wParam == 1001)
{
OutputDebugString("push end");
if (hThread!=NULL)
{
OutputDebugString("do end");
SuspendThread(hThread);// 挂起线程
CloseHandle(hThread);// 关闭线程句柄(这两步可终止线程)
hThread = NULL;
}
}
}
return CDialog::PreTranslateMessage(pMsg);
}
浙公网安备 33010602011771号