I want to hook all WM_COMMAND and modify some of them so the users can not access to a menu anymore. For the moment I have already wroten the hook (wich works good), but i don't know how to modify the message. Dos anyone has an idea ? (s)
hi, here are my thoughts on this matter.. as you probably already know hooks are chained in a linked list with the most recent installed hook at the head of the list, and when an event occurs, the OS will call only the first hook in the chain. your hook procedure must make the call the next hook in the chain and pass the message to him. if your hook proc change the message in the mean time the next hook would caught the modified message. the thing is, this works with other hook procs in the chain (or at least it should work), but i don't know if this is gona change the messages sent to the "normal" win procs for the running progs (i think it should change, since hooks were primarily made for debugging). and note that the hook procedures for some types of hooks can only monitor messages (i.e you can see the message but you can't change it). the system passes messages to each hook procedure, regardless of whether a particular procedure calls CallNextHookEx. if this doesn't work, instead of changing the message sent to the CallNextHookEx, try to send a message in some other way.. maybe with PostMessage. other thing.. before displaying any menus, the system sends the WM_INITMENU message to the window procedure so that an application can modify the menus before the user sees them. maybe you should caught this message instead of the WM_COMMAND and then disable the menu. WM_INITMENU gives you the menu handle to be initialized. i'm afraid this ain't gona be helpfull cos i don't know wich message to sent then.. not much help.. try everything you can, i'm almost sure this can be done (just haven't tried yet:D) ensein
if you use the SetWindowsHookEx function, you can return a corresponding value in the HandlerProc. Not all modes of SetWindowsHookEx support a modification of the message.
You must subclass a window to change its behaviour. Hook can trap messages but can't change them. But function SetWindowLongA checks is window belongs to the calling process. So we have to call SetWindowLongA from another process. We can do it if we install thread-wide hook WH_GETMESSAGE and call SetWindowLongA from callback-function GetMsgProc. It works, I did it. If you need a sample, I can give you one.
In fact, I found the answer by myself : in the GetMsgProc, lParam point to the Msg struct send to the app, just change this to modify the message, and it works. (if you want the source, mail me) (s)