Hi all,
I have developed a BHO that installs low level keybaord hooks and CBT
hooks globally whenever IE is opened.The keys that are pressed when IE
is active are to be captured.I am trying to check whether the IE is
active first, If it is i set a boolean flag.In the key hook proc ,if
the flag is set, the keys are sent for further processing.The keyboard
hooks is working fine(when checked separately), but the CBT hooks is
not working properly. The IE page is taking a long time to load and
after it loads, its not informing me abt whether the IE is active. The
only code returns is the Window creations.Nothing else is happening.
My hook proc is as follows:
public static int CbtHookProc(int nCode, IntPtr wParam,IntPtr lParam)
{
StringBuilder title = new StringBuilder();
string classname;
title.Capacity=10;
if(nCode==HCBT_ACTIVATE)
{
try{
GetClassName(wParam,title,10);
classname=title.ToString();
if(classname.StartsWith("IE"))
IE_Active=true; //an bool variable set to false initially
else
IE_Active=false;
}
catch(Exception e) {
MessageBox.Show(e.ToString());
}
}
return CallNextHookEx(CBTHook,nCode,wParam,lParam);
}
Win32 Import for GetClassName is as follows:
[DllImport("user32.dll")]
protected static extern int GetClassName(IntPtr hwnd,
StringBuilder lpClassName, int nMaxCount);
Is this correct?If so , y is this not working? wat am i missing in
this?.
thanks and regards,
Hema