Skip to main content
gamedev.net
🔒 Locked

Blocking Window Messages

Started by Ratterbox Jun 6, 2004 at 8:03 AM 9 replies 900+ views
Original Post
Ratterbox
Ratterbox
Hi. Is it possible to block or prevent a windows messages. I want to block the WM_CONTEXTMENU and WM_RBUTTONUP messages from being sent to a windows window procedure. How am I able to do this? Thanks [edited by - Ratterbox on June 6, 2004 9:03:49 AM]
MauMan
MauMan
You usually do this with windows hook by calling SetWindowsHookEx. read this for details on message hooks.
---CyberbrineDreamsSuspected implementation of the Windows idle loop: void idle_loop() { *((char*)rand()) = 0; }
Wildfire
Wildfire
Is the window one from your own application? In that case... simply ignore those messages.

If you want to intercept messages sent to another application you could try using the PeekMessage-function to get them:


BOOL PeekMessage(
LPMSG lpMsg,
HWND hWnd,
UINT wMsgFilterMin,
UINT wMsgFilterMax,
UINT wRemoveMsg
);


Use this to intercept the messages sent to the window (you need the handle, set wRemoveMsg ''PM_REMOVE''). Repost the messages that should get through and ''drop'' the ones you want to remove.

I guess it won''t work most of the time though.

The application itself will be reading its own messages with PeekMessage (probably). Depending on the scheduler either your programm or the target-application will be executed first, so your programm may or may not get to see the message before the application does.


What are you trying to do this for btw.? Preventing users to right clicking and/or using the context menu sounds like some vb "security" script to stop users from downloading images from a webpage (which is not worth the effort...).
How do I set my laser printer n stun? o
kuphryn
kuphryn
Interesting.

Given that you wanted to block the message to main window, one possible solution is to override PreTranslateMessage().

Kuphryn
Ratterbox
Ratterbox
The reason I want to do this, is because I am making a Mouse Gestures application that allows mouse gestures to be used in every program.

I have installed a system-wide mouse hook, and that works fine. The problem is, is if for example I do the gesture for minimize, the window minimizes, and then shows its context menu. Windows then flashes the window thinking its been updated in the background.

Ofcourse, I dont want this to happen, so im trying to prevent the context menu from showing up.

My current attempted at the solution (which isnt working), is that I override the WndProc of the window using SetWindowLong(hWnd, GWL_WNDPROC, MyNewWindowProcedureHere); and then I ignore WM_CONTEXTMENU, and WM_RBUTTONUP. However it isnt working.

Anymore ideas?
Etnu
Etnu
I''m fairly certain that windows security features will prevent you from doing this sort of thing, because it reeks of attempting to hack into the application for malicious use (from windows'' point of view).

The real issue is that you may be preventing some necessary functionality of the target app. That could cause a big problem.



---------------------------Hello, and Welcome to some arbitrary temporal location in the space-time continuum.
Ratterbox
Ratterbox
I would be more than grateful if you would post some code as to how to inject my own code into another apps address space. Also, could you enlighten me as to how to subclass another apps window?

Im not sure as to how to do that either.

Thank you for your help.
Hanny
Hanny
I''d love to know the answer to this, too. I just finished up work on a school project of my own two days ago; this was an unresolved problem of mine as well.

Injecting the code into other apps'' memory space doesn''t seem like a good solution; who knows how many apps there might be that need to be injected. There has to be some way to disable the context menu entirely on a system-wide, low-level basis.

Anyone have any ideas?

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.