Click to See Complete Forum and Search --> : WIn 32 Hooks
xs2ahmed
April 10th, 2003, 08:39 AM
Hi:
I want my Application to notifiled each time a new window is activated..or deactivated (i am refering to any window in OS ),Perhaps using hooks is the best method ,but can someone please write a comprhensive code for it
another query is :
how can i find the absolute file path of the active application (egc:\windows\notepad.exe),
thanks
Ahmed
Metro_Mystery
April 18th, 2003, 12:45 AM
Writing code that Hooks processes requires a lot of time, effort and money. I don't think people will be that nie as to do your project for you- after all, we don't get paid.
Andreas Masur
April 19th, 2003, 05:23 PM
Originally posted by xs2ahmed
Hi:
I want my Application to notifiled each time a new window is activated..or deactivated (i am refering to any window in OS ),Perhaps using hooks is the best method ,but can someone please write a comprhensive code for it
As already mentioned there is basically a zero percent chance of getting any valuable answer for this. Everyone contributing here is doing it in his/her spare time...being volunteers. The forum is intended to help people with specific problems not to write the complete software.
Originally posted by xs2ahmed
another query is :
how can i find the absolute file path of the active application (egc:\windows\notepad.exe),
thanks
Ahmed
Take a look at this FAQ (http://www.codeguru.com/forum/showthread.php?s=&threadid=231171)...
xs2ahmed
April 21st, 2003, 03:47 AM
Hi:
i think some people are getting angry with the text
"comprehensive code"
i did'nt mean to ask you to write full code .....
I think if any one knew something about it ,he would have given me some tips.................................
For Andreas Masur ... i didnt ask to write full software , and i dont think that this problem needs more than 10 lines of code.........
The first part of my question is already solved ....
if any one know something about finding the path of the exe associated with a window ....please let me know...........
thanks
Ahmed
Andreas Masur
April 21st, 2003, 09:01 AM
Originally posted by xs2ahmed
if any one know something about finding the path of the exe associated with a window ....please let me know...........
thanks
Ahmed
Did you take a look at the FAQ I posted in my previous post?
xs2ahmed
April 22nd, 2003, 03:18 AM
Hi:
I think the problem is soved ..
this was what i was asking for
HWND GetForegroundWindow(VOID);
//this returns the handle to active application
//and we can use this handle inthe following func to get the full path of the exe
UINT GetWindowModuleFileName(
HWND hwnd, // handle to window
LPTSTR lpszFileName, // file name buffer
UINT cchFileNameMax // max size of file name buffer
);
thanks to all for helping me
Ahmed
JamesSchumacher
April 22nd, 2003, 10:39 PM
Here is the code of a hook function that would monitor when windows are created.... g_hGlobalHook is the a global, the handle of the hook which would be set via another function after loading the *.dll - that handle is retrieved via SetWindowsHookEx() which is called by the app that loads the *.dll to inject the hook.
int __stdcall MyWindowHook(int nCode,WPARAM wParam,LPARAM lParam)
{
if (nCode < 0)
{
return ::CallNextHookEx(g_hGlobalHook,nCode,wParam,lParam);
}
else
{
CWPSTRUCT * pStruct = reinterpret_cast<CWPSTRUCT *>(lParam);
if (pStruct->message == WM_CREATE)
{
// Do something now that a window is being created.....
// Just don't create another window, that includes a MessageBox() call.
}
return ::CallNextHookEx(::g_hGlobalHook,nCode,wParam,lParam);
}
}
In fact, hooks are one of the easiest parts of the WINAPI to understand. How easy, never used one until 10 minutes ago.
the_ENIGMA
April 29th, 2003, 07:33 AM
the code james has put in here is just the hook handler...
i guess the book from which he learnt about win32 hooks
in 10 min, missed out the hook placing part..
Hook are indeed not cryptic.... save yourself from
the DLL maze....
start with plain code to learn hooks... you need DLL only
when you place an application specific hooks... and
your hook handler needs to be in those DLL...
have a look as this code
************************************************
if(theApp.m_hGlobalHook == NULL)
{
theApp.m_hGlobalHook = SetWindowsHookEx(my_WH_KEYBOARD_LL,(HOOKPROC)LLevelKeyBoardHandler,AfxGetApp()->m_hInstance,0);
if(theApp.m_hGlobalHook == NULL)
{
AfxMessageBox("Hook Failed");
}
}
where the handler is
LRESULT CALLBACK LLevelKeyBoardHandler(INT f_nKeyCode,WPARAM wParam,LPARAM lParam)
{
KBDLLHOOKSTRUCT *pkbhs = (KBDLLHOOKSTRUCT *) lParam;
if((f_nKeyCode == HC_ACTION) && ((wParam == WM_KEYDOWN) || (wParam == WM_SYSKEYDOWN)))
{
if((pkbhs->vkCode == VK_F12) && ((wParam == WM_KEYDOWN) || (wParam == WM_SYSKEYDOWN)))
// global hook for F12 key.....
}
}
******************************************
Just have a simple win32 console binary....
and have fun with hooks...
about the stuff which you want to do,
is just matter of changing the hook type...
(keyboard,mouse, wm_messages, wm_sysmessages)
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.