We help IT Professionals succeed at work.

PreTranslateMessage

orange_juice
orange_juice asked
on
i want to use F9, F10, F11, F12 keypress to trigger some function in my view class
i handle PreTranslateMessage() in any class other than my App class CMyApp
i did this.... it works ok, but a press on button 'x' also trigger VK_F9
i tried
    case VK_F9:
       if(pMsg->wParam != 'x')
      {pView->DoF9();}
      break;

also don't work. It kill my VK_F9 also.
what is wrong? Any other ways to do this? Here is my code

    BOOL CMyApp::PreTranslateMessage(MSG* pMsg)
    {
     BOOL ok=FALSE;    
     CFrameWnd *pFrame=(CFrameWnd*)m_pMainWnd;
     CAutopanelView *pView=(CMyView *)pFrame->GetActiveView ();//to get my view class pointer
     
     if((pMsg->message ==WM_SYSKEYDOWN))
     {
          switch(pMsg->wParam)
          {          
               case VK_F10:
                          pView->DoSomethingF10();
                          break;
               default:
                  break;
          }
         }
     else
     {
          switch(pMsg->wParam)
          {
          case VK_F9:
                  pView->DoF9();
               break;
          case VK_F11:
               ...
                break;
          case VK_F12:
               ...
               break;
          default:
               break;
          }
     }
Comment
Watch Question

Sr Program Manager
Commented:
Hi,

Just modify ur function to

BOOL CSDIApp::PreTranslateMessage(MSG* pMsg)
{
     BOOL ok=FALSE;    
    CFrameWnd *pFrame=(CFrameWnd*)m_pMainWnd;
    CSDIView *pView=(CSDIView *)pFrame->GetActiveView ();//to get my view class pointer
   
    if((pMsg->message ==WM_SYSKEYDOWN))
    {
          switch(pMsg->wParam)
          {          
          case VK_F10:
               AfxMessageBox("VK_F10");
               break;
          default:
               break;
          }
     }
    else if(pMsg->message != WM_CHAR)
    {
          switch(pMsg->wParam)
          {
          case VK_F9:
               AfxMessageBox("VK_F9");
               break;
          case VK_F11:              
                    break;
          case VK_F12:              
                    break;
          default:
               break;
          }
    }    
     return CWinApp::PreTranslateMessage(pMsg);
}

Here, in the else part I am putting one more condition like, the message should not be of WM_CHAR type. As u r handling the function keys, that should solve ur prob.

Try it out.
VinExpert

Author

Commented:
ok, thanks
:)

Author

Commented:
ok, thank you :)

Explore More ContentExplore courses, solutions, and other research materials related to this topic.