Hi everyone,
I try to do local hook to writing window on NotePad, my code is:
#include <windows.h>
HHOOK keyboardHook;
LRESULT CALLBACK KeyboardProc(int nCode, WPARAM wParam, LPARAM lParam)
{
if (wParam == WM_KEYDOWN && nCode == HC_ACTION)
{
Beep(440, 440);
return 0;
}
return CallNextHookEx(keyboardHook, nCode, wParam, lParam);
}
int main()
{
HWND hParent = FindWindow(L"Notepad", L"Untitled - Notepad");
HWND hChild = FindWindowEx(hParent, NULL, L"Edit", L"");
DWORD processId;
DWORD threadId = GetWindowThreadProcessId(hChild, &processId);
keyboardHook = SetWindowsHookEx(WH_KEYBOARD_LL, KeyboardProc, 0, threadId);
MSG msg{ 0 };
while (GetMessage(&msg, NULL, 0, 0) != 0);
UnhookWindowsHookEx(keyboardHook);
return 0;
}
"Global hook" works well when I put the last parameter of SetWindowsHookEx function is zero. But local hook with this parameter threadId (not equal to zero) is not working ! I don't know why is that ! Help me, please. Thanks.
What I have tried:
I tried to find this problem from internet, but there is no !