home *** CD-ROM | disk | FTP | other *** search
/ Chip 2004 July / CMCD0704.ISO / Software / Freeware / Utilitare / VisualBoyAdvance-1.7.2 / src / win32 / KeyboardEdit.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2003-11-04  |  3.9 KB  |  149 lines

  1. ////////////////////////////////////////////////////////////////////////////////
  2. // Copyright (C) 1998 by Thierry Maurel
  3. // All rights reserved
  4. //
  5. // Distribute freely, except: don't remove my name from the source or
  6. // documentation (don't take credit for my work), mark your changes (don't
  7. // get me blamed for your possible bugs), don't alter or remove this
  8. // notice.
  9. // No warrantee of any kind, express or implied, is included with this
  10. // software; use at your own risk, responsibility for damages (if any) to
  11. // anyone resulting from the use of this software rests entirely with the
  12. // user.
  13. //
  14. // Send bug reports, bug fixes, enhancements, requests, flames, etc., and
  15. // I'll try to keep a version up to date.  I can be reached as follows:
  16. //    tmaurel@caramail.com   (or tmaurel@hol.fr)
  17. //
  18. ////////////////////////////////////////////////////////////////////////////////
  19. // File    : KeyboardEdit.cpp
  20. // Project : AccelsEditor
  21. ////////////////////////////////////////////////////////////////////////////////
  22. // Version : 1.0                       * Authors : A.Lebatard + T.Maurel
  23. // Date    : 17.08.98
  24. //
  25. // Remarks : implementation file
  26. //
  27. ////////////////////////////////////////////////////////////////////////////////
  28.  
  29. #include "stdafx.h"
  30. #include "KeyboardEdit.h"
  31.  
  32. #ifdef _DEBUG
  33. #define new DEBUG_NEW
  34. #undef THIS_FILE
  35. static char THIS_FILE[] = __FILE__;
  36. #endif
  37.  
  38. extern TCHAR* mapVirtKeysStringFromWORD(WORD wKey);
  39.  
  40. /////////////////////////////////////////////////////////////////////////////
  41. // CKeyboardEdit
  42.  
  43. CKeyboardEdit::CKeyboardEdit()
  44. {
  45.   m_bKeyDefined = false;
  46.   ResetKey ();
  47. }
  48.  
  49. CKeyboardEdit::~CKeyboardEdit()
  50. {
  51. }
  52.  
  53.  
  54. BEGIN_MESSAGE_MAP(CKeyboardEdit, CEdit)
  55.   //{{AFX_MSG_MAP(CKeyboardEdit)
  56.   //}}AFX_MSG_MAP
  57.   END_MESSAGE_MAP()
  58.  
  59. #pragma warning( disable : 4706 )
  60.   /////////////////////////////////////////////////////////////////////////////
  61. // CKeyboardEdit message handlers
  62. BOOL CKeyboardEdit::PreTranslateMessage (MSG* pMsg) 
  63. {
  64.   bool bPressed;
  65.   if ((bPressed = (pMsg->message == WM_KEYDOWN)) || pMsg->message == WM_KEYUP || (bPressed = (pMsg->message == WM_SYSKEYDOWN)) || pMsg->message == WM_SYSKEYUP) {
  66.     if (bPressed && m_bKeyDefined && !((1 << 30) & pMsg->lParam))
  67.       ResetKey ();
  68.     if (pMsg->wParam == VK_SHIFT && !m_bKeyDefined)
  69.       m_bShiftPressed = bPressed;
  70.     else if (pMsg->wParam == VK_CONTROL &&!m_bKeyDefined) {
  71.       m_bCtrlPressed = bPressed;
  72.     }
  73.     else if (pMsg->wParam == VK_MENU && !m_bKeyDefined)
  74.       m_bAltPressed = bPressed;
  75.     else {
  76.       if (!m_bKeyDefined) {
  77.         m_wVirtKey = (WORD)pMsg->wParam;
  78.         if (bPressed)
  79.           m_bKeyDefined = true;
  80.       }
  81.     }
  82.     DisplayKeyboardString ();
  83.     return TRUE;
  84.   }
  85.         
  86.   return CEdit::PreTranslateMessage(pMsg);
  87. }
  88. #pragma warning( default : 4706 )
  89.  
  90. ////////////////////////////////////////////////////////////////////////
  91. //
  92. void CKeyboardEdit::DisplayKeyboardString()
  93. {
  94.   CString strKbd;
  95.  
  96.   // modifiers
  97.   if (m_bCtrlPressed)
  98.     strKbd = "Ctrl";
  99.   if (m_bAltPressed) {
  100.     if (strKbd.GetLength () > 0)
  101.       strKbd += '+';
  102.     strKbd += "Alt";
  103.   }
  104.   if (m_bShiftPressed) {
  105.     if (strKbd.GetLength () > 0)
  106.       strKbd += '+';
  107.     strKbd += "Shift";
  108.   }
  109.   // virtual key
  110.   LPCTSTR szVirtKey = mapVirtKeysStringFromWORD(m_wVirtKey);
  111.   if (szVirtKey != NULL) {
  112.     if (strKbd.GetLength () > 0)
  113.       strKbd += '+';
  114.     strKbd += szVirtKey;
  115.   }
  116.   SetWindowText (strKbd);
  117. }
  118.  
  119.  
  120. ////////////////////////////////////////////////////////////////////////
  121. //
  122. void CKeyboardEdit::ResetKey ()
  123. {
  124.   m_wVirtKey = 0;
  125.   m_bCtrlPressed = false;
  126.   m_bAltPressed = false;
  127.   m_bShiftPressed = false;
  128.   
  129.   m_bKeyDefined = false;
  130.   if(m_hWnd != NULL)
  131.     SetWindowText(_T(""));
  132. }
  133.  
  134.  
  135. ////////////////////////////////////////////////////////////////////////
  136. //
  137. bool CKeyboardEdit::GetAccelKey(WORD& wVirtKey, bool& bCtrl, bool& bAlt, bool& bShift)
  138. {
  139.   if (!m_bKeyDefined)
  140.     return false;
  141.   
  142.   wVirtKey = m_wVirtKey;
  143.   bAlt = m_bAltPressed;
  144.   bCtrl = m_bCtrlPressed;
  145.   bShift = m_bShiftPressed;
  146.   return true;
  147. }
  148.  
  149.