////////////////////////////////////////////////// First of all, the definition of ////////////////////////////////////////
HWND g_hWnd; / / define a window handle
HHOOK g_hMouse; / / mouse hook of the process
HHOOK g_hKeyBoard; / / keyboard hook of the process
////////////////////////////////////////////////// //////////////////////////////////////// The course of the mouse hook callback function
LRESULT CALLBACK MouseProc (int nCode,
WPARAM wParam, LPARAM lParam)
(
return 1;
)
////////////////////////////////////////////////// //////////////////////////////////////// Process keyboard hook callback function
LRESULT CALLBACK KeyboardProc (int nCode, WPARAM wParam, LPARAM lParam)
(
/ *
if (VK_SPACE == wParam) / / VK_SPACE code for the virtual device, said space
/ / We can choose to go to definition to find the other virtual yards, if we
/ / Off at the same time shielding the enter key, then click on the Alt + F4 key to exit.
/ / If you do not even want to shield Alt + F4, add the following sentence to judge
/ / if (VK_F4 == wParam & & (lParam>> 29 & 1))
/ / lParam shifted to right 29, it is the 29th in the first place,
/ / lParam a 29th place, said the Alt key was pressed
return 1;
* /
/////////////////////// Procedure so that in the F2 key from the press after ////////////////// ///////
if (VK_F2 == wParam)
(
:: SendMessage (g_hWnd, WM_CLOSE, 0,0); / / send messages to close
UnhookWindowsHookEx (g_hKeyBoard);
UnhookWindowsHookEx (g_hMouse); / / remove a hook has been installed
/ / When we send a message to close their program, we must remember that the closure of Hook
)
else
return CallNextHookEx (g_hKeyBoard, nCode, wParam, lParam);
/ / Return the process to the next hook (a button hook of a process)
)
////////////////////////////////////////////////// //////////////////////////////////////// Above the callback function, the following is running HOOK
BOOL CInnerHookDlg:: OnInitDialog ()
(
/ / TODO: Add extra initialization here
g_hWnd = m_hWnd; / / get the current window handle for the callback function to use
/ / Install a mouse hook, GetCurrentThreadId () call to return to thread the thread logo
g_hMouse = SetWindowsHookEx (WH_MOUSE, MouseProc, NULL, GetCurrentThreadId ());
/ / Install a keyboard hook
g_hKeyBoard = SetWindowsHookEx (WH_KEYBOARD, KeyboardProc, NULL, GetCurrentThreadId ());
) |