Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Ratterbox

Blocking Window Messages

This topic is 5223 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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]

Share this post


Link to post
Share on other sites
Advertisement
You usually do this with windows hook by calling SetWindowsHookEx. read this for details on message hooks.

Share this post


Link to post
Share on other sites
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...).

Share this post


Link to post
Share on other sites
Interesting.

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

Kuphryn

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
umm, neither of the above mentioned methods will work if you want to prevent another app or thread from receiving those messages. the only way to do this correctly is to get part of your own code, usually via an injected dll, into the other app''s address space, and then to have your own code sub-class that particular window so that it can process all of its window messaages first and "return 0" on the ones that it doesn''t want to have processed.

you can also get your code to run within another app''s address space via a system-wide hook, but the hook itself will not allow you to prevent a message from being passed on to the app. instead, you must use other mechanisms to get the sub-classing accomplished, which is the only correct way of intercepting window messages other than to spoof the system dll functions with your own.

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
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.



Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Windows will not let you sub-class another app''s window proc unless the code doing the sub-classing is within the other app''s address space. that''s why you must either dll-inject or use a system-wide hook and execute the sub-classing code within the hook processing code, which means that your app''s code will then be executing within the context of the other app''s address space.

either method works fine under all versions of Windows from XP backwards, as Windows has always been a very open OS with regards to manipulating other app''s windows.

if you''d like an example, i''d be more than happy to post some code here.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!