PeekMessage

I need to do the following:
1. Peek windows message
2. If message is "User pressed ESC key", do nothing, else translate and dispatch the message.

How can i modify the below code to suit my need?


MSG msg;
while(PeekMessage(&msg, NULL, 0, 0,PM_NOREMOVE))
{
   if (msg.message == WM_KEYDOWN &&  msg.wParam == VK_ESCAPE )
   {
        //??????
   }
   GetMessage(&msg,NULL,0,0);
   TranslateMessage(&msg);
   DispatchMessage(&msg);
}
leowlfAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

inprasCommented:
while(PeekMessage(&msg, NULL, 0, 0,PM_NOREMOVE))
{
   if (msg.message == WM_KEYDOWN &&  msg.wParam == VK_ESCAPE )
   {
        continue;
   }
   GetMessage(&msg,NULL,0,0);
   TranslateMessage(&msg);
   DispatchMessage(&msg);
}

0
leowlfAuthor Commented:
That won't work.
It will go into a infinite loop if the user press the ESC key, because the ESC message will forever remains in the message queue.
0
Vinayak KumbarSr Program ManagerCommented:
Hi,

How about manipulating the ESCAPE massage with something else that Ur program does not need?

while(PeekMessage(&msg, NULL, 0, 0,PM_NOREMOVE))
{
if (msg.message == WM_KEYDOWN &&  msg.wParam ==
                               VK_ESCAPE )
   {
         msg.wParam = 0;// nullify that message
    }
GetMessage(&msg,NULL,0,0);
TranslateMessage(&msg);
DispatchMessage(&msg);
}

here instead of making it null, u can modify it to some other kay. And u can modify the msg.message to something else and dispach those messages.

Try it out.

VinExpert
0
Cloud Class® Course: Microsoft Azure 2017

Azure has a changed a lot since it was originally introduce by adding new services and features. Do you know everything you need to about Azure? This course will teach you about the Azure App Service, monitoring and application insights, DevOps, and Team Services.

inprasCommented:
Where is this code of URs U have put?
0
inprasCommented:
Where is this code of URs U have put?
I mean in which function?
Regards
0
mikeblasCommented:
The problem is that you're using PeekMessage().  Why is that?  You should be using GetMessage().

I guess you're using PeekMessage() because you don't want to block when no message is around.  Then, you should code:


   MSG msg;
   while(PeekMessage(&msg, NULL, 0, 0,PM_NOREMOVE))
   {
      GetMessage(&msg,NULL,0,0);
      if (msg.message != WM_KEYDOWN || msg.wParam != VK_ESCAPE )
      {
         TranslateMessage(&msg);
         DispatchMessage(&msg);
      }
   }

If you're writing an MFC application, it seems like you should be able to find a more appropriate override to realize this functionality.  But it's pretty wierrd functionality: what are you really trying to do? Do you want to leave the WM_KEYDOWN/VK_ESCAPE messages in the queue for some reason?  Why?

..B ekiM


0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
System Programming

From novice to tech pro — start learning today.