ChildView.cpp 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. // ChildView.cpp : implementation of the CChildView class
  2. //
  3. #include "stdafx.h"
  4. #include "VirtualKeyboard.h"
  5. #include "ChildView.h"
  6. #ifdef _DEBUG
  7. #define new DEBUG_NEW
  8. #endif
  9. // CChildView
  10. CChildView::CChildView()
  11. {
  12. m_pkb = NULL;
  13. }
  14. CChildView::~CChildView()
  15. {
  16. }
  17. BEGIN_MESSAGE_MAP(CChildView, CWnd)
  18. ON_WM_PAINT()
  19. ON_WM_LBUTTONDOWN()
  20. ON_WM_LBUTTONDBLCLK()
  21. ON_WM_LBUTTONUP()
  22. ON_WM_MOUSEMOVE()
  23. END_MESSAGE_MAP()
  24. // CChildView message handlers
  25. BOOL CChildView::PreCreateWindow(CREATESTRUCT& cs)
  26. {
  27. if (!CWnd::PreCreateWindow(cs))
  28. return FALSE;
  29. cs.dwExStyle |= WS_EX_CLIENTEDGE;
  30. cs.style &= ~WS_BORDER;
  31. cs.lpszClass = AfxRegisterWndClass(CS_HREDRAW|CS_VREDRAW|CS_DBLCLKS,
  32. ::LoadCursor(NULL, IDC_ARROW), reinterpret_cast<HBRUSH>(COLOR_DESKTOP), NULL);
  33. return TRUE;
  34. }
  35. void CChildView::OnPaint()
  36. {
  37. if(m_pkb)
  38. {
  39. m_pkb->draw();
  40. }
  41. }
  42. bool CChildView::Bind( Keyboard* pkb )
  43. {
  44. if(!pkb)
  45. return false;
  46. m_pkb = pkb;
  47. pkb->rebind(this);
  48. return true;
  49. }
  50. void CChildView::OnLButtonDown(UINT nFlags, CPoint point)
  51. {
  52. if(m_pkb)
  53. {
  54. int index = m_pkb->hit(point);
  55. if(index >= 0)
  56. {
  57. m_pkb->press(index);
  58. }
  59. }
  60. CWnd::OnLButtonDown(nFlags, point);
  61. }
  62. void CChildView::OnLButtonDblClk(UINT nFlags, CPoint point)
  63. {
  64. if (m_pkb)
  65. {
  66. int index = m_pkb->hit(point);
  67. if (index >= 0)
  68. {
  69. m_pkb->press(index);
  70. }
  71. }
  72. CWnd::OnLButtonDown(nFlags, point);
  73. }
  74. void CChildView::OnLButtonUp(UINT nFlags, CPoint point)
  75. {
  76. if(m_pkb)
  77. {
  78. int index = m_pkb->hit(point);
  79. if(index >= 0)
  80. {
  81. m_pkb->release(index);
  82. }
  83. }
  84. CWnd::OnLButtonUp(nFlags, point);
  85. }
  86. void CChildView::OnMouseMove(UINT nFlags, CPoint point)
  87. {
  88. // TODO: Add your message handler code here and/or call default
  89. static HCURSOR hHand = ::LoadCursor(NULL,IDC_HAND);
  90. static HCURSOR hArrow = ::GetCursor();
  91. if(m_pkb)
  92. {
  93. int index = m_pkb->hit(point);
  94. if(index >= 0)
  95. {
  96. if(::GetCursor() != hHand)
  97. {
  98. ::SetCursor(hHand);
  99. }
  100. }
  101. else
  102. {
  103. if(::GetCursor() != hArrow)
  104. {
  105. ::SetCursor(hArrow);
  106. }
  107. }
  108. }
  109. CWnd::OnMouseMove(nFlags, point);
  110. }