We help IT Professionals succeed at work.

PreTranslateMessage

orange_juice
orange_juice asked
on
Medium Priority
779 Views
Last Modified: 2013-11-20
I use PreTranslateMessage() to capture F5 key in CMyApp for FormView derived project. I want to trigger dosomething() when i push F5

......

   switch(pMsg->wparam)
{
case VK_F5:
    dosomething(); //dosomething is a function in CMyView
    break;
......
}

problem is, every time i press F5, dosomething() gets trigger twice. What is the problem?
Dosomething() is ok, as i also map it to a button click event, and it trigger once only if i click on button


sorry for the bit short code been put up, i hope this is enough to highlight my problem.
Comment
Watch Question

Author

Commented:
ok, i missed something



switch(pMsg->wparam)
{
case VK_F5:
   pView->dosomething();//dosomething is in CMyView
   break;
......
}


//pView is pointer to my CMyView
AxterSenior Software Engineer

Commented:
Add a busy variable that will stop it from pass through on a second thread.

Example:

static busy = false;

if (!busy)
{
   busy = true;

   switch(pMsg->wparam)
   {
   case VK_F5:
     pView->dosomething();//dosomething is in CMyView
     break;
   ......
   }

   busy = false;
}
Sr Program Manager
Commented:
Hi,

U just include one more checking in ur PreTranslateMessage funtion like

...
...
if(pMsg->message == WM_KEYDOWN)
{
switch(pMsg->wparam)
{
....
case VK_F5:
//Do whatever u want to do
break;
....
}
}
...
...

Try it out.
VinExpert
AndyAinscowFreelance programmer / Consultant
CERTIFIED EXPERT

Commented:
You are getting one for the KEYDOWN and one for the KEYUP events.