Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

The usage of SetWindowsHookEx?

12 views
Skip to first unread message

SangGyu Nam

unread,
Sep 11, 1995, 3:00:00 AM9/11/95
to
I'm trying to hook the message of DeskTop and use the SetWindowsHookEx API.
But this is very complex.
My hook procedure is created by current process but I don't know what the 4th
parameter dwThreadID is. What is the ID of current process?
And, I'm wanna know more about the 1st parameter.


-----------------------------------------
SangGyu Nam
Medison Co., Ltd. R&D Center Delta Team
E-Mail : hal...@medison.co.kr
-----------------------------------------


L.J. Wischik

unread,
Sep 20, 1995, 3:00:00 AM9/20/95
to
SangGyu Nam <hal...@medison.co.kr> wrote:
>I'm trying to hook the message of DeskTop and use the SetWindowsHookEx API.
>But this is very complex.
>My hook procedure is created by current process but I don't know what the 4th
>parameter dwThreadID is. What is the ID of current process?
>And, I'm wanna know more about the 1st parameter.

If you only want your hook to hook messages meant for your thread of
processing (that is, your application, if it is a regular, simple,
single-threaded one), then put dwThreadID=GetCurrentThread();
If you want to hook messages on a global level, then put dwThreadID=0.
Note that, if you want to put in global hooks, then your
WindowsHookProcedure __MUST__ be in a DLL.

You wrote that you are trying to "hook the message of DeskTop".
Perhaps a better solution would be to _subclass_ the desktop:

oldWndProc=SetWindowLong(GetDesktopWindow(),GWL_WNDPROC,myDesktopWndProc);
to set up the subclassing, and
SetWindowLong(GetDesktopWindow(),GWL_WNDPROC,oldWndProc)
to restore the subclassing.

Note that your 'myDesktopWndProc' __MUST__ be in a DLL.
You would probably store the variable 'oldWndProc' as a global variable
in the DLL. You would also make absolutely sure that the procedure you
write (in the DLL) would be called only once by your program, to avoid
confusion.

Anyway, it would probably look like this:

LRESULT CALLBACK _export myDesktopWndProc(HWND h,UINT u,WPARAM w,LPARAM l)
{ ... some programming here to detect if 'u' is one of the messages
you want to hook
// Then, you will almost always want to call the old WndProc
oldWndProc(h,u,w,l);
}


I have written a 16-bit program 'DESK', which subclasses the
desktop in this way. I use it to respond to user clicks on the
background, to pop up a menu of convenient shortcuts defined in the DLL
in resource workshop. Also, the right button click has been subclassed to
place a 'splat' on the desktop; and the paint message has been subclassed
to draw the splats.

You started your question with 'SetWindowsHookEx'.
Well, my program also creats a global keyboard hook to intercept the key
combination Alt-F10. It then pops up the same menu.
(However, since it is 16 bit, it uses SetWindowsHook() instead of the
extend version.)

If anyone would like a copy of DESK (including source code), please email me.
I use it as a replacement for BackMenu because it has several convenient
features:
- ability to define your custom menus graphically, using whatever
resource workshop you use
- the menu goes away when you click somewhere else on the desktop
- ability to set up different menus for any combination of
mouse-clicks. So, you can have single-click to put up your
menu, but a double-click to bring up the taskmanager.
- programs can be executed from click combinations without
needing to bring up a menu first
- you can SPLAT! on the desktop

--
Lucian Wischik, Queens' College, U of Cambridge. ljw...@cam.ac.uk

0 new messages