responding to arrow keys (Win32)

Nigel Nunn nNunn at ausport.gov.au
Wed May 17 10:27:58 EDT 2000


Recently, someone asked about responding to arrow keys. 
Just started experimenting with a view class for the
new VC++ WTL library (April SDK), and the following is 
working well.  (Please note that this uses ATL/WTL, not 
the MFC classes, but both libs take the same approach 
to message handling.) 
 
 
  virtual BOOL PreTranslateMessage(MSG* pMsg) 
  { 
    if (CFrameWindowImpl<CMainFrame>::PreTranslateMessage(pMsg)) 
      return TRUE; 
 
    if (pMsg->message == WM_KEYDOWN)  
    {  
      CString msg; 
      switch (pMsg->wParam) // VK_XXX flags  
      { 
      case VK_ESCAPE: msg = "Key press: ESCAPE "; break; 
      case VK_SPACE : msg = "Key press: SPACE "; break; 
      case VK_PRIOR : msg = "Key press: Page UP"; break; 
      case VK_NEXT  : msg = "Key press: Page Down"; break; 
      case VK_END   : msg = "Key press: END "; break; 
      case VK_HOME  : msg = "Key press: HOME "; break; 
      case VK_LEFT  : msg = "arrow press: LEFT "; break; 
      case VK_UP    : msg = "arrow press: UP   "; break; 
      case VK_RIGHT : msg = "arrow press: RIGHT"; break; 
      case VK_DOWN  : msg = "arrow press: DOWN "; break; 
      default : msg.Format("Key flag was %d",pMsg->wParam); break; 
      } 
      MessageBox(msg); 
    }

    return m_view.PreTranslateMessage(pMsg);
  }


To get other info from a MSG structure, try 

  if (pMsg->message == WM_RBUTTONDOWN)
  {
    HWND   hwnd    = pMsg->hwnd;
    UINT   message = pMsg->message;
    WPARAM wParam  = pMsg->wParam;
    int xPos       = LOWORD(pMsg->lParam);
    int yPos       = HIWORD(pMsg->lParam);
    DWORD  time    = pMsg->time;
  }

Nigel 
nnunn at ausport.gov.au 


--------------------------------------------------------------------
This is the private VTK discussion list. Please keep messages on-topic.
Check the FAQ at: <http://public.kitware.com/cgi-bin/vtkfaq>
To UNSUBSCRIBE, send message body containing "unsubscribe vtkusers" to
<majordomo at public.kitware.com>. For help, send message body containing
"info vtkusers" to the same address.
--------------------------------------------------------------------



More information about the vtkusers mailing list