Problem With WH_SHELL hook
Hi, I have set up a hook to moniter which window is activated and then display the title of the window in a message box, but it only displays the title of the window when you activate command boxes, and only displays messageboxes for the first cmd to be activated and ignores the rest. this probally doesn't make since, but can anyone look over my code to see what is going wrong?
variable declaration and setting up the hook...
Code:
HHOOK hWindowHook;
hWindowHook = SetWindowsHookEx (WH_SHELL, (HOOKPROC)WindowEvent, hExe, 0);
the function that is only called once each time the program is opened, and stops notifications after...
Code:
__declspec(dllexport) LRESULT CALLBACK WindowEvent (int nCode, HWND wParam, LPARAM lParam, WPARAM wParam2){
if(nCode < 0) return CallNextHookEx(NULL, nCode, wParam2, lParam);
if(nCode == HSHELL_WINDOWACTIVATED){
char buf[100];
GetWindowText(wParam, buf, 100);
MessageBox(NULL, buf,buf, 0);
}
anyways if you can't find what is causing it to act this way, thanks for reading my post anyways!
Re: Problem With WH_SHELL hook
A question:
why are you passing NULL to CallNextHookEx? The first parameter should be the handle returned from a call to SetWindowsHookEx.
Also, try removing the call to MessageBox and using a different way to notify show window text.
Re: Problem With WH_SHELL hook
Msdn says the first parameter of CallNextHookEx is ignored (http://msdn.microsoft.com/library/en...nexthookex.asp)
also, I tried simply writing the window text to a text file and it seems to be doing the same thing and only writing to the text file once, and only writing if you activate a command line box. here is the code if it helps....
Code:
__declspec(dllexport) LRESULT CALLBACK WindowEvent (int nCode, HWND wParam, LPARAM lParam, WPARAM wParam2){
if(nCode < 0) return CallNextHookEx(NULL, nCode, wParam2, lParam);
if(nCode == HSHELL_WINDOWACTIVATED){
char buf[100];
char buf2[100];
GetWindowText(wParam, buf, 100);
sprintf(buf2, "%s", buf);
ofstream out("window.txt",ios::app);
out<<"\n"<<buf2;
out.close();
}
return CallNextHookEx(NULL, nCode,wParam2,lParam);
}