Sign in to follow this  
gerbenvv

Disable key messages

Recommended Posts

In my game, key messages are send by windows to my window-procedure. This can affect the fps of the game, cause the game checks first if there are any messages and handles them. But in the game procedure, i handle my own key messages. Is there a way to disallow (disable) windows from sending those key messages? (VK_*) Gerben VV

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Not really. If they are affecting the performance of your game noticably, though, you're doing something very, very, very wrong somewhere in your code. Perhaps if you described your game loop in detail or posted some code, others could help you fix the bug.
-Extrarius

Share this post


Link to post
Share on other sites
Yes, there is. The last two parameters of GetMessage () function are used to specified the range between allowed messages.
But IMO, there're tons of messages are sent to your window and most of them are processed by DefWindowProc (), you should let Windows do the work for you, even if you want to disable some messages, the nunmber of remaining messages is still huge in comparison to these disabled ones.

Hth
V@T

Share this post


Link to post
Share on other sites
Well, firstly my specifying range is applicable only to applications which completely handle input messages (no API GetKeyboardState () or similar at all because they won't work).

In my application, it is between WM_CREATE and WM_NCXBUTTONDBLCLK.
It maynot be correct for your application though.

Hth
V@T

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
What happens to messages you don't process in such a way? I doubt windows discards them because you might later have another call to GetMessage/PeekMessage that processes those messages. As far as I can tell, MSDN doesn't specify what happens to messages filtered out by the two parameters given.

Likely, such a method will cause messages to build up in a buffer and eventually you'll probably get very strange errors once the message buffer is filled (if it is a fixed size). Alternately, if the buffer is growable, you might have what appears to be a memory leak as more and more memory is used to buffer unprocessed messages.

At the very least, you should have a PeekMessage that will catch messages from 0 to one less than the lowest you process, and another PeekMessage from the highest+1 you process to the maximum value (0xFFFF because you can only pass in a single word for each value) to discard messages that you don't process. This could be dangerous, though, since you have no idea what important messages you might be discarding.

-Extrarius

Share this post


Link to post
Share on other sites
I thought about that and tried, the messages really got filtered out. I coded the main () function like this:


while(GetMessage(&msg, NULL, firstMsg , lastMsg))
{
TranslateMessage(&msg);
DispatchMessage(&msg);

}

MessageBox (NULL, NULL, 0, 0) ; //To know when the user clicked Close button

while(GetMessage(&msg, NULL, 0 , 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}



I did some mouse and keyboard inputs while in the WindowProc () I still processed these messages, apparently I got nothing. Then after clicking the close button, a message box showed up then the app exited, doesn't that mean no messages are buffered ?.

But as Extrarius mentioned, these kind of 'optimizations' make no sense even in a very small app. I just gave you a way to do this, this shouldn't be implemented.

V@T

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Your typical PC does a couple hundred million things per second. Even with key repeat rate cranked all the way up, the rate at which key messages come into your app is analogous to the passing of Halley's Comet. This is really a very silly optimization.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this