Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

166 lines
5.3 KiB

  1. // VelocityPage.cpp : Implementation of CVelocityPage
  2. #include "stdafx.h"
  3. #include "ToolProps.h"
  4. #include "VelocityPage.h"
  5. /////////////////////////////////////////////////////////////////////////////
  6. // CVelocityPage
  7. CVelocityPage::CVelocityPage()
  8. {
  9. m_dwTitleID = IDS_TITLEVelocityPage;
  10. m_dwHelpFileID = IDS_HELPFILEVelocityPage;
  11. m_dwDocStringID = IDS_DOCSTRINGVelocityPage;
  12. m_pVelocity = NULL;
  13. }
  14. CVelocityPage::~CVelocityPage()
  15. {
  16. if (m_pVelocity)
  17. {
  18. m_pVelocity->Release();
  19. }
  20. }
  21. STDMETHODIMP CVelocityPage::SetObjects(ULONG cObjects,IUnknown **ppUnk)
  22. {
  23. if (cObjects < 1 || cObjects > 1)
  24. return E_UNEXPECTED;
  25. return ppUnk[0]->QueryInterface(IID_IDirectMusicVelocityTool,(void **) &m_pVelocity);
  26. }
  27. STDMETHODIMP CVelocityPage::Apply(void)
  28. {
  29. m_pVelocity->SetStrength((long) m_ctStrength.GetValue());
  30. m_pVelocity->SetLowLimit((long) m_ctLowLimit.GetValue());
  31. m_pVelocity->SetHighLimit((long) m_ctHighLimit.GetValue());
  32. m_pVelocity->SetCurveStart((long) m_ctCurveStart.GetValue());
  33. m_pVelocity->SetCurveEnd((long) m_ctCurveEnd.GetValue());
  34. m_bDirty = FALSE;
  35. return S_OK;
  36. }
  37. LRESULT CVelocityPage::OnInitDialog(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
  38. {
  39. if (m_pVelocity)
  40. {
  41. m_ctStrength.Init(GetDlgItem(IDC_STRENGTH),GetDlgItem(IDC_STRENGTH_DISPLAY),0,100,true);
  42. m_ctLowLimit.Init(GetDlgItem(IDC_LOWERLIMIT),GetDlgItem(IDC_LOWERLIMIT_DISPLAY),1,127,true);
  43. m_ctHighLimit.Init(GetDlgItem(IDC_UPPERLIMIT),GetDlgItem(IDC_UPPERLIMIT_DISPLAY),1,127,true);
  44. m_ctCurveStart.Init(GetDlgItem(IDC_CURVESTART),GetDlgItem(IDC_CURVESTART_DISPLAY),1,127,true);
  45. m_ctCurveEnd.Init(GetDlgItem(IDC_CURVEEND),GetDlgItem(IDC_CURVEEND_DISPLAY),1,127,true);
  46. long lValue;
  47. m_pVelocity->GetStrength(&lValue);
  48. m_ctStrength.SetValue((float)lValue);
  49. m_pVelocity->GetLowLimit(&lValue);
  50. m_ctLowLimit.SetValue((float)lValue);
  51. m_pVelocity->GetHighLimit(&lValue);
  52. m_ctHighLimit.SetValue((float)lValue);
  53. m_pVelocity->GetCurveStart(&lValue);
  54. m_ctCurveStart.SetValue((float)lValue);
  55. m_pVelocity->GetCurveEnd(&lValue);
  56. m_ctCurveEnd.SetValue((float)lValue);
  57. HWND hWnd = GetDlgItem(IDC_DISPLAY_CURVE);
  58. ::GetWindowRect(hWnd,&m_rectDisplay);
  59. ::DestroyWindow(hWnd);
  60. ScreenToClient(&m_rectDisplay);
  61. }
  62. return 1;
  63. }
  64. void CVelocityPage::DrawCurve(HDC hDCIn)
  65. {
  66. float fLowLimit = m_ctLowLimit.GetValue() * (m_rectDisplay.top - m_rectDisplay.bottom ) / 127;
  67. float fHighLimit = m_ctHighLimit.GetValue() * (m_rectDisplay.top - m_rectDisplay.bottom) / 127;
  68. float fCurveStart = m_ctCurveStart.GetValue() * (m_rectDisplay.right - m_rectDisplay.left) / 127;
  69. float fCurveEnd = m_ctCurveEnd.GetValue() * (m_rectDisplay.right - m_rectDisplay.left ) / 127;
  70. HDC hDC;
  71. if (!hDCIn)
  72. {
  73. hDC = ::GetDC(m_hWnd);
  74. }
  75. else
  76. {
  77. hDC = hDCIn;
  78. }
  79. if (hDC)
  80. {
  81. m_rectDisplay.bottom++;
  82. ::FillRect(hDC, &m_rectDisplay, (HBRUSH) (COLOR_GRADIENTACTIVECAPTION));
  83. m_rectDisplay.bottom--;
  84. HPEN hPen = CreatePen(PS_SOLID,1,RGB(0,0,0));
  85. if (hPen)
  86. {
  87. HPEN hOldPen = (HPEN) ::SelectObject(hDC,hPen);
  88. ::MoveToEx(hDC,m_rectDisplay.left,m_rectDisplay.bottom + (int) fLowLimit,NULL);
  89. ::LineTo(hDC,m_rectDisplay.left + (int) fCurveStart,m_rectDisplay.bottom + (int) fLowLimit);
  90. ::LineTo(hDC,m_rectDisplay.left + (int) fCurveEnd,m_rectDisplay.bottom + (int) fHighLimit);
  91. ::LineTo(hDC,m_rectDisplay.right,m_rectDisplay.bottom + (int) fHighLimit);
  92. ::DeleteObject(hPen);
  93. }
  94. if (!hDCIn)
  95. {
  96. ::ReleaseDC(m_hWnd,hDC);
  97. }
  98. }
  99. }
  100. LRESULT CVelocityPage::OnPaint(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
  101. {
  102. PAINTSTRUCT Paint;
  103. HDC hDC = ::BeginPaint(m_hWnd,&Paint);
  104. if (hDC)
  105. {
  106. DrawCurve(hDC);
  107. ::EndPaint(m_hWnd,&Paint);
  108. }
  109. return true;
  110. }
  111. LRESULT CVelocityPage::OnCommand(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
  112. {
  113. LRESULT lr = m_ctStrength.MessageHandler(uMsg, wParam,lParam, bHandled);
  114. if (!bHandled)
  115. lr = m_ctLowLimit.MessageHandler(uMsg, wParam, lParam, bHandled);
  116. if (!bHandled)
  117. lr = m_ctHighLimit.MessageHandler(uMsg, wParam, lParam, bHandled);
  118. if (!bHandled)
  119. lr = m_ctCurveStart.MessageHandler(uMsg, wParam, lParam, bHandled);
  120. if (!bHandled)
  121. lr = m_ctCurveEnd.MessageHandler(uMsg, wParam, lParam, bHandled);
  122. if (bHandled)
  123. SetDirty(true);
  124. DrawCurve(NULL);
  125. return lr;
  126. }
  127. LRESULT CVelocityPage::OnSlider(UINT uMsg, WPARAM wParam,LPARAM lParam, BOOL& bHandled)
  128. {
  129. LRESULT lr = m_ctStrength.MessageHandler(uMsg, wParam,lParam, bHandled);
  130. if (!bHandled)
  131. lr = m_ctLowLimit.MessageHandler(uMsg, wParam, lParam, bHandled);
  132. if (!bHandled)
  133. lr = m_ctHighLimit.MessageHandler(uMsg, wParam, lParam, bHandled);
  134. if (!bHandled)
  135. lr = m_ctCurveStart.MessageHandler(uMsg, wParam, lParam, bHandled);
  136. if (!bHandled)
  137. lr = m_ctCurveEnd.MessageHandler(uMsg, wParam, lParam, bHandled);
  138. if (bHandled)
  139. SetDirty(true);
  140. DrawCurve(NULL);
  141. return lr;
  142. }