Newsgroups : Borland : borland.public.delphi.nativeapi.win32 : 2006 Dec : SetWindowsHookEx for a single external process?

www.cryer.info
Managed Newsgroup Archive

SetWindowsHookEx for a single external process?

Subject:SetWindowsHookEx for a single external process?
Posted by:"Dave" (daytonada..@dslextreme.com)
Date:Wed, 13 Dec 2006 14:50:29

Hi All,

I have been going round for a few days on an issue here...  Basically, I
have a 3rd party app that allows the user to exit even if the app is not in
a safe place to do so.  This results in data corruption and a host of other
issues.  The developer of this app is not willing to do anything to prevent
this, so I am doing it myself.

I now control where or not the user can use the File/Exit , System Menu, or
Shutdown/Restart to exit the application based on the apps state.  When it
is safe to close I re-enable those exit methods.  The two methods I have not
been able to stop yet are:  Alt-F4 and End Process in task manager.

I was referred to madshi's madCodeHook to handle this, but have not had a
lot of luck getting it to run as expected when injected into an app.  madshi
actually recommended that I use SetWindowsHookEx instead of madCH.  My
problem there is that I cannot seem to find a way to monitor for WM_CLOSE on
a single process.  It seems wasteful to set a global hook when only a couple
of the processes might be affected.

Can anyone think of any alternatives?  Maybe I am just missing something
obvious?

I would love to see a demo that would intercept and block the WM_CLOSE for
notepad.exe.  If it is possible, then it should be fairly simple.

Anyone want to help me before my head explodes?

THANKS!
Dave

Replies:

www.cryer.info
Managed Newsgroup Archive