HHOOK hKeyHook;
LRESULT CALLBACK KeyHookProc(int nCode, WPARAM wParam, LPARAM lParam)
{
if (nCode >= 0) {
if (wParam == VK_F2) {
...
}
}
return CallNextHookEx(hKeyHook, nCode, wParam, lParam);
}
LRESULT CALLBACK WndProc(HWND hWnd,UINT iMessage,WPARAM wParam,LPARAM lParam)
{
switch (iMessage) {
case WM_CREATE:
hWndMain = hWnd;
hKeyHook = SetWindowsHookEx(WH_KEYBOARD, KeyHookProc, NULL, GetCurrentThreadId());
return 0;
case WM_DESTROY:
UnhookWindowsHookEx(hKeyHook);
PostQuitMessage(0);
return 0;
...
}
return(DefWindowProc(hWnd ,iMessage, wParam, lParam));
}
HHOOK hCbtHook;
LRESULT CALLBACK CbtHookProc(int nCode,WPARAM wParam,LPARAM lParam)
{
CBT_CREATEWND *pCbt;
HWND hWnd;
TCHAR szClassName[32];
if (nCode == HCBT_CREATEWND) {
hWnd = (HWND)wParam;
pCbt = (CBT_CREATEWND *)lParam;
if (HIWORD(pCbt->lpcs->lpszClass)) {
lstrcpy(szClassName,pCbt->lpcs->lpszClass);
} else {
GlobalGetAtomName((ATOM)pCbt->lpcs->lpszClass, szClassName, 32);
}
if (lstrcmpi(szClassName, "#32770") == 0 && ((pCbt->lpcs->style & WS_CHILD) == 0)) {
...
}
}
return CallNextHookEx(hCbtHook, nCode, wParam, lParam);
}
LRESULT CALLBACK WndProc(HWND hWnd, UINT iMessage, WPARAM wParam, LPARAM lParam)
{
switch (iMessage) {
case WM_CREATE:
hCbtHook = SetWindowsHookEx(WH_CBT, CbtHookProc, NULL, GetCurrentThreadId());
return 0;
case WM_DESTROY:
UnhookWindowsHookEx(hCbtHook);
PostQuitMessage(0);
return 0;
...
}
return(DefWindowProc(hWnd, iMessage, wParam, lParam));
}
참조 사이트: