Re: Windows Hooks and Switching Applications
sure..
I did one years back...i can't say 100%
HMODULE hDll=::LoadLibrary("HookDll");//your hook dll which u should
create
HookProc *pHook;
pHook=(HookProc*)::GetProcAddress(hDll,"HookProc");
h_global_hook=::SetWindowsHookEx(WH_CBT,(HOOKPROC)pHook,hDll,NULL);
this should be your hook exe side
You have to write hookdll
extern "C" LRESULT PASCAL EXPORT HookProc(int nCode, WPARAM wParam,
LPARAM lParam )
{
AFX_MANAGE_STATE(AfxGetStaticModuleState());
try
{
CBTACTIVATESTRUCT *myStuct =(CBTACTIVATESTRUCT*)lParam;
if(nCode<0)return CallNextHookEx(glob_hook,nCode,wParam,lParam);
if(nCode==HCBT_MINMAX||nCode==HCBT_MOVESIZE||nCode==HCBT_ACTIVATE)//if
active or resize or min max
//plz reomove un necessorry events
{
// char str[100];
// cnt++;
//HWND hwnd=myStuct->hWndActive;
HWND hwnd=(HWND)wParam;
::GetWindowText(hwnd,str,strlen(str));
//::GetClassName(hwnd,str,strlen(str));
if(!strcmp(str,"windowcaption"))//instead of window caption , we
//can place any windows text which we want to notify
{
MessageBox(::GetActiveWindow(),"Acive OK","TestHook",0);
return 0;
//}
}
}
catch(...)
{
AfxMessageBox("Error In HOOk DLL");
}
return 0;
}