I try to get notified when a new window is created. To accomplish that i use a global windows hook like that:
LRESULT CALLBACK ShellHookProc(int code, WPARAM wParam, LPARAM lParam)
{
if(code == HSHELL_WINDOWCREATED) {
HWND hWindow = (HWND)wParam;
WCHAR wndText[255];
GetWindowText(hWindow, wndText, 255);
MessageBox(nullptr, L"WindowCreated", wndText, MB_OK);
}
return CallNextHookEx(nullptr, code, wParam, lParam);
}
__declspec(dllexport) void __stdcall initHooking()
{
HHOOK gShellHook = SetWindowsHookEx(WH_SHELL, ShellHookProc, GetModuleHandle(L"HookDll.dll"), 0);
if(gShellHook == nullptr) {
std::wstringstream strm;
strm << L"Error setting hook: " << GetLastError();
MessageBox(nullptr, strm.str().c_str(), L"", MB_OK);
}
}
The hook actually works, but it gets called like 10 times for the same window with the same window handle. Is that normal? And if so whats the reason?
Greetings
Muepe